paperclip 3.5.4 → 5.3.0

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