paperclip 3.4.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +17 -0
  3. data/.github/issue_template.md +3 -0
  4. data/.gitignore +0 -6
  5. data/.hound.yml +1055 -0
  6. data/.rubocop.yml +1 -0
  7. data/.travis.yml +19 -12
  8. data/Appraisals +4 -11
  9. data/CONTRIBUTING.md +29 -13
  10. data/Gemfile +13 -4
  11. data/LICENSE +1 -3
  12. data/MIGRATING-ES.md +317 -0
  13. data/MIGRATING.md +375 -0
  14. data/NEWS +390 -71
  15. data/README.md +607 -152
  16. data/RELEASING.md +17 -0
  17. data/Rakefile +6 -8
  18. data/UPGRADING +12 -9
  19. data/features/basic_integration.feature +34 -21
  20. data/features/migration.feature +0 -24
  21. data/features/rake_tasks.feature +2 -3
  22. data/features/step_definitions/attachment_steps.rb +44 -36
  23. data/features/step_definitions/html_steps.rb +2 -2
  24. data/features/step_definitions/rails_steps.rb +125 -26
  25. data/features/step_definitions/s3_steps.rb +3 -3
  26. data/features/step_definitions/web_steps.rb +1 -103
  27. data/features/support/env.rb +3 -2
  28. data/features/support/fakeweb.rb +4 -1
  29. data/features/support/file_helpers.rb +12 -2
  30. data/features/support/fixtures/gemfile.txt +1 -1
  31. data/features/support/paths.rb +1 -1
  32. data/features/support/rails.rb +4 -11
  33. data/gemfiles/4.2.gemfile +17 -0
  34. data/gemfiles/5.0.gemfile +17 -0
  35. data/lib/generators/paperclip/paperclip_generator.rb +9 -3
  36. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +2 -2
  37. data/lib/paperclip/attachment.rb +215 -82
  38. data/lib/paperclip/attachment_registry.rb +60 -0
  39. data/lib/paperclip/callbacks.rb +13 -1
  40. data/lib/paperclip/content_type_detector.rb +48 -24
  41. data/lib/paperclip/errors.rb +8 -1
  42. data/lib/paperclip/file_command_content_type_detector.rb +6 -8
  43. data/lib/paperclip/filename_cleaner.rb +15 -0
  44. data/lib/paperclip/geometry_detector_factory.rb +12 -5
  45. data/lib/paperclip/geometry_parser_factory.rb +1 -1
  46. data/lib/paperclip/glue.rb +1 -2
  47. data/lib/paperclip/has_attached_file.rb +115 -0
  48. data/lib/paperclip/helpers.rb +15 -20
  49. data/lib/paperclip/interpolations/plural_cache.rb +18 -0
  50. data/lib/paperclip/interpolations.rb +36 -14
  51. data/lib/paperclip/io_adapters/abstract_adapter.rb +42 -5
  52. data/lib/paperclip/io_adapters/attachment_adapter.rb +20 -9
  53. data/lib/paperclip/io_adapters/data_uri_adapter.rb +22 -0
  54. data/lib/paperclip/io_adapters/empty_string_adapter.rb +19 -0
  55. data/lib/paperclip/io_adapters/file_adapter.rb +13 -7
  56. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +16 -0
  57. data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
  58. data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
  59. data/lib/paperclip/io_adapters/registry.rb +6 -2
  60. data/lib/paperclip/io_adapters/stringio_adapter.rb +15 -16
  61. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +11 -7
  62. data/lib/paperclip/io_adapters/uri_adapter.rb +43 -19
  63. data/lib/paperclip/locales/en.yml +1 -0
  64. data/lib/paperclip/logger.rb +1 -1
  65. data/lib/paperclip/matchers/have_attached_file_matcher.rb +3 -6
  66. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  67. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +7 -2
  68. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
  69. data/lib/paperclip/matchers.rb +1 -1
  70. data/lib/paperclip/media_type_spoof_detector.rb +93 -0
  71. data/lib/paperclip/missing_attachment_styles.rb +11 -16
  72. data/lib/paperclip/processor.rb +15 -43
  73. data/lib/paperclip/processor_helpers.rb +50 -0
  74. data/lib/paperclip/rails_environment.rb +25 -0
  75. data/lib/paperclip/schema.rb +10 -8
  76. data/lib/paperclip/storage/filesystem.rb +20 -5
  77. data/lib/paperclip/storage/fog.rb +49 -23
  78. data/lib/paperclip/storage/s3.rb +153 -82
  79. data/lib/paperclip/style.rb +8 -3
  80. data/lib/paperclip/tempfile_factory.rb +6 -4
  81. data/lib/paperclip/thumbnail.rb +35 -19
  82. data/lib/paperclip/url_generator.rb +26 -14
  83. data/lib/paperclip/validators/attachment_content_type_validator.rb +15 -2
  84. data/lib/paperclip/validators/attachment_file_name_validator.rb +80 -0
  85. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +29 -0
  86. data/lib/paperclip/validators/attachment_presence_validator.rb +12 -8
  87. data/lib/paperclip/validators/attachment_size_validator.rb +17 -10
  88. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +31 -0
  89. data/lib/paperclip/validators.rb +31 -3
  90. data/lib/paperclip/version.rb +3 -1
  91. data/lib/paperclip.rb +41 -55
  92. data/lib/tasks/paperclip.rake +56 -9
  93. data/paperclip.gemspec +18 -17
  94. data/shoulda_macros/paperclip.rb +13 -3
  95. data/spec/paperclip/attachment_definitions_spec.rb +13 -0
  96. data/spec/paperclip/attachment_processing_spec.rb +79 -0
  97. data/spec/paperclip/attachment_registry_spec.rb +158 -0
  98. data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +597 -389
  99. data/spec/paperclip/content_type_detector_spec.rb +48 -0
  100. data/spec/paperclip/file_command_content_type_detector_spec.rb +40 -0
  101. data/spec/paperclip/filename_cleaner_spec.rb +13 -0
  102. data/spec/paperclip/geometry_detector_spec.rb +39 -0
  103. data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
  104. data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +50 -52
  105. data/spec/paperclip/glue_spec.rb +44 -0
  106. data/spec/paperclip/has_attached_file_spec.rb +158 -0
  107. data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +179 -199
  108. data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +79 -46
  109. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +160 -0
  110. data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +54 -25
  111. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +89 -0
  112. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
  113. data/spec/paperclip/io_adapters/file_adapter_spec.rb +131 -0
  114. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +138 -0
  115. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
  116. data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
  117. data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +12 -9
  118. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +64 -0
  119. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +146 -0
  120. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +220 -0
  121. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
  122. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +109 -0
  123. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
  124. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
  125. data/spec/paperclip/media_type_spoof_detector_spec.rb +120 -0
  126. data/spec/paperclip/meta_class_spec.rb +30 -0
  127. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
  128. data/spec/paperclip/paperclip_spec.rb +192 -0
  129. data/spec/paperclip/plural_cache_spec.rb +37 -0
  130. data/spec/paperclip/processor_helpers_spec.rb +57 -0
  131. data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +7 -7
  132. data/spec/paperclip/rails_environment_spec.rb +33 -0
  133. data/spec/paperclip/rake_spec.rb +103 -0
  134. data/spec/paperclip/schema_spec.rb +248 -0
  135. data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
  136. data/spec/paperclip/storage/fog_spec.rb +566 -0
  137. data/spec/paperclip/storage/s3_live_spec.rb +188 -0
  138. data/spec/paperclip/storage/s3_spec.rb +1693 -0
  139. data/spec/paperclip/style_spec.rb +254 -0
  140. data/spec/paperclip/tempfile_factory_spec.rb +33 -0
  141. data/spec/paperclip/tempfile_spec.rb +35 -0
  142. data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +186 -141
  143. data/spec/paperclip/url_generator_spec.rb +221 -0
  144. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
  145. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
  146. data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +20 -20
  147. data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +87 -59
  148. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +52 -0
  149. data/spec/paperclip/validators_spec.rb +164 -0
  150. data/spec/spec_helper.rb +46 -0
  151. data/spec/support/assertions.rb +82 -0
  152. data/spec/support/fake_model.rb +25 -0
  153. data/spec/support/fake_rails.rb +12 -0
  154. data/spec/support/fixtures/empty.html +1 -0
  155. data/spec/support/fixtures/empty.xlsx +0 -0
  156. data/spec/support/fixtures/spaced file.jpg +0 -0
  157. data/spec/support/matchers/accept.rb +5 -0
  158. data/spec/support/matchers/exist.rb +5 -0
  159. data/spec/support/matchers/have_column.rb +23 -0
  160. data/{test → spec}/support/mock_attachment.rb +2 -0
  161. data/{test → spec}/support/mock_url_generator_builder.rb +2 -2
  162. data/spec/support/model_reconstruction.rb +68 -0
  163. data/spec/support/reporting.rb +11 -0
  164. data/spec/support/test_data.rb +13 -0
  165. data/spec/support/version_helper.rb +9 -0
  166. metadata +395 -346
  167. data/Gemfile.lock +0 -200
  168. data/RUNNING_TESTS.md +0 -4
  169. data/cucumber/paperclip_steps.rb +0 -6
  170. data/gemfiles/3.0.gemfile +0 -11
  171. data/gemfiles/3.1.gemfile +0 -11
  172. data/gemfiles/3.2.gemfile +0 -11
  173. data/lib/paperclip/attachment_options.rb +0 -9
  174. data/lib/paperclip/instance_methods.rb +0 -35
  175. data/test/attachment_options_test.rb +0 -27
  176. data/test/attachment_processing_test.rb +0 -29
  177. data/test/content_type_detector_test.rb +0 -40
  178. data/test/file_command_content_type_detector_test.rb +0 -25
  179. data/test/generator_test.rb +0 -80
  180. data/test/geometry_detector_test.rb +0 -24
  181. data/test/helper.rb +0 -199
  182. data/test/io_adapters/abstract_adapter_test.rb +0 -50
  183. data/test/io_adapters/file_adapter_test.rb +0 -100
  184. data/test/io_adapters/identity_adapter_test.rb +0 -8
  185. data/test/io_adapters/stringio_adapter_test.rb +0 -51
  186. data/test/io_adapters/uploaded_file_adapter_test.rb +0 -123
  187. data/test/io_adapters/uri_adapter_test.rb +0 -86
  188. data/test/matchers/have_attached_file_matcher_test.rb +0 -24
  189. data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -110
  190. data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -47
  191. data/test/matchers/validate_attachment_size_matcher_test.rb +0 -86
  192. data/test/meta_class_test.rb +0 -32
  193. data/test/paperclip_missing_attachment_styles_test.rb +0 -94
  194. data/test/paperclip_test.rb +0 -259
  195. data/test/schema_test.rb +0 -200
  196. data/test/storage/fog_test.rb +0 -453
  197. data/test/storage/s3_live_test.rb +0 -179
  198. data/test/storage/s3_test.rb +0 -1236
  199. data/test/style_test.rb +0 -213
  200. data/test/support/mock_model.rb +0 -2
  201. data/test/tempfile_factory_test.rb +0 -13
  202. data/test/url_generator_test.rb +0 -187
  203. data/test/validators/attachment_content_type_validator_test.rb +0 -292
  204. data/test/validators_test.rb +0 -25
  205. /data/{test → spec}/database.yml +0 -0
  206. /data/{test → spec/support}/fixtures/12k.png +0 -0
  207. /data/{test → spec/support}/fixtures/50x50.png +0 -0
  208. /data/{test → spec/support}/fixtures/5k.png +0 -0
  209. /data/{test → spec/support}/fixtures/animated +0 -0
  210. /data/{test → spec/support}/fixtures/animated.gif +0 -0
  211. /data/{test → spec/support}/fixtures/animated.unknown +0 -0
  212. /data/{test → spec/support}/fixtures/bad.png +0 -0
  213. /data/{test → spec/support}/fixtures/fog.yml +0 -0
  214. /data/{test → spec/support}/fixtures/rotated.jpg +0 -0
  215. /data/{test → spec/support}/fixtures/s3.yml +0 -0
  216. /data/{test → spec/support}/fixtures/spaced file.png +0 -0
  217. /data/{test → spec/support}/fixtures/text.txt +0 -0
  218. /data/{test → spec/support}/fixtures/twopage.pdf +0 -0
  219. /data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
  220. /data/{test → spec}/support/mock_interpolator.rb +0 -0
