sayso-paperclip 2.3.10.001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/LICENSE +26 -0
  2. data/README.md +250 -0
  3. data/Rakefile +80 -0
  4. data/generators/paperclip/USAGE +5 -0
  5. data/generators/paperclip/paperclip_generator.rb +27 -0
  6. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  7. data/init.rb +1 -0
  8. data/lib/generators/paperclip/USAGE +8 -0
  9. data/lib/generators/paperclip/paperclip_generator.rb +31 -0
  10. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  11. data/lib/paperclip.rb +376 -0
  12. data/lib/paperclip/attachment.rb +378 -0
  13. data/lib/paperclip/callback_compatability.rb +61 -0
  14. data/lib/paperclip/geometry.rb +117 -0
  15. data/lib/paperclip/interpolations.rb +130 -0
  16. data/lib/paperclip/iostream.rb +45 -0
  17. data/lib/paperclip/matchers.rb +33 -0
  18. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  19. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +75 -0
  20. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  21. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  22. data/lib/paperclip/processor.rb +58 -0
  23. data/lib/paperclip/railtie.rb +24 -0
  24. data/lib/paperclip/storage.rb +3 -0
  25. data/lib/paperclip/storage/filesystem.rb +73 -0
  26. data/lib/paperclip/storage/fog.rb +98 -0
  27. data/lib/paperclip/storage/s3.rb +192 -0
  28. data/lib/paperclip/style.rb +91 -0
  29. data/lib/paperclip/thumbnail.rb +81 -0
  30. data/lib/paperclip/upfile.rb +55 -0
  31. data/lib/paperclip/version.rb +3 -0
  32. data/lib/tasks/paperclip.rake +72 -0
  33. data/rails/init.rb +2 -0
  34. data/shoulda_macros/paperclip.rb +118 -0
  35. data/test/attachment_test.rb +939 -0
  36. data/test/database.yml +4 -0
  37. data/test/fixtures/12k.png +0 -0
  38. data/test/fixtures/50x50.png +0 -0
  39. data/test/fixtures/5k.png +0 -0
  40. data/test/fixtures/bad.png +1 -0
  41. data/test/fixtures/s3.yml +8 -0
  42. data/test/fixtures/text.txt +0 -0
  43. data/test/fixtures/twopage.pdf +0 -0
  44. data/test/fixtures/uppercase.PNG +0 -0
  45. data/test/fog_test.rb +107 -0
  46. data/test/geometry_test.rb +190 -0
  47. data/test/helper.rb +146 -0
  48. data/test/integration_test.rb +570 -0
  49. data/test/interpolations_test.rb +143 -0
  50. data/test/iostream_test.rb +71 -0
  51. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  52. data/test/matchers/validate_attachment_content_type_matcher_test.rb +47 -0
  53. data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  54. data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  55. data/test/paperclip_test.rb +271 -0
  56. data/test/processor_test.rb +10 -0
  57. data/test/storage_test.rb +416 -0
  58. data/test/style_test.rb +163 -0
  59. data/test/thumbnail_test.rb +257 -0
  60. data/test/upfile_test.rb +36 -0
  61. metadata +203 -0
