cloudfuji_paperclip 2.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +13 -0
  3. data/Appraisals +14 -0
  4. data/CONTRIBUTING.md +38 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +137 -0
  7. data/LICENSE +26 -0
  8. data/README.md +444 -0
  9. data/Rakefile +41 -0
  10. data/cucumber/paperclip_steps.rb +6 -0
  11. data/features/basic_integration.feature +46 -0
  12. data/features/rake_tasks.feature +63 -0
  13. data/features/step_definitions/attachment_steps.rb +65 -0
  14. data/features/step_definitions/html_steps.rb +15 -0
  15. data/features/step_definitions/rails_steps.rb +182 -0
  16. data/features/step_definitions/s3_steps.rb +14 -0
  17. data/features/step_definitions/web_steps.rb +209 -0
  18. data/features/support/env.rb +8 -0
  19. data/features/support/fakeweb.rb +3 -0
  20. data/features/support/fixtures/.boot_config.rb.swo +0 -0
  21. data/features/support/fixtures/boot_config.txt +15 -0
  22. data/features/support/fixtures/gemfile.txt +5 -0
  23. data/features/support/fixtures/preinitializer.txt +20 -0
  24. data/features/support/paths.rb +28 -0
  25. data/features/support/rails.rb +46 -0
  26. data/features/support/selectors.rb +19 -0
  27. data/gemfiles/rails2.gemfile +9 -0
  28. data/gemfiles/rails3.gemfile +9 -0
  29. data/gemfiles/rails3_1.gemfile +9 -0
  30. data/generators/paperclip/USAGE +5 -0
  31. data/generators/paperclip/paperclip_generator.rb +27 -0
  32. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  33. data/init.rb +4 -0
  34. data/lib/generators/paperclip/USAGE +8 -0
  35. data/lib/generators/paperclip/paperclip_generator.rb +33 -0
  36. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  37. data/lib/paperclip/attachment.rb +468 -0
  38. data/lib/paperclip/callback_compatibility.rb +61 -0
  39. data/lib/paperclip/geometry.rb +120 -0
  40. data/lib/paperclip/interpolations.rb +174 -0
  41. data/lib/paperclip/iostream.rb +45 -0
  42. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  43. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
  44. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  45. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  46. data/lib/paperclip/matchers.rb +64 -0
  47. data/lib/paperclip/missing_attachment_styles.rb +87 -0
  48. data/lib/paperclip/processor.rb +58 -0
  49. data/lib/paperclip/railtie.rb +31 -0
  50. data/lib/paperclip/schema.rb +39 -0
  51. data/lib/paperclip/storage/filesystem.rb +81 -0
  52. data/lib/paperclip/storage/fog.rb +174 -0
  53. data/lib/paperclip/storage/s3.rb +333 -0
  54. data/lib/paperclip/storage.rb +3 -0
  55. data/lib/paperclip/style.rb +103 -0
  56. data/lib/paperclip/thumbnail.rb +105 -0
  57. data/lib/paperclip/upfile.rb +62 -0
  58. data/lib/paperclip/url_generator.rb +64 -0
  59. data/lib/paperclip/version.rb +3 -0
  60. data/lib/paperclip.rb +487 -0
  61. data/lib/tasks/paperclip.rake +101 -0
  62. data/paperclip.gemspec +41 -0
  63. data/rails/init.rb +2 -0
  64. data/shoulda_macros/paperclip.rb +124 -0
  65. data/test/.gitignore +1 -0
  66. data/test/attachment_test.rb +1116 -0
  67. data/test/database.yml +4 -0
  68. data/test/fixtures/12k.png +0 -0
  69. data/test/fixtures/50x50.png +0 -0
  70. data/test/fixtures/5k.png +0 -0
  71. data/test/fixtures/animated.gif +0 -0
  72. data/test/fixtures/bad.png +1 -0
  73. data/test/fixtures/fog.yml +8 -0
  74. data/test/fixtures/question?mark.png +0 -0
  75. data/test/fixtures/s3.yml +8 -0
  76. data/test/fixtures/spaced file.png +0 -0
  77. data/test/fixtures/text.txt +1 -0
  78. data/test/fixtures/twopage.pdf +0 -0
  79. data/test/fixtures/uppercase.PNG +0 -0
  80. data/test/geometry_test.rb +206 -0
  81. data/test/helper.rb +177 -0
  82. data/test/integration_test.rb +654 -0
  83. data/test/interpolations_test.rb +216 -0
  84. data/test/iostream_test.rb +71 -0
  85. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  86. data/test/matchers/validate_attachment_content_type_matcher_test.rb +87 -0
  87. data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  88. data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  89. data/test/paperclip_missing_attachment_styles_test.rb +80 -0
  90. data/test/paperclip_test.rb +390 -0
  91. data/test/processor_test.rb +10 -0
  92. data/test/schema_test.rb +98 -0
  93. data/test/storage/filesystem_test.rb +56 -0
  94. data/test/storage/fog_test.rb +219 -0
  95. data/test/storage/s3_live_test.rb +138 -0
  96. data/test/storage/s3_test.rb +943 -0
  97. data/test/style_test.rb +209 -0
  98. data/test/support/mock_attachment.rb +22 -0
  99. data/test/support/mock_interpolator.rb +24 -0
  100. data/test/support/mock_model.rb +2 -0
  101. data/test/support/mock_url_generator_builder.rb +27 -0
  102. data/test/thumbnail_test.rb +383 -0
  103. data/test/upfile_test.rb +53 -0
  104. data/test/url_generator_test.rb +187 -0
  105. metadata +404 -0