@@ -1,70 +1,38 @@
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
- teardown { @tempfile.close }
11
-
12
- should "have its path contain a real extension" do
13
- assert_equal ".jpg", File.extname(@tempfile.path)
14
- end
15
-
16
- should "be a real Tempfile" do
17
- assert @tempfile.is_a?(::Tempfile)
18
- end
19
- end
20
-
21
- context "Another Paperclip Tempfile" do
22
- setup do
23
- @tempfile = Paperclip::Tempfile.new("file")
24
- end
25
-
26
- teardown { @tempfile.close }
27
-
28
- should "not have an extension if not given one" do
29
- assert_equal "", File.extname(@tempfile.path)
30
- end
31
-
32
- should "still be a real Tempfile" do
33
- assert @tempfile.is_a?(::Tempfile)
34
- end
35
- end
1
+ require 'spec_helper'
36
2
 
3
+ describe Paperclip::Thumbnail do
37
4
  context "An image" do
38
- setup do
5
+ before do
39
6
  @file = File.new(fixture_file("5k.png"), 'rb')
40
7
  end
41
8
 
42
- teardown { @file.close }
9
+ after { @file.close }
43
10
 
44
11
  [["600x600>", "434x66"],
45
12
  ["400x400>", "400x61"],
46
- ["32x32<", "434x66"]
13
+ ["32x32<", "434x66"],
14
+ [nil, "434x66"]
47
15
  ].each do |args|