@@ -0,0 +1,257 @@
1
+ require './test/helper'
2
+
3
+ class ThumbnailTest < Test::Unit::TestCase
4
+
5
+ context "A Paperclip Tempfile" do
6
+ setup do
7
+ @tempfile = Paperclip::Tempfile.new(["file", ".jpg"])
8
+ end
9
+
10
+ should "have its path contain a real extension" do
11
+ assert_equal ".jpg", File.extname(@tempfile.path)
12
+ end
13
+
14
+ should "be a real Tempfile" do
15
+ assert @tempfile.is_a?(::Tempfile)
16
+ end
17
+ end
18
+
19
+ context "Another Paperclip Tempfile" do
20
+ setup do
21
+ @tempfile = Paperclip::Tempfile.new("file")
22
+ end
23
+
24
+ should "not have an extension if not given one" do
25
+ assert_equal "", File.extname(@tempfile.path)
26
+ end
27
+
28
+ should "still be a real Tempfile" do
29
+ assert @tempfile.is_a?(::Tempfile)
30
+ end
31
+ end
32
+
33
+ context "An image" do
34
+ setup do
35
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
36
+ end
37
+
38
+ teardown { @file.close }
39
+
40
+ [["600x600>", "434x66"],
41
+ ["400x400>", "400x61"],
42
+ ["32x32<", "434x66"]
43
+ ].each do |args|
44
+ context "being thumbnailed with a geometry of #{args[0]}" do
45
+ setup do
46
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
47
+ end
48
+
49
+ should "start with dimensions of 434x66" do
50
+ cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
51
+ assert_equal "434x66", `#{cmd}`.chomp
52
+ end
53
+
54
+ should "report the correct target geometry" do
55
+ assert_equal args[0], @thumb.target_geometry.to_s
56
+ end
57
+
58
+ context "when made" do
59
+ setup do
60
+ @thumb_result = @thumb.make
61
+ end
62
+
63
+ should "be the size we expect it to be" do
64
+ cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
65
+ assert_equal args[1], `#{cmd}`.chomp
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ context "being thumbnailed at 100x50 with cropping" do
72
+ setup do
73
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
74
+ end
75
+
76
+ should "let us know when a command isn't found versus a processing error" do
77
+ old_path = ENV['PATH']
78
+ begin
79
+ ENV['PATH'] = ''
80
+ assert_raises(Paperclip::CommandNotFoundError) do
81
+ @thumb.make
82
+ end
83
+ ensure
84
+ ENV['PATH'] = old_path
85
+ end
86
+ end
87
+
88
+ should "report its correct current and target geometries" do
89
+ assert_equal "100x50#", @thumb.target_geometry.to_s
90
+ assert_equal "434x66", @thumb.current_geometry.to_s
91
+ end
92
+
93
+ should "report its correct format" do
94
+ assert_nil @thumb.format
95
+ end
96
+
97
+ should "have whiny turned on by default" do
98
+ assert @thumb.whiny
99
+ end
100
+
101
+ should "have convert_options set to nil by default" do
102
+ assert_equal nil, @thumb.convert_options
103
+ end
104
+
105
+ should "send the right command to convert when sent #make" do
106
+ Paperclip.expects(:run).with do |*arg|
107
+ arg[0] == 'convert' &&
108
+ arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
109
+ arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
110
+ end
111
+ @thumb.make
112
+ end
113
+
114
+ should "create the thumbnail when sent #make" do
115
+ dst = @thumb.make
116
+ assert_match /100x50/, `identify "#{dst.path}"`
117
+ end
118
+ end
119
+
120
+ context "being thumbnailed with source file options set" do
121
+ setup do
122
+ @thumb = Paperclip::Thumbnail.new(@file,
123
+ :geometry => "100x50#",
124
+ :source_file_options => "-strip")
125
+ end
126
+
127
+ should "have source_file_options value set" do
128
+ assert_equal ["-strip"], @thumb.source_file_options
129
+ end
130
+
131
+ should "send the right command to convert when sent #make" do
132
+ Paperclip.expects(:run).with do |*arg|
133
+ arg[0] == 'convert' &&
134
+ arg[1] == '-strip :source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
135
+ arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
136
+ end
137
+ @thumb.make
138
+ end
139
+
140
+ should "create the thumbnail when sent #make" do
141
+ dst = @thumb.make
142
+ assert_match /100x50/, `identify "#{dst.path}"`
143
+ end
144
+
145
+ context "redefined to have bad source_file_options setting" do
146
+ setup do
147
+ @thumb = Paperclip::Thumbnail.new(@file,
148
+ :geometry => "100x50#",
149
+ :source_file_options => "-this-aint-no-option")
150
+ end
151
+
152
+ should "error when trying to create the thumbnail" do
153
+ assert_raises(Paperclip::PaperclipError) do
154
+ @thumb.make
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ context "being thumbnailed with convert options set" do
161
+ setup do
162
+ @thumb = Paperclip::Thumbnail.new(@file,
163
+ :geometry => "100x50#",
164
+ :convert_options => "-strip -depth 8")
165
+ end
166
+
167
+ should "have convert_options value set" do
168
+ assert_equal %w"-strip -depth 8", @thumb.convert_options
169
+ end
170
+
171
+ should "send the right command to convert when sent #make" do
172
+ Paperclip.expects(:run).with do |*arg|
173
+ arg[0] == 'convert' &&
174
+ arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
175
+ arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
176
+ end
177
+ @thumb.make
178
+ end
179
+
180
+ should "create the thumbnail when sent #make" do
181
+ dst = @thumb.make
182
+ assert_match /100x50/, `identify "#{dst.path}"`
183
+ end
184
+
185
+ context "redefined to have bad convert_options setting" do
186
+ setup do
187
+ @thumb = Paperclip::Thumbnail.new(@file,
188
+ :geometry => "100x50#",
189
+ :convert_options => "-this-aint-no-option")
190
+ end
191
+
192
+ should "error when trying to create the thumbnail" do
193
+ assert_raises(Paperclip::PaperclipError) do
194
+ @thumb.make
195
+ end
196
+ end
197
+
198
+ should "let us know when a command isn't found versus a processing error" do
199
+ old_path = ENV['PATH']
200
+ begin
201
+ ENV['PATH'] = ''
202
+ assert_raises(Paperclip::CommandNotFoundError) do
203
+ @thumb.make
204
+ end
205
+ ensure
206
+ ENV['PATH'] = old_path
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ context "being thumbnailed with a blank geometry string" do
213
+ setup do
214
+ @thumb = Paperclip::Thumbnail.new(@file,
215
+ :geometry => "",
216
+ :convert_options => "-gravity center -crop \"300x300+0-0\"")
217
+ end
218
+
219
+ should "not get resized by default" do
220
+ assert !@thumb.transformation_command.include?("-resize")
221
+ end
222
+ end
223
+ end
224
+
225
+ context "A multipage PDF" do
226
+ setup do
227
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
228
+ end
229
+
230
+ teardown { @file.close }
231
+
232
+ should "start with two pages with dimensions 612x792" do
233
+ cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
234
+ assert_equal "612x792"*2, `#{cmd}`.chomp
235
+ end
236
+
237
+ context "being thumbnailed at 100x100 with cropping" do
238
+ setup do
239
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
240
+ end
241
+
242
+ should "report its correct current and target geometries" do
243
+ assert_equal "100x100#", @thumb.target_geometry.to_s
244
+ assert_equal "612x792", @thumb.current_geometry.to_s
245
+ end
246
+
247
+ should "report its correct format" do
248
+ assert_equal :png, @thumb.format
249
+ end
250
+
251
+ should "create the thumbnail when sent #make" do
252
+ dst = @thumb.make
253
+ assert_match /100x100/, `identify "#{dst.path}"`
254
+ end
255
+ end
256
+ end
257
+ end
@@ -0,0 +1,36 @@
1
+ require './test/helper'
2
+
3
+ class UpfileTest < Test::Unit::TestCase
4
+ { %w(jpg jpe jpeg) => 'image/jpeg',
5
+ %w(tif tiff) => 'image/tiff',
6
+ %w(png) => 'image/png',
7
+ %w(gif) => 'image/gif',
8
+ %w(bmp) => 'image/bmp',
9
+ %w(txt) => 'text/plain',
10
+ %w(htm html) => 'text/html',
11
+ %w(csv) => 'text/csv',
12
+ %w(xml) => 'text/xml',
13
+ %w(css) => 'text/css',
14
+ %w(js) => 'application/js',
15
+ %w(foo) => 'application/x-foo'
16
+ }.each do |extensions, content_type|
17
+ extensions.each do |extension|
18
+ should "return a content_type of #{content_type} for a file with extension .#{extension}" do
19
+ file = stub('file', :path => "basename.#{extension}")
20
+ class << file
21
+ include Paperclip::Upfile
22
+ end
23
+
24
+ assert_equal content_type, file.content_type
25
+ end
26
+ end
27
+ end
28
+
29
+ should "return a content_type of text/plain on a real file whose content_type is determined with the file command" do
30
+ file = File.new(File.join(File.dirname(__FILE__), "..", "LICENSE"))
31
+ class << file
32
+ include Paperclip::Upfile
33
+ end
34
+ assert_equal 'text/plain', file.content_type
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sayso-paperclip
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 2.3.10.001
6
+ platform: ruby
7
+ authors:
8
+ - SaySo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-23 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activerecord
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.3.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.3.2
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: cocaine
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.2
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: shoulda
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: appraisal
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: mocha
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: aws-s3
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: sqlite3-ruby
95
+ prerelease: false
96
+ requirement: &id008 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ type: :development
103
+ version_requirements: *id008
104
+ description: Easy upload management for ActiveRecord - forked and gemified for sayso
105
+ email: sayso@truvolabs.com
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ extra_rdoc_files:
111
+ - README.md
112
+ files:
113
+ - README.md
114
+ - LICENSE
115
+ - Rakefile
116
+ - init.rb
117
+ - lib/generators/paperclip/paperclip_generator.rb
118
+ - lib/generators/paperclip/templates/paperclip_migration.rb.erb
119
+ - lib/generators/paperclip/USAGE
120
+ - lib/paperclip/attachment.rb
121
+ - lib/paperclip/callback_compatability.rb
122
+ - lib/paperclip/geometry.rb
123
+ - lib/paperclip/interpolations.rb
124
+ - lib/paperclip/iostream.rb
125
+ - lib/paperclip/matchers/have_attached_file_matcher.rb
126
+ - lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
127
+ - lib/paperclip/matchers/validate_attachment_presence_matcher.rb
128
+ - lib/paperclip/matchers/validate_attachment_size_matcher.rb
129
+ - lib/paperclip/matchers.rb
130
+ - lib/paperclip/processor.rb
131
+ - lib/paperclip/railtie.rb
132
+ - lib/paperclip/storage/filesystem.rb
133
+ - lib/paperclip/storage/fog.rb
134
+ - lib/paperclip/storage/s3.rb
135
+ - lib/paperclip/storage.rb
136
+ - lib/paperclip/style.rb
137
+ - lib/paperclip/thumbnail.rb
138
+ - lib/paperclip/upfile.rb
139
+ - lib/paperclip/version.rb
140
+ - lib/paperclip.rb
141
+ - lib/tasks/paperclip.rake
142
+ - test/attachment_test.rb
143
+ - test/database.yml
144
+ - test/fixtures/12k.png
145
+ - test/fixtures/50x50.png
146
+ - test/fixtures/5k.png
147
+ - test/fixtures/bad.png
148
+ - test/fixtures/s3.yml
149
+ - test/fixtures/text.txt
150
+ - test/fixtures/twopage.pdf
151
+ - test/fixtures/uppercase.PNG
152
+ - test/fog_test.rb
153
+ - test/geometry_test.rb
154
+ - test/helper.rb
155
+ - test/integration_test.rb
156
+ - test/interpolations_test.rb
157
+ - test/iostream_test.rb
158
+ - test/matchers/have_attached_file_matcher_test.rb
159
+ - test/matchers/validate_attachment_content_type_matcher_test.rb
160
+ - test/matchers/validate_attachment_presence_matcher_test.rb
161
+ - test/matchers/validate_attachment_size_matcher_test.rb
162
+ - test/paperclip_test.rb
163
+ - test/processor_test.rb
164
+ - test/storage_test.rb
165
+ - test/style_test.rb
166
+ - test/thumbnail_test.rb
167
+ - test/upfile_test.rb
168
+ - rails/init.rb
169
+ - generators/paperclip/paperclip_generator.rb
170
+ - generators/paperclip/templates/paperclip_migration.rb.erb
171
+ - generators/paperclip/USAGE
172
+ - shoulda_macros/paperclip.rb
173
+ has_rdoc: true
174
+ homepage: http://github.com/sayso/paperclip
175
+ licenses: []
176
+
177
+ post_install_message:
178
+ rdoc_options:
179
+ - --line-numbers
180
+ - --inline-source
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: "0"
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ none: false
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: "0"
195
+ requirements:
196
+ - ImageMagick
197
+ rubyforge_project: paperclip
198
+ rubygems_version: 1.6.2
199
+ signing_key:
200
+ specification_version: 3
201
+ summary: File attachments as attributes for ActiveRecord - forked and gemified for sayso
202
+ test_files: []
203
+