@@ -0,0 +1,209 @@
1
+ # encoding: utf-8
2
+ require './test/helper'
3
+
4
+ class StyleTest < Test::Unit::TestCase
5
+
6
+ context "A style rule" do
7
+ setup do
8
+ @attachment = attachment :path => ":basename.:extension",
9
+ :styles => { :foo => {:geometry => "100x100#", :format => :png} },
10
+ :whiny => true
11
+ @style = @attachment.styles[:foo]
12
+ end
13
+
14
+ should "be held as a Style object" do
15
+ assert_kind_of Paperclip::Style, @style
16
+ end
17
+
18
+ should "get processors from the attachment definition" do
19
+ assert_equal [:thumbnail], @style.processors
20
+ end
21
+
22
+ should "have the right geometry" do
23
+ assert_equal "100x100#", @style.geometry
24
+ end
25
+
26
+ should "be whiny if the attachment is" do
27
+ assert @style.whiny?
28
+ end
29
+
30
+ should "respond to hash notation" do
31
+ assert_equal [:thumbnail], @style[:processors]
32
+ assert_equal "100x100#", @style[:geometry]
33
+ end
34
+ end
35
+
36
+ context "A style rule with properties supplied as procs" do
37
+ setup do
38
+ @attachment = attachment :path => ":basename.:extension",
39
+ :whiny_thumbnails => true,
40
+ :processors => lambda {|a| [:test]},
41
+ :styles => {
42
+ :foo => lambda{|a| "300x300#"},
43
+ :bar => {
44
+ :geometry => lambda{|a| "300x300#"},
45
+ :convert_options => lambda{|a| "-do_stuff"},
46
+ :source_file_options => lambda{|a| "-do_extra_stuff"}
47
+ }
48
+ }
49
+ end
50
+
51
+ should "call procs when they are needed" do
52
+ assert_equal "300x300#", @attachment.styles[:foo].geometry
53
+ assert_equal "300x300#", @attachment.styles[:bar].geometry
54
+ assert_equal [:test], @attachment.styles[:foo].processors
55
+ assert_equal [:test], @attachment.styles[:bar].processors
56
+ assert_equal "-do_stuff", @attachment.styles[:bar].convert_options
57
+ assert_equal "-do_extra_stuff", @attachment.styles[:bar].source_file_options
58
+ end
59
+ end
60
+
61
+ context "An attachment with style rules in various forms" do
62
+ setup do
63
+ styles = ActiveSupport::OrderedHash.new
64
+ styles[:aslist] = ["100x100", :png]
65
+ styles[:ashash] = {:geometry => "100x100", :format => :png}
66
+ styles[:asstring] = "100x100"
67
+ @attachment = attachment :path => ":basename.:extension",
68
+ :styles => styles
69
+ end
70
+ should "have the right number of styles" do
71
+ assert_kind_of Hash, @attachment.styles
72
+ assert_equal 3, @attachment.styles.size
73
+ end
74
+
75
+ should "have styles as Style objects" do
76
+ [:aslist, :ashash, :aslist].each do |s|
77
+ assert_kind_of Paperclip::Style, @attachment.styles[s]
78
+ end
79
+ end
80
+
81
+ should "have the right geometries" do
82
+ [:aslist, :ashash, :aslist].each do |s|
83
+ assert_equal @attachment.styles[s].geometry, "100x100"
84
+ end
85
+ end
86
+
87
+ should "have the right formats" do
88
+ assert_equal @attachment.styles[:aslist].format, :png
89
+ assert_equal @attachment.styles[:ashash].format, :png
90
+ assert_nil @attachment.styles[:asstring].format
91
+ end
92
+
93
+ should "retain order" do
94
+ assert_equal [:aslist, :ashash, :asstring], @attachment.styles.keys
95
+ end
96
+ end
97
+
98
+ context "An attachment with :convert_options" do
99
+ setup do
100
+ @attachment = attachment :path => ":basename.:extension",
101
+ :styles => {:thumb => "100x100", :large => "400x400"},
102
+ :convert_options => {:all => "-do_stuff", :thumb => "-thumbnailize"}
103
+ @style = @attachment.styles[:thumb]
104
+ @file = StringIO.new("...")
105
+ @file.stubs(:original_filename).returns("file.jpg")
106
+ end
107
+
108
+ before_should "not have called extra_options_for(:thumb/:large) on initialization" do
109
+ @attachment.expects(:extra_options_for).never
110
+ end
111
+
112
+ should "call extra_options_for(:thumb/:large) when convert options are requested" do
113
+ @attachment.expects(:extra_options_for).with(:thumb)
114
+ @attachment.styles[:thumb].convert_options
115
+ end
116
+ end
117
+
118
+ context "An attachment with :source_file_options" do
119
+ setup do
120
+ @attachment = attachment :path => ":basename.:extension",
121
+ :styles => {:thumb => "100x100", :large => "400x400"},
122
+ :source_file_options => {:all => "-density 400", :thumb => "-depth 8"}
123
+ @style = @attachment.styles[:thumb]
124
+ @file = StringIO.new("...")
125
+ @file.stubs(:original_filename).returns("file.jpg")
126
+ end
127
+
128
+ before_should "not have called extra_source_file_options_for(:thumb/:large) on initialization" do
129
+ @attachment.expects(:extra_source_file_options_for).never
130
+ end
131
+
132
+ should "call extra_options_for(:thumb/:large) when convert options are requested" do
133
+ @attachment.expects(:extra_source_file_options_for).with(:thumb)
134
+ @attachment.styles[:thumb].source_file_options
135
+ end
136
+ end
137
+
138
+ context "A style rule with its own :processors" do
139
+ setup do
140
+ @attachment = attachment :path => ":basename.:extension",
141
+ :styles => {
142
+ :foo => {
143
+ :geometry => "100x100#",
144
+ :format => :png,
145
+ :processors => [:test]
146
+ }
147
+ },
148
+ :processors => [:thumbnail]
149
+ @style = @attachment.styles[:foo]
150
+ end
151
+
152
+ should "not get processors from the attachment" do
153
+ @attachment.expects(:processors).never
154
+ assert_not_equal [:thumbnail], @style.processors
155
+ end
156
+
157
+ should "report its own processors" do
158
+ assert_equal [:test], @style.processors
159
+ end
160
+
161
+ end
162
+
163
+ context "A style rule with :processors supplied as procs" do
164
+ setup do
165
+ @attachment = attachment :path => ":basename.:extension",
166
+ :styles => {
167
+ :foo => {
168
+ :geometry => "100x100#",
169
+ :format => :png,
170
+ :processors => lambda{|a| [:test]}
171
+ }
172
+ },
173
+ :processors => [:thumbnail]
174
+ end
175
+
176
+ should "defer processing of procs until they are needed" do
177
+ assert_kind_of Proc, @attachment.styles[:foo].instance_variable_get("@processors")
178
+ end
179
+
180
+ should "call procs when they are needed" do
181
+ assert_equal [:test], @attachment.styles[:foo].processors
182
+ end
183
+ end
184
+
185
+ context "An attachment with :convert_options and :source_file_options in :styles" do
186
+ setup do
187
+ @attachment = attachment :path => ":basename.:extension",
188
+ :styles => {
189
+ :thumb => "100x100",
190
+ :large => {:geometry => "400x400",
191
+ :convert_options => "-do_stuff",
192
+ :source_file_options => "-do_extra_stuff"
193
+ }
194
+ }
195
+ @file = StringIO.new("...")
196
+ @file.stubs(:original_filename).returns("file.jpg")
197
+ end
198
+
199
+ should "have empty options for :thumb style" do
200
+ assert_equal "", @attachment.styles[:thumb].processor_options[:convert_options]
201
+ assert_equal "", @attachment.styles[:thumb].processor_options[:source_file_options]
202
+ end
203
+
204
+ should "have the right options for :large style" do
205
+ assert_equal "-do_stuff", @attachment.styles[:large].processor_options[:convert_options]
206
+ assert_equal "-do_extra_stuff", @attachment.styles[:large].processor_options[:source_file_options]
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,22 @@
1
+ class MockAttachment
2
+ attr_accessor :updated_at, :original_filename
3
+
4
+ def initialize(options = {})
5
+ @model = options[:model]
6
+ @responds_to_updated_at = options[:responds_to_updated_at]
7
+ @updated_at = options[:updated_at]
8
+ @original_filename = options[:original_filename]
9
+ end
10
+
11
+ def instance
12
+ @model
13
+ end
14
+
15
+ def respond_to?(meth)
16
+ if meth.to_s == "updated_at"
17
+ @responds_to_updated_at || @updated_at
18
+ else
19
+ super
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ class MockInterpolator
2
+ def initialize(options = {})
3
+ @options = options
4
+ end
5
+
6
+ def interpolate(pattern, attachment, style_name)
7
+ @interpolated_pattern = pattern
8
+ @interpolated_attachment = attachment
9
+ @interpolated_style_name = style_name
10
+ @options[:result]
11
+ end
12
+
13
+ def has_interpolated_pattern?(pattern)
14
+ @interpolated_pattern == pattern
15
+ end
16
+
17
+ def has_interpolated_style_name?(style_name)
18
+ @interpolated_style_name == style_name
19
+ end
20
+
21
+ def has_interpolated_attachment?(attachment)
22
+ @interpolated_attachment == attachment
23
+ end
24
+ end
@@ -0,0 +1,2 @@
1
+ class MockModel
2
+ end
@@ -0,0 +1,27 @@
1
+ class MockUrlGeneratorBuilder
2
+ def initializer
3
+ end
4
+
5
+ def new(attachment, attachment_options)
6
+ @attachment = attachment
7
+ @attachment_options = attachment_options
8
+ self
9
+ end
10
+
11
+ def for(style_name, options)
12
+ @generated_url_with_style_name = style_name
13
+ @generated_url_with_options = options
14
+ "hello"
15
+ end
16
+
17
+ def has_generated_url_with_options?(options)
18
+ # options.is_a_subhash_of(@generated_url_with_options)
19
+ options.inject(true) do |acc,(k,v)|
20
+ acc && @generated_url_with_options[k] == v
21
+ end
22
+ end
23
+
24
+ def has_generated_url_with_style_name?(style_name)
25
+ @generated_url_with_style_name == style_name
26
+ end
27
+ end
@@ -0,0 +1,383 @@
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 "have source_file_options set to nil by default" do
106
+ assert_equal nil, @thumb.source_file_options
107
+ end
108
+
109
+ should "send the right command to convert when sent #make" do
110
+ Paperclip.expects(:run).with do |*arg|
111
+ arg[0] == 'convert' &&
112
+ arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
113
+ arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
114
+ end
115
+ @thumb.make
116
+ end
117
+
118
+ should "create the thumbnail when sent #make" do
119
+ dst = @thumb.make
120
+ assert_match /100x50/, `identify "#{dst.path}"`
121
+ end
122
+ end
123
+
124
+ context "being thumbnailed with source file options set" do
125
+ setup do
126
+ @thumb = Paperclip::Thumbnail.new(@file,
127
+ :geometry => "100x50#",
128
+ :source_file_options => "-strip")
129
+ end
130
+
131
+ should "have source_file_options value set" do
132
+ assert_equal ["-strip"], @thumb.source_file_options
133
+ end
134
+
135
+ should "send the right command to convert when sent #make" do
136
+ Paperclip.expects(:run).with do |*arg|
137
+ arg[0] == 'convert' &&
138
+ arg[1] == '-strip :source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
139
+ arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
140
+ end
141
+ @thumb.make
142
+ end
143
+
144
+ should "create the thumbnail when sent #make" do
145
+ dst = @thumb.make
146
+ assert_match /100x50/, `identify "#{dst.path}"`
147
+ end
148
+
149
+ context "redefined to have bad source_file_options setting" do
150
+ setup do
151
+ @thumb = Paperclip::Thumbnail.new(@file,
152
+ :geometry => "100x50#",
153
+ :source_file_options => "-this-aint-no-option")
154
+ end
155
+
156
+ should "error when trying to create the thumbnail" do
157
+ assert_raises(Paperclip::PaperclipError) do
158
+ @thumb.make
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ context "being thumbnailed with convert options set" do
165
+ setup do
166
+ @thumb = Paperclip::Thumbnail.new(@file,
167
+ :geometry => "100x50#",
168
+ :convert_options => "-strip -depth 8")
169
+ end
170
+
171
+ should "have convert_options value set" do
172
+ assert_equal %w"-strip -depth 8", @thumb.convert_options
173
+ end
174
+
175
+ should "send the right command to convert when sent #make" do
176
+ Paperclip.expects(:run).with do |*arg|
177
+ arg[0] == 'convert' &&
178
+ arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
179
+ arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
180
+ end
181
+ @thumb.make
182
+ end
183
+
184
+ should "create the thumbnail when sent #make" do
185
+ dst = @thumb.make
186
+ assert_match /100x50/, `identify "#{dst.path}"`
187
+ end
188
+
189
+ context "redefined to have bad convert_options setting" do
190
+ setup do
191
+ @thumb = Paperclip::Thumbnail.new(@file,
192
+ :geometry => "100x50#",
193
+ :convert_options => "-this-aint-no-option")
194
+ end
195
+
196
+ should "error when trying to create the thumbnail" do
197
+ assert_raises(Paperclip::PaperclipError) do
198
+ @thumb.make
199
+ end
200
+ end
201
+
202
+ should "let us know when a command isn't found versus a processing error" do
203
+ old_path = ENV['PATH']
204
+ begin
205
+ ENV['PATH'] = ''
206
+ assert_raises(Paperclip::CommandNotFoundError) do
207
+ @thumb.make
208
+ end
209
+ ensure
210
+ ENV['PATH'] = old_path
211
+ end
212
+ end
213
+ end
214
+ end
215
+
216
+ context "being thumbnailed with a blank geometry string" do
217
+ setup do
218
+ @thumb = Paperclip::Thumbnail.new(@file,
219
+ :geometry => "",
220
+ :convert_options => "-gravity center -crop \"300x300+0-0\"")
221
+ end
222
+
223
+ should "not get resized by default" do
224
+ assert !@thumb.transformation_command.include?("-resize")
225
+ end
226
+ end
227
+
228
+ context "passing a custom file geometry parser" do
229
+ should "produce the appropriate transformation_command" do
230
+ GeoParser = Class.new do
231
+ def self.from_file(file)
232
+ new
233
+ end
234
+ def transformation_to(target, should_crop)
235
+ ["SCALE", "CROP"]
236
+ end
237
+ end
238
+
239
+ thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :file_geometry_parser => GeoParser)
240
+
241
+ transformation_command = thumb.transformation_command
242
+
243
+ assert transformation_command.include?('-crop'),
244
+ %{expected #{transformation_command.inspect} to include '-crop'}
245
+ assert transformation_command.include?('"CROP"'),
246
+ %{expected #{transformation_command.inspect} to include '"CROP"'}
247
+ assert transformation_command.include?('-resize'),
248
+ %{expected #{transformation_command.inspect} to include '-resize'}
249
+ assert transformation_command.include?('"SCALE"'),
250
+ %{expected #{transformation_command.inspect} to include '"SCALE"'}
251
+ end
252
+ end
253
+
254
+ context "passing a custom geometry string parser" do
255
+ should "produce the appropriate transformation_command" do
256
+ GeoParser = Class.new do
257
+ def self.parse(s)
258
+ new
259
+ end
260
+
261
+ def to_s
262
+ "151x167"
263
+ end
264
+ end
265
+
266
+ thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :string_geometry_parser => GeoParser)
267
+
268
+ transformation_command = thumb.transformation_command
269
+
270
+ assert transformation_command.include?('"151x167"'),
271
+ %{expected #{transformation_command.inspect} to include '151x167'}
272
+ end
273
+ end
274
+ end
275
+
276
+ context "A multipage PDF" do
277
+ setup do
278
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
279
+ end
280
+
281
+ teardown { @file.close }
282
+
283
+ should "start with two pages with dimensions 612x792" do
284
+ cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
285
+ assert_equal "612x792"*2, `#{cmd}`.chomp
286
+ end
287
+
288
+ context "being thumbnailed at 100x100 with cropping" do
289
+ setup do
290
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
291
+ end
292
+
293
+ should "report its correct current and target geometries" do
294
+ assert_equal "100x100#", @thumb.target_geometry.to_s
295
+ assert_equal "612x792", @thumb.current_geometry.to_s
296
+ end
297
+
298
+ should "report its correct format" do
299
+ assert_equal :png, @thumb.format
300
+ end
301
+
302
+ should "create the thumbnail when sent #make" do
303
+ dst = @thumb.make
304
+ assert_match /100x100/, `identify "#{dst.path}"`
305
+ end
306
+ end
307
+ end
308
+
309
+ context "An animated gif" do
310
+ setup do
311
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "animated.gif"), 'rb')
312
+ end
313
+
314
+ teardown { @file.close }
315
+
316
+ should "start with 12 frames with size 100x100" do
317
+ cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
318
+ assert_equal "100x100"*12, `#{cmd}`.chomp
319
+ end
320
+
321
+ context "with static output" do
322
+ setup do
323
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :jpg)
324
+ end
325
+
326
+ should "create the single frame thumbnail when sent #make" do
327
+ dst = @thumb.make
328
+ cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
329
+ assert_equal "50x50", `#{cmd}`.chomp
330
+ end
331
+ end
332
+
333
+ context "with animated output format" do
334
+ setup do
335
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :gif)
336
+ end
337
+
338
+ should "create the 12 frames thumbnail when sent #make" do
339
+ dst = @thumb.make
340
+ cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
341
+ assert_equal "50x50"*12, `#{cmd}`.chomp
342
+ end
343
+
344
+ should "use the -coalesce option" do
345
+ assert_equal @thumb.transformation_command.first, "-coalesce"
346
+ end
347
+ end
348
+
349
+ context "with omitted output format" do
350
+ setup do
351
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50")
352
+ end
353
+
354
+ should "create the 12 frames thumbnail when sent #make" do
355
+ dst = @thumb.make
356
+ cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
357
+ assert_equal "50x50"*12, `#{cmd}`.chomp
358
+ end
359
+
360
+ should "use the -coalesce option" do
361
+ assert_equal @thumb.transformation_command.first, "-coalesce"
362
+ end
363
+ end
364
+
365
+ context "with animated option set to false" do
366
+ setup do
367
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :animated => false)
368
+ end
369
+
370
+ should "output the gif format" do
371
+ dst = @thumb.make
372
+ cmd = %Q[identify "#{dst.path}"]
373
+ assert_match /GIF/, `#{cmd}`.chomp
374
+ end
375
+
376
+ should "create the single frame thumbnail when sent #make" do
377
+ dst = @thumb.make
378
+ cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
379
+ assert_equal "50x50", `#{cmd}`.chomp
380
+ end
381
+ end
382
+ end
383
+ end