48
16
  context "being thumbnailed with a geometry of #{args[0]}" do
49
- setup do
50
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
17
+ before do
18
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: args[0])
51
19
  end
52
20
 
53
- should "start with dimensions of 434x66" do
21
+ it "starts with dimensions of 434x66" do
54
22
  cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
55
23
  assert_equal "434x66", `#{cmd}`.chomp
56
24
  end
57
25
 
58
- should "report the correct target geometry" do
59
- assert_equal args[0], @thumb.target_geometry.to_s
26
+ it "reports the correct target geometry" do
27
+ assert_equal args[0].to_s, @thumb.target_geometry.to_s
60
28
  end
61
29
 
62
30
  context "when made" do
63
- setup do
31
+ before do
64
32
  @thumb_result = @thumb.make
65
33
  end
66
34
 
67
- should "be the size we expect it to be" do
35
+ it "is the size we expect it to be" do
68
36
  cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
69
37
  assert_equal args[1], `#{cmd}`.chomp
70
38
  end
@@ -73,14 +41,14 @@ class ThumbnailTest < Test::Unit::TestCase
73
41
  end
74
42
 
75
43
  context "being thumbnailed at 100x50 with cropping" do
76
- setup do
77
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
44
+ before do
45
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
78
46
  end
79
47
 
80
- should "let us know when a command isn't found versus a processing error" do
48
+ it "lets us know when a command isn't found versus a processing error" do
81
49
  old_path = ENV['PATH']
82
50
  begin
83
- Cocaine::CommandLine.path = ''
51
+ Terrapin::CommandLine.path = ''
84
52
  Paperclip.options[:command_path] = ''
85
53
  ENV['PATH'] = ''
86
54
  assert_raises(Paperclip::Errors::CommandNotFoundError) do
@@ -93,28 +61,28 @@ class ThumbnailTest < Test::Unit::TestCase
93
61
  end
94
62
  end
95
63
 
96
- should "report its correct current and target geometries" do
64
+ it "reports its correct current and target geometries" do
97
65
  assert_equal "100x50#", @thumb.target_geometry.to_s
98
66
  assert_equal "434x66", @thumb.current_geometry.to_s
99
67
  end
100
68
 
101
- should "report its correct format" do
69
+ it "reports its correct format" do
102
70
  assert_nil @thumb.format
103
71
  end
104
72
 
105
- should "have whiny turned on by default" do
73
+ it "has whiny turned on by default" do
106
74
  assert @thumb.whiny
107
75
  end
108
76
 
109
- should "have convert_options set to nil by default" do
77
+ it "has convert_options set to nil by default" do
110
78
  assert_equal nil, @thumb.convert_options
111
79
  end
112
80
 
113
- should "have source_file_options set to nil by default" do
81
+ it "has source_file_options set to nil by default" do
114
82
  assert_equal nil, @thumb.source_file_options
115
83
  end
116
84
 
117
- should "send the right command to convert when sent #make" do
85
+ it "sends the right command to convert when sent #make" do
118
86
  @thumb.expects(:convert).with do |*arg|
119
87
  arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
120
88
  arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
@@ -122,34 +90,34 @@ class ThumbnailTest < Test::Unit::TestCase
122
90
  @thumb.make
123
91
  end
124
92
 
125
- should "create the thumbnail when sent #make" do
93
+ it "creates the thumbnail when sent #make" do
126
94
  dst = @thumb.make
127
95
  assert_match /100x50/, `identify "#{dst.path}"`
128
96
  end
129
97
  end
130
98
 
131
- should 'properly crop a EXIF-rotated image' do
99
+ it 'crops a EXIF-rotated image properly' do
132
100
  file = File.new(fixture_file('rotated.jpg'))
133
- thumb = Paperclip::Thumbnail.new(file, :geometry => "50x50#")
101
+ thumb = Paperclip::Thumbnail.new(file, geometry: "50x50#")
134
102
 
135
103
  output_file = thumb.make
136
104
 
137
- command = Cocaine::CommandLine.new("identify", "-format %wx%h :file")
138
- assert_equal "50x50", command.run(:file => output_file.path).strip
105
+ command = Terrapin::CommandLine.new("identify", "-format %wx%h :file")
106
+ assert_equal "50x50", command.run(file: output_file.path).strip
139
107
  end
140
108
 
141
109
  context "being thumbnailed with source file options set" do
142
- setup do
110
+ before do
143
111
  @thumb = Paperclip::Thumbnail.new(@file,
144
- :geometry => "100x50#",
145
- :source_file_options => "-strip")
112
+ geometry: "100x50#",
113
+ source_file_options: "-strip")
146
114
  end
147
115
 
148
- should "have source_file_options value set" do
116
+ it "has source_file_options value set" do
149
117
  assert_equal ["-strip"], @thumb.source_file_options
150
118
  end
151
119
 
152
- should "send the right command to convert when sent #make" do
120
+ it "sends the right command to convert when sent #make" do
153
121
  @thumb.expects(:convert).with do |*arg|
154
122
  arg[0] == '-strip :source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
155
123
  arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
@@ -157,19 +125,19 @@ class ThumbnailTest < Test::Unit::TestCase
157
125
  @thumb.make
158
126
  end
159
127
 
160
- should "create the thumbnail when sent #make" do
128
+ it "creates the thumbnail when sent #make" do
161
129
  dst = @thumb.make
162
130
  assert_match /100x50/, `identify "#{dst.path}"`
163
131
  end
164
132
 
165
133
  context "redefined to have bad source_file_options setting" do
166
- setup do
134
+ before do
167
135
  @thumb = Paperclip::Thumbnail.new(@file,
168
- :geometry => "100x50#",
169
- :source_file_options => "-this-aint-no-option")
136
+ geometry: "100x50#",
137
+ source_file_options: "-this-aint-no-option")
170
138
  end
171
139
 
172
- should "error when trying to create the thumbnail" do
140
+ it "errors when trying to create the thumbnail" do
173
141
  assert_raises(Paperclip::Error) do
174
142
  silence_stream(STDERR) do
175
143
  @thumb.make
@@ -180,17 +148,17 @@ class ThumbnailTest < Test::Unit::TestCase
180
148
  end
181
149
 
182
150
  context "being thumbnailed with convert options set" do
183
- setup do
151
+ before do
184
152
  @thumb = Paperclip::Thumbnail.new(@file,
185
- :geometry => "100x50#",
186
- :convert_options => "-strip -depth 8")
153
+ geometry: "100x50#",
154
+ convert_options: "-strip -depth 8")
187
155
  end
188
156
 
189
- should "have convert_options value set" do
157
+ it "has convert_options value set" do
190
158
  assert_equal %w"-strip -depth 8", @thumb.convert_options
191
159
  end
192
160
 
193
- should "send the right command to convert when sent #make" do
161
+ it "sends the right command to convert when sent #make" do
194
162
  @thumb.expects(:convert).with do |*arg|
195
163
  arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
196
164
  arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
@@ -198,30 +166,32 @@ class ThumbnailTest < Test::Unit::TestCase
198
166
  @thumb.make
199
167
  end
200
168
 
201
- should "create the thumbnail when sent #make" do
169
+ it "creates the thumbnail when sent #make" do
202
170
  dst = @thumb.make
203
171
  assert_match /100x50/, `identify "#{dst.path}"`
204
172
  end
205
173
 
206
174
  context "redefined to have bad convert_options setting" do
207
- setup do
175
+ before do
208
176
  @thumb = Paperclip::Thumbnail.new(@file,
209
- :geometry => "100x50#",
210
- :convert_options => "-this-aint-no-option")
177
+ geometry: "100x50#",
178
+ convert_options: "-this-aint-no-option")
211
179
  end
212
180
 
213
- should "error when trying to create the thumbnail" do
214
- assert_raises(Paperclip::Error) do
215
- silence_stream(STDERR) do
181
+ it "errors when trying to create the thumbnail" do
182
+ silence_stream(STDERR) do
183
+ expect {
216
184
  @thumb.make
217
- end
185
+ }.to raise_error(
186
+ Paperclip::Error, /unrecognized option `-this-aint-no-option'/
187
+ )
218
188
  end
219
189
  end
220
190
 
221
- should "let us know when a command isn't found versus a processing error" do
191
+ it "lets us know when a command isn't found versus a processing error" do
222
192
  old_path = ENV['PATH']
223
193
  begin
224
- Cocaine::CommandLine.path = ''
194
+ Terrapin::CommandLine.path = ''
225
195
  Paperclip.options[:command_path] = ''
226
196
  ENV['PATH'] = ''
227
197
  assert_raises(Paperclip::Errors::CommandNotFoundError) do
@@ -237,20 +207,20 @@ class ThumbnailTest < Test::Unit::TestCase
237
207
  end
238
208
 
239
209
  context "being thumbnailed with a blank geometry string" do
240
- setup do
210
+ before do
241
211
  @thumb = Paperclip::Thumbnail.new(@file,
242
- :geometry => "",
243
- :convert_options => "-gravity center -crop \"300x300+0-0\"")
212
+ geometry: "",
213
+ convert_options: "-gravity center -crop \"300x300+0-0\"")
244
214
  end
245
215
 
246
- should "not get resized by default" do
216
+ it "does not get resized by default" do
247
217
  assert !@thumb.transformation_command.include?("-resize")
248
218
  end
249
219
  end
250
220
 
251
221
  context "being thumbnailed with default animated option (true)" do
252
- should "call identify to check for animated images when sent #make" do
253
- thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
222
+ it "calls identify to check for animated images when sent #make" do
223
+ thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
254
224
  thumb.expects(:identify).at_least_once.with do |*arg|
255
225
  arg[0] == '-format %m :file' &&
256
226
  arg[1][:file] == "#{File.expand_path(thumb.file.path)}[0]"
@@ -260,11 +230,11 @@ class ThumbnailTest < Test::Unit::TestCase
260
230
  end
261
231
 
262
232
  context "passing a custom file geometry parser" do
263
- teardown do
264
- self.class.send(:remove_const, :GeoParser)
233
+ after do
234
+ Object.send(:remove_const, :GeoParser) if Object.const_defined?(:GeoParser)
265
235
  end
266
236
 
267
- should "produce the appropriate transformation_command" do
237
+ it "produces the appropriate transformation_command" do
268
238
  GeoParser = Class.new do
269
239
  def self.from_file(file)
270
240
  new
@@ -275,7 +245,7 @@ class ThumbnailTest < Test::Unit::TestCase
275
245
  end
276
246
  end
277
247
 
278
- thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :file_geometry_parser => GeoParser)
248
+ thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', file_geometry_parser: ::GeoParser)
279
249
 
280
250
  transformation_command = thumb.transformation_command
281
251
 
@@ -291,11 +261,11 @@ class ThumbnailTest < Test::Unit::TestCase
291
261
  end
292
262
 
293
263
  context "passing a custom geometry string parser" do
294
- teardown do
295
- self.class.send(:remove_const, :GeoParser)
264
+ after do
265
+ Object.send(:remove_const, :GeoParser) if Object.const_defined?(:GeoParser)
296
266
  end
297
267
 
298
- should "produce the appropriate transformation_command" do
268
+ it "produces the appropriate transformation_command" do
299
269
  GeoParser = Class.new do
300
270
  def self.parse(s)
301
271
  new
@@ -306,7 +276,7 @@ class ThumbnailTest < Test::Unit::TestCase
306
276
  end
307
277
  end
308
278
 
309
- thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :string_geometry_parser => GeoParser)
279
+ thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', string_geometry_parser: ::GeoParser)
310
280
 
311
281
  transformation_command = thumb.transformation_command
312
282
 
@@ -317,32 +287,32 @@ class ThumbnailTest < Test::Unit::TestCase
317
287
  end
318
288
 
319
289
  context "A multipage PDF" do
320
- setup do
290
+ before do
321
291
  @file = File.new(fixture_file("twopage.pdf"), 'rb')
322
292
  end
323
293
 
324
- teardown { @file.close }
294
+ after { @file.close }
325
295
 
326
- should "start with two pages with dimensions 612x792" do
296
+ it "starts with two pages with dimensions 612x792" do
327
297
  cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
328
298
  assert_equal "612x792"*2, `#{cmd}`.chomp
329
299
  end
330
300
 
331
301
  context "being thumbnailed at 100x100 with cropping" do
332
- setup do
333
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
302
+ before do
303
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "100x100#", format: :png)
334
304
  end
335
305
 
336
- should "report its correct current and target geometries" do
306
+ it "reports its correct current and target geometries" do
337
307
  assert_equal "100x100#", @thumb.target_geometry.to_s
338
308
  assert_equal "612x792", @thumb.current_geometry.to_s
339
309
  end
340
310
 
341
- should "report its correct format" do
311
+ it "reports its correct format" do
342
312
  assert_equal :png, @thumb.format
343
313
  end
344
314
 
345
- should "create the thumbnail when sent #make" do
315
+ it "creates the thumbnail when sent #make" do
346
316
  dst = @thumb.make
347
317
  assert_match /100x100/, `identify "#{dst.path}"`
348
318
  end
@@ -350,23 +320,23 @@ class ThumbnailTest < Test::Unit::TestCase
350
320
  end
351
321
 
352
322
  context "An animated gif" do
353
- setup do
323
+ before do
354
324
  @file = File.new(fixture_file("animated.gif"), 'rb')
355
325
  end
356
326
 
357
- teardown { @file.close }
327
+ after { @file.close }
358
328
 
359
- should "start with 12 frames with size 100x100" do
329
+ it "starts with 12 frames with size 100x100" do
360
330
  cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
361
331
  assert_equal "100x100"*12, `#{cmd}`.chomp
362
332
  end
363
333
 
364
334
  context "with static output" do
365
- setup do
366
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :jpg)
335
+ before do
336
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :jpg)
367
337
  end
368
338
 
369
- should "create the single frame thumbnail when sent #make" do
339
+ it "creates the single frame thumbnail when sent #make" do
370
340
  dst = @thumb.make
371
341
  cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
372
342
  assert_equal "50x50", `#{cmd}`.chomp
@@ -374,87 +344,162 @@ class ThumbnailTest < Test::Unit::TestCase
374
344
  end
375
345
 
376
346
  context "with animated output format" do
377
- setup do
378
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :gif)
347
+ before do
348
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
379
349
  end
380
350
 
381
- should "create the 12 frames thumbnail when sent #make" do
351
+ it "creates the 12 frames thumbnail when sent #make" do
382
352
  dst = @thumb.make
383
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
384
- assert_equal "50x50"*12, `#{cmd}`.chomp
353
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
354
+ frames = `#{cmd}`.chomp.split(',')
355
+ assert_equal 12, frames.size
356
+ assert_frame_dimensions (45..50), frames
385
357
  end
386
358
 
387
- should "use the -coalesce option" do
359
+ it "uses the -coalesce option" do
388
360
  assert_equal @thumb.transformation_command.first, "-coalesce"
389
361
  end
362
+
363
+ it "uses the -layers 'optimize' option" do
364
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
365
+ end
390
366
  end
391
367
 
392
368
  context "with omitted output format" do
393
- setup do
394
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50")
369
+ before do
370
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50")
395
371
  end
396
372
 
397
- should "create the 12 frames thumbnail when sent #make" do
373
+ it "creates the 12 frames thumbnail when sent #make" do
398
374
  dst = @thumb.make
399
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
400
- assert_equal "50x50"*12, `#{cmd}`.chomp
375
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
376
+ frames = `#{cmd}`.chomp.split(',')
377
+ assert_equal 12, frames.size
378
+ assert_frame_dimensions (45..50), frames
401
379
  end
402
380
 
403
- should "use the -coalesce option" do
381
+ it "uses the -coalesce option" do
404
382
  assert_equal @thumb.transformation_command.first, "-coalesce"
405
383
  end
384
+
385
+ it "uses the -layers 'optimize' option" do
386
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
387
+ end
406
388
  end
407
389
 
408
390
  context "with unidentified source format" do
409
- setup do
391
+ before do
410
392
  @unidentified_file = File.new(fixture_file("animated.unknown"), 'rb')
411
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "60x60")
393
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "60x60")
412
394
  end
413
395
 
414
- should "create the 12 frames thumbnail when sent #make" do
396
+ it "creates the 12 frames thumbnail when sent #make" do
415
397
  dst = @thumb.make
416
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
417
- assert_equal "60x60"*12, `#{cmd}`.chomp
398
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
399
+ frames = `#{cmd}`.chomp.split(',')
400
+ assert_equal 12, frames.size
401
+ assert_frame_dimensions (55..60), frames
418
402
  end
419
403
 
420
- should "use the -coalesce option" do
404
+ it "uses the -coalesce option" do
421
405
  assert_equal @thumb.transformation_command.first, "-coalesce"
422
406
  end
407
+
408
+ it "uses the -layers 'optimize' option" do
409
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
410
+ end
423
411
  end
424
412
 
425
413
  context "with no source format" do
426
- setup do
414
+ before do
427
415
  @unidentified_file = File.new(fixture_file("animated"), 'rb')
428
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "70x70")
416
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "70x70")
429
417
  end
430
418
 
431
- should "create the 12 frames thumbnail when sent #make" do
419
+ it "creates the 12 frames thumbnail when sent #make" do
432
420
  dst = @thumb.make
433
- cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
434
- assert_equal "70x70"*12, `#{cmd}`.chomp
421
+ cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
422
+ frames = `#{cmd}`.chomp.split(',')
423
+ assert_equal 12, frames.size
424
+ assert_frame_dimensions (60..70), frames
435
425
  end
436
426
 
437
- should "use the -coalesce option" do
427
+ it "uses the -coalesce option" do
438
428
  assert_equal @thumb.transformation_command.first, "-coalesce"
439
429
  end
430
+
431
+ it "uses the -layers 'optimize' option" do
432
+ assert_equal @thumb.transformation_command.last, '-layers "optimize"'
433
+ end
440
434
  end
441
435
 
442
436
  context "with animated option set to false" do
443
- setup do
444
- @thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :animated => false)
437
+ before do
438
+ @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", animated: false)
445
439
  end
446
440
 
447
- should "output the gif format" do
441
+ it "outputs the gif format" do
448
442
  dst = @thumb.make
449
443
  cmd = %Q[identify "#{dst.path}"]
450
444
  assert_match /GIF/, `#{cmd}`.chomp
451
445
  end
452
446
 
453
- should "create the single frame thumbnail when sent #make" do
447
+ it "creates the single frame thumbnail when sent #make" do
454
448
  dst = @thumb.make
455
449
  cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
456
450
  assert_equal "50x50", `#{cmd}`.chomp
457
451
  end
458
452
  end
453
+
454
+ context "with a specified frame_index" do
455
+ before do
456
+ @thumb = Paperclip::Thumbnail.new(
457
+ @file,
458
+ geometry: "50x50",
459
+ frame_index: 5,
460
+ format: :jpg,
461
+ )
462
+ end
463
+
464
+ it "creates the thumbnail from the frame index when sent #make" do
465
+ @thumb.make
466
+ assert_equal 5, @thumb.frame_index
467
+ end
468
+ end
469
+
470
+ context "with a specified frame_index out of bounds" do
471
+ before do
472
+ @thumb = Paperclip::Thumbnail.new(
473
+ @file,
474
+ geometry: "50x50",
475
+ frame_index: 20,
476
+ format: :jpg,
477
+ )
478
+ end
479
+
480
+ it "errors when trying to create the thumbnail" do
481
+ assert_raises(Paperclip::Error) do
482
+ silence_stream(STDERR) do
483
+ @thumb.make
484
+ end
485
+ end
486
+ end
487
+ end
488
+ end
489
+
490
+ context "with a really long file name" do
491
+ before do
492
+ tempfile = Tempfile.new("f")
493
+ tempfile_additional_chars = tempfile.path.split("/")[-1].length + 15
494
+ image_file = File.new(fixture_file("5k.png"), "rb")
495
+ @file = Tempfile.new("f" * (255 - tempfile_additional_chars))
496
+ @file.write(image_file.read)
497
+ @file.rewind
498
+ end
499
+
500
+ it "does not throw Errno::ENAMETOOLONG" do
501
+ thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
502
+ expect { thumb.make }.to_not raise_error
503
+ end
459
504
  end
460
505
  end