paperclip 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.travis.yml +4 -13
  4. data/Appraisals +0 -10
  5. data/CONTRIBUTING.md +10 -5
  6. data/Gemfile +8 -4
  7. data/NEWS +1 -1
  8. data/README.md +51 -10
  9. data/Rakefile +6 -8
  10. data/features/basic_integration.feature +5 -5
  11. data/features/step_definitions/attachment_steps.rb +4 -4
  12. data/features/step_definitions/rails_steps.rb +4 -4
  13. data/features/step_definitions/web_steps.rb +2 -2
  14. data/features/support/env.rb +2 -2
  15. data/features/support/fixtures/gemfile.txt +1 -1
  16. data/features/support/rails.rb +2 -1
  17. data/gemfiles/3.2.gemfile +5 -3
  18. data/gemfiles/4.0.gemfile +5 -3
  19. data/gemfiles/4.1.gemfile +5 -3
  20. data/lib/generators/paperclip/paperclip_generator.rb +0 -2
  21. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
  22. data/lib/paperclip.rb +4 -1
  23. data/lib/paperclip/attachment.rb +90 -29
  24. data/lib/paperclip/content_type_detector.rb +1 -1
  25. data/lib/paperclip/geometry_detector_factory.rb +3 -1
  26. data/lib/paperclip/has_attached_file.rb +2 -1
  27. data/lib/paperclip/interpolations.rb +8 -0
  28. data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -1
  29. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  30. data/lib/paperclip/io_adapters/stringio_adapter.rb +5 -11
  31. data/lib/paperclip/locales/de.yml +18 -0
  32. data/lib/paperclip/locales/es.yml +18 -0
  33. data/lib/paperclip/matchers/have_attached_file_matcher.rb +2 -1
  34. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -1
  35. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
  36. data/lib/paperclip/media_type_spoof_detector.rb +10 -2
  37. data/lib/paperclip/storage/filesystem.rb +1 -1
  38. data/lib/paperclip/storage/s3.rb +26 -4
  39. data/lib/paperclip/style.rb +1 -1
  40. data/lib/paperclip/thumbnail.rb +6 -6
  41. data/lib/paperclip/validators.rb +5 -3
  42. data/lib/paperclip/validators/attachment_size_validator.rb +7 -3
  43. data/lib/paperclip/version.rb +1 -1
  44. data/lib/tasks/paperclip.rake +1 -2
  45. data/paperclip.gemspec +5 -3
  46. data/shoulda_macros/paperclip.rb +0 -1
  47. data/{test → spec}/database.yml +0 -0
  48. data/spec/paperclip/attachment_definitions_spec.rb +13 -0
  49. data/{test/attachment_processing_test.rb → spec/paperclip/attachment_processing_spec.rb} +20 -21
  50. data/{test/attachment_registry_test.rb → spec/paperclip/attachment_registry_spec.rb} +10 -11
  51. data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +367 -360
  52. data/{test/content_type_detector_test.rb → spec/paperclip/content_type_detector_spec.rb} +8 -8
  53. data/{test/file_command_content_type_detector_test.rb → spec/paperclip/file_command_content_type_detector_spec.rb} +5 -5
  54. data/spec/paperclip/filename_cleaner_spec.rb +14 -0
  55. data/spec/paperclip/geometry_detector_spec.rb +39 -0
  56. data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
  57. data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +49 -51
  58. data/{test/has_attached_file_test.rb → spec/paperclip/has_attached_file_spec.rb} +18 -27
  59. data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +134 -126
  60. data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +54 -40
  61. data/{test/io_adapters/abstract_adapter_test.rb → spec/paperclip/io_adapters/abstract_adapter_spec.rb} +21 -10
  62. data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +27 -29
  63. data/{test/io_adapters/data_uri_adapter_test.rb → spec/paperclip/io_adapters/data_uri_adapter_spec.rb} +22 -18
  64. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
  65. data/{test/io_adapters/file_adapter_test.rb → spec/paperclip/io_adapters/file_adapter_spec.rb} +32 -28
  66. data/{test/io_adapters/http_url_proxy_adapter_test.rb → spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb} +22 -22
  67. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
  68. data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
  69. data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +10 -7
  70. data/{test/io_adapters/stringio_adapter_test.rb → spec/paperclip/io_adapters/stringio_adapter_spec.rb} +16 -17
  71. data/{test/io_adapters/uploaded_file_adapter_test.rb → spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb} +41 -41
  72. data/{test/io_adapters/uri_adapter_test.rb → spec/paperclip/io_adapters/uri_adapter_spec.rb} +22 -22
  73. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
  74. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +99 -0
  75. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
  76. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
  77. data/{test/media_type_spoof_detector_test.rb → spec/paperclip/media_type_spoof_detector_spec.rb} +13 -8
  78. data/spec/paperclip/meta_class_spec.rb +30 -0
  79. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
  80. data/{test/paperclip_test.rb → spec/paperclip/paperclip_spec.rb} +47 -47
  81. data/{test/plural_cache_test.rb → spec/paperclip/plural_cache_spec.rb} +6 -6
  82. data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +5 -5
  83. data/{test/rake_test.rb → spec/paperclip/rake_spec.rb} +15 -15
  84. data/spec/paperclip/schema_spec.rb +206 -0
  85. data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
  86. data/{test/storage/fog_test.rb → spec/paperclip/storage/fog_spec.rb} +145 -140
  87. data/spec/paperclip/storage/s3_live_spec.rb +182 -0
  88. data/spec/paperclip/storage/s3_spec.rb +1475 -0
  89. data/spec/paperclip/style_spec.rb +255 -0
  90. data/spec/paperclip/tempfile_factory_spec.rb +29 -0
  91. data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +107 -107
  92. data/{test/url_generator_test.rb → spec/paperclip/url_generator_spec.rb} +55 -56
  93. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
  94. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
  95. data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +19 -19
  96. data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +65 -58
  97. data/{test/validators/media_type_spoof_detection_validator_test.rb → spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb} +8 -8
  98. data/spec/paperclip/validators_spec.rb +164 -0
  99. data/spec/spec_helper.rb +40 -0
  100. data/spec/support/assertions.rb +71 -0
  101. data/spec/support/fake_model.rb +21 -0
  102. data/spec/support/fake_rails.rb +12 -0
  103. data/{test → spec/support}/fixtures/12k.png +0 -0
  104. data/{test → spec/support}/fixtures/50x50.png +0 -0
  105. data/{test → spec/support}/fixtures/5k.png +0 -0
  106. data/{test → spec/support}/fixtures/animated +0 -0
  107. data/{test → spec/support}/fixtures/animated.gif +0 -0
  108. data/{test → spec/support}/fixtures/animated.unknown +0 -0
  109. data/{test → spec/support}/fixtures/bad.png +0 -0
  110. data/{test → spec/support}/fixtures/empty.html +0 -0
  111. data/{test → spec/support}/fixtures/fog.yml +0 -0
  112. data/{test → spec/support}/fixtures/rotated.jpg +0 -0
  113. data/{test → spec/support}/fixtures/s3.yml +0 -0
  114. data/spec/support/fixtures/spaced file.jpg +0 -0
  115. data/test/fixtures/spaced file.png b/data/spec/support/fixtures/spaced → file.png +0 -0
  116. data/{test → spec/support}/fixtures/text.txt +0 -0
  117. data/{test → spec/support}/fixtures/twopage.pdf +0 -0
  118. data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
  119. data/spec/support/matchers/accept.rb +5 -0
  120. data/spec/support/matchers/exist.rb +5 -0
  121. data/{test → spec}/support/mock_attachment.rb +0 -0
  122. data/{test → spec}/support/mock_interpolator.rb +0 -0
  123. data/{test → spec}/support/mock_model.rb +0 -0
  124. data/{test → spec}/support/mock_url_generator_builder.rb +0 -0
  125. data/spec/support/model_reconstruction.rb +60 -0
  126. data/spec/support/rails_helpers.rb +7 -0
  127. data/spec/support/test_data.rb +13 -0
  128. data/spec/support/version_helper.rb +9 -0
  129. metadata +256 -210
  130. data/gemfiles/3.0.gemfile +0 -11
  131. data/gemfiles/3.1.gemfile +0 -11
  132. data/test/attachment_definitions_test.rb +0 -13
  133. data/test/filename_cleaner_test.rb +0 -14
  134. data/test/generator_test.rb +0 -84
  135. data/test/geometry_detector_test.rb +0 -24
  136. data/test/helper.rb +0 -239
  137. data/test/io_adapters/empty_string_adapter_test.rb +0 -18
  138. data/test/io_adapters/identity_adapter_test.rb +0 -8
  139. data/test/matchers/have_attached_file_matcher_test.rb +0 -25
  140. data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -111
  141. data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -70
  142. data/test/matchers/validate_attachment_size_matcher_test.rb +0 -87
  143. data/test/meta_class_test.rb +0 -32
  144. data/test/paperclip_missing_attachment_styles_test.rb +0 -90
  145. data/test/schema_test.rb +0 -206
  146. data/test/storage/s3_live_test.rb +0 -179
  147. data/test/storage/s3_test.rb +0 -1357
  148. data/test/style_test.rb +0 -251
  149. data/test/tempfile_factory_test.rb +0 -29
  150. data/test/validators/attachment_content_type_validator_test.rb +0 -324
  151. data/test/validators/attachment_file_name_validator_test.rb +0 -162
  152. data/test/validators_test.rb +0 -101
@@ -1,7 +1,7 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
 
3
- class InterpolationsTest < Test::Unit::TestCase
4
- should "return all methods but the infrastructure when sent #all" do
3
+ describe Paperclip::Interpolations do
4
+ it "returns all methods but the infrastructure when sent #all" do
5
5
  methods = Paperclip::Interpolations.all
6
6
  assert ! methods.include?(:[])
7
7
  assert ! methods.include?(:[]=)
@@ -11,49 +11,49 @@ class InterpolationsTest < Test::Unit::TestCase
11
11
  end
12
12
  end
13
13
 
14
- should "return the Rails.root" do
14
+ it "returns the Rails.root" do
15
15
  assert_equal Rails.root, Paperclip::Interpolations.rails_root(:attachment, :style)
16
16
  end
17
17
 
18
- should "return the Rails.env" do
18
+ it "returns the Rails.env" do
19
19
  assert_equal Rails.env, Paperclip::Interpolations.rails_env(:attachment, :style)
20
20
  end
21
21
 
22
- should "return the class of the Interpolations module when called with no params" do
22
+ it "returns the class of the Interpolations module when called with no params" do
23
23
  assert_equal Module, Paperclip::Interpolations.class
24
24
  end
25
25
 
26
- should "return the class of the instance" do
26
+ it "returns the class of the instance" do
27
27
  attachment = mock
28
28
  attachment.expects(:instance).returns(attachment)
29
29
  attachment.expects(:class).returns("Thing")
30
30
  assert_equal "things", Paperclip::Interpolations.class(attachment, :style)
31
31
  end
32
32
 
33
- should "return the basename of the file" do
33
+ it "returns the basename of the file" do
34
34
  attachment = mock
35
35
  attachment.expects(:original_filename).returns("one.jpg").times(2)
36
36
  assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
37
37
  end
38
38
 
39
- should "return the extension of the file" do
39
+ it "returns the extension of the file" do
40
40
  attachment = mock
41
41
  attachment.expects(:original_filename).returns("one.jpg")
42
42
  attachment.expects(:styles).returns({})
43
43
  assert_equal "jpg", Paperclip::Interpolations.extension(attachment, :style)
44
44
  end
45
45
 
46
- should "return the extension of the file as the format if defined in the style" do
46
+ it "returns the extension of the file as the format if defined in the style" do
47
47
  attachment = mock
48
48
  attachment.expects(:original_filename).never
49
- attachment.expects(:styles).twice.returns({:style => {:format => "png"}})
49
+ attachment.expects(:styles).twice.returns({style: {format: "png"}})
50
50
 
51
51
  [:style, 'style'].each do |style|
52
52
  assert_equal "png", Paperclip::Interpolations.extension(attachment, style)
53
53
  end
54
54
  end
55
55
 
56
- should "return the extension of the file based on the content type" do
56
+ it "returns the extension of the file based on the content type" do
57
57
  attachment = mock
58
58
  attachment.expects(:content_type).returns('image/jpeg')
59
59
  attachment.expects(:styles).returns({})
@@ -62,7 +62,7 @@ class InterpolationsTest < Test::Unit::TestCase
62
62
  assert_equal "jpeg", interpolations.content_type_extension(attachment, :style)
63
63
  end
64
64
 
65
- should "return the original extension of the file if it matches a content type extension" do
65
+ it "returns the original extension of the file if it matches a content type extension" do
66
66
  attachment = mock
67
67
  attachment.expects(:content_type).returns('image/jpeg')
68
68
  attachment.expects(:styles).returns({})
@@ -71,7 +71,21 @@ class InterpolationsTest < Test::Unit::TestCase
71
71
  assert_equal "jpe", interpolations.content_type_extension(attachment, :style)
72
72
  end
73
73
 
74
- should "return the latter half of the content type of the extension if no match found" do
74
+ it "returns the extension of the file with a dot" do
75
+ attachment = mock
76
+ attachment.expects(:original_filename).returns("one.jpg")
77
+ attachment.expects(:styles).returns({})
78
+ assert_equal ".jpg", Paperclip::Interpolations.dotextension(attachment, :style)
79
+ end
80
+
81
+ it "returns the extension of the file without a dot if the extension is empty" do
82
+ attachment = mock
83
+ attachment.expects(:original_filename).returns("one")
84
+ attachment.expects(:styles).returns({})
85
+ assert_equal "", Paperclip::Interpolations.dotextension(attachment, :style)
86
+ end
87
+
88
+ it "returns the latter half of the content type of the extension if no match found" do
75
89
  attachment = mock
76
90
  attachment.expects(:content_type).at_least_once().returns('not/found')
77
91
  attachment.expects(:styles).returns({})
@@ -80,87 +94,87 @@ class InterpolationsTest < Test::Unit::TestCase
80
94
  assert_equal "found", interpolations.content_type_extension(attachment, :style)
81
95
  end
82
96
 
83
- should "return the format if defined in the style, ignoring the content type" do
97
+ it "returns the format if defined in the style, ignoring the content type" do
84
98
  attachment = mock
85
99
  attachment.expects(:content_type).returns('image/jpeg')
86
- attachment.expects(:styles).returns({:style => {:format => "png"}})
100
+ attachment.expects(:styles).returns({style: {format: "png"}})
87
101
  interpolations = Paperclip::Interpolations
88
102
  interpolations.expects(:extension).returns('random')
89
103
  assert_equal "png", interpolations.content_type_extension(attachment, :style)
90
104
  end
91
105
 
92
- should "be able to handle numeric style names" do
106
+ it "is able to handle numeric style names" do
93
107
  attachment = mock(
94
- :styles => {:"4" => {:format => :expected_extension}}
108
+ styles: {:"4" => {format: :expected_extension}}
95
109
  )
96
110
  assert_equal :expected_extension, Paperclip::Interpolations.extension(attachment, 4)
97
111
  end
98
112
 
99
- should "return the #to_param of the attachment" do
113
+ it "returns the #to_param of the attachment" do
100
114
  attachment = mock
101
115
  attachment.expects(:to_param).returns("23-awesome")
102
116
  attachment.expects(:instance).returns(attachment)
103
117
  assert_equal "23-awesome", Paperclip::Interpolations.param(attachment, :style)
104
118
  end
105
119
 
106
- should "return the id of the attachment" do
120
+ it "returns the id of the attachment" do
107
121
  attachment = mock
108
122
  attachment.expects(:id).returns(23)
109
123
  attachment.expects(:instance).returns(attachment)
110
124
  assert_equal 23, Paperclip::Interpolations.id(attachment, :style)
111
125
  end
112
126
 
113
- should "return nil for attachments to new records" do
127
+ it "returns nil for attachments to new records" do
114
128
  attachment = mock
115
129
  attachment.expects(:id).returns(nil)
116
130
  attachment.expects(:instance).returns(attachment)
117
131
  assert_nil Paperclip::Interpolations.id(attachment, :style)
118
132
  end
119
133
 
120
- should "return the partitioned id of the attachment when the id is an integer" do
134
+ it "returns the partitioned id of the attachment when the id is an integer" do
121
135
  attachment = mock
122
136
  attachment.expects(:id).returns(23)
123
137
  attachment.expects(:instance).returns(attachment)
124
138
  assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style)
125
139
  end
126
140
 
127
- should "return the partitioned id of the attachment when the id is a string" do
141
+ it "returns the partitioned id of the attachment when the id is a string" do
128
142
  attachment = mock
129
143
  attachment.expects(:id).returns("32fnj23oio2f")
130
144
  attachment.expects(:instance).returns(attachment)
131
145
  assert_equal "32f/nj2/3oi", Paperclip::Interpolations.id_partition(attachment, :style)
132
146
  end
133
147
 
134
- should "return nil for the partitioned id of an attachment to a new record (when the id is nil)" do
148
+ it "returns nil for the partitioned id of an attachment to a new record (when the id is nil)" do
135
149
  attachment = mock
136
150
  attachment.expects(:id).returns(nil)
137
151
  attachment.expects(:instance).returns(attachment)
138
152
  assert_nil Paperclip::Interpolations.id_partition(attachment, :style)
139
153
  end
140
154
 
141
- should "return the name of the attachment" do
155
+ it "returns the name of the attachment" do
142
156
  attachment = mock
143
157
  attachment.expects(:name).returns("file")
144
158
  assert_equal "files", Paperclip::Interpolations.attachment(attachment, :style)
145
159
  end
146
160
 
147
- should "return the style" do
161
+ it "returns the style" do
148
162
  assert_equal :style, Paperclip::Interpolations.style(:attachment, :style)
149
163
  end
150
164
 
151
- should "return the default style" do
165
+ it "returns the default style" do
152
166
  attachment = mock
153
167
  attachment.expects(:default_style).returns(:default_style)
154
168
  assert_equal :default_style, Paperclip::Interpolations.style(attachment, nil)
155
169
  end
156
170
 
157
- should "reinterpolate :url" do
171
+ it "reinterpolates :url" do
158
172
  attachment = mock
159
- attachment.expects(:url).with(:style, :timestamp => false, :escape => false).returns("1234")
173
+ attachment.expects(:url).with(:style, timestamp: false, escape: false).returns("1234")
160
174
  assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
161
175
  end
162
176
 
163
- should "raise if infinite loop detcted reinterpolating :url" do
177
+ it "raises if infinite loop detcted reinterpolating :url" do
164
178
  attachment = Object.new
165
179
  class << attachment
166
180
  def url(*args)
@@ -170,35 +184,35 @@ class InterpolationsTest < Test::Unit::TestCase
170
184
  assert_raises(Paperclip::Errors::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
171
185
  end
172
186
 
173
- should "return the filename as basename.extension" do
187
+ it "returns the filename as basename.extension" do
174
188
  attachment = mock
175
189
  attachment.expects(:styles).returns({})
176
190
  attachment.expects(:original_filename).returns("one.jpg").times(3)
177
191
  assert_equal "one.jpg", Paperclip::Interpolations.filename(attachment, :style)
178
192
  end
179
193
 
180
- should "return the filename as basename.extension when format supplied" do
194
+ it "returns the filename as basename.extension when format supplied" do
181
195
  attachment = mock
182
- attachment.expects(:styles).returns({:style => {:format => :png}})
196
+ attachment.expects(:styles).returns({style: {format: :png}})
183
197
  attachment.expects(:original_filename).returns("one.jpg").times(2)
184
198
  assert_equal "one.png", Paperclip::Interpolations.filename(attachment, :style)
185
199
  end
186
200
 
187
- should "return the filename as basename when extension is blank" do
201
+ it "returns the filename as basename when extension is blank" do
188
202
  attachment = mock
189
203
  attachment.stubs(:styles).returns({})
190
204
  attachment.stubs(:original_filename).returns("one")
191
205
  assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
192
206
  end
193
207
 
194
- should "return the basename when the extension contains regexp special characters" do
208
+ it "returns the basename when the extension contains regexp special characters" do
195
209
  attachment = mock
196
210
  attachment.stubs(:styles).returns({})
197
211
  attachment.stubs(:original_filename).returns("one.ab)")
198
212
  assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
199
213
  end
200
214
 
201
- should "return the timestamp" do
215
+ it "returns the timestamp" do
202
216
  now = Time.now
203
217
  zone = 'UTC'
204
218
  attachment = mock
@@ -207,28 +221,28 @@ class InterpolationsTest < Test::Unit::TestCase
207
221
  assert_equal now.in_time_zone(zone).to_s, Paperclip::Interpolations.timestamp(attachment, :style)
208
222
  end
209
223
 
210
- should "return updated_at" do
224
+ it "returns updated_at" do
211
225
  attachment = mock
212
226
  seconds_since_epoch = 1234567890
213
227
  attachment.expects(:updated_at).returns(seconds_since_epoch)
214
228
  assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style)
215
229
  end
216
230
 
217
- should "return attachment's hash when passing both arguments" do
231
+ it "returns attachment's hash when passing both arguments" do
218
232
  attachment = mock
219
233
  fake_hash = "a_wicked_secure_hash"
220
234
  attachment.expects(:hash_key).returns(fake_hash)
221
235
  assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style)
222
236
  end
223
237
 
224
- should "return Object#hash when passing no argument" do
238
+ it "returns Object#hash when passing no argument" do
225
239
  attachment = mock
226
240
  fake_hash = "a_wicked_secure_hash"
227
241
  attachment.expects(:hash_key).never.returns(fake_hash)
228
242
  assert_not_equal fake_hash, Paperclip::Interpolations.hash
229
243
  end
230
244
 
231
- should "call all expected interpolations with the given arguments" do
245
+ it "calls all expected interpolations with the given arguments" do
232
246
  Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234)
233
247
  Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments")
234
248
  Paperclip::Interpolations.expects(:notreal).never
@@ -1,6 +1,6 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
 
3
- class AbstractAdapterTest < Test::Unit::TestCase
3
+ describe Paperclip::AbstractAdapter do
4
4
  class TestAdapter < Paperclip::AbstractAdapter
5
5
  attr_accessor :tempfile
6
6
 
@@ -10,31 +10,31 @@ class AbstractAdapterTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  context "content type from file command" do
13
- setup do
13
+ before do
14
14
  @adapter = TestAdapter.new
15
15
  @adapter.stubs(:path).returns("image.png")
16
16
  Paperclip.stubs(:run).returns("image/png\n")
17
17
  end
18
18
 
19
- should "return the content type without newline" do
19
+ it "returns the content type without newline" do
20
20
  assert_equal "image/png", @adapter.content_type
21
21
  end
22
22
  end
23
23
 
24
24
  context "nil?" do
25
- should "return false" do
25
+ it "returns false" do
26
26
  assert !TestAdapter.new.nil?
27
27
  end
28
28
  end
29
29
 
30
30
  context "delegation" do
31
- setup do
31
+ before do
32
32
  @adapter = TestAdapter.new
33
33
  @adapter.tempfile = stub("Tempfile")
34
34
  end
35
35
 
36
36
  [:binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :rewind, :unlink].each do |method|
37
- should "delegate #{method} to @tempfile" do
37
+ it "delegates #{method} to @tempfile" do
38
38
  @adapter.tempfile.stubs(method)
39
39
  @adapter.public_send(method)
40
40
  assert_received @adapter.tempfile, method
@@ -42,18 +42,29 @@ class AbstractAdapterTest < Test::Unit::TestCase
42
42
  end
43
43
  end
44
44
 
45
- should 'get rid of slashes and colons in filenames' do
45
+ it 'gets rid of slashes and colons in filenames' do
46
46
  @adapter = TestAdapter.new
47
47
  @adapter.original_filename = "awesome/file:name.png"
48
48
 
49
49
  assert_equal "awesome_file_name.png", @adapter.original_filename
50
50
  end
51
51
 
52
- should 'be an assignment' do
52
+ it 'is an assignment' do
53
53
  assert TestAdapter.new.assignment?
54
54
  end
55
55
 
56
- should 'not be nil' do
56
+ it 'is not nil' do
57
57
  assert !TestAdapter.new.nil?
58
58
  end
59
+
60
+ it "generates a destination filename with no original filename" do
61
+ @adapter = TestAdapter.new
62
+ expect(@adapter.send(:destination).path).to_not be_nil
63
+ end
64
+
65
+ it 'uses the original filename to generate the tempfile' do
66
+ @adapter = TestAdapter.new
67
+ @adapter.original_filename = "file.png"
68
+ expect(@adapter.send(:destination).path).to end_with(".png")
69
+ end
59
70
  end
@@ -1,15 +1,13 @@
1
- require './test/helper'
2
- require 'pp'
1
+ require 'spec_helper'
3
2
 
4
- class AttachmentAdapterTest < Test::Unit::TestCase
5
-
6
- def setup
7
- rebuild_model :path => "tmp/:class/:attachment/:style/:filename", :styles => {:thumb => '50x50'}
3
+ describe Paperclip::AttachmentAdapter do
4
+ before do
5
+ rebuild_model path: "tmp/:class/:attachment/:style/:filename", styles: {thumb: '50x50'}
8
6
  @attachment = Dummy.new.avatar
9
7
  end
10
8
 
11
9
  context "for an attachment" do
12
- setup do
10
+ before do
13
11
  @file = File.new(fixture_file("5k.png"))
14
12
  @file.binmode
15
13
 
@@ -18,37 +16,37 @@ class AttachmentAdapterTest < Test::Unit::TestCase
18
16
  @subject = Paperclip.io_adapters.for(@attachment)
19
17
  end
20
18
 
21
- teardown do
19
+ after do
22
20
  @file.close
23
21
  @subject.close
24
22
  end
25
23
 
26
- should "get the right filename" do
24
+ it "gets the right filename" do
27
25
  assert_equal "5k.png", @subject.original_filename
28
26
  end
29
27
 
30
- should "force binmode on tempfile" do
28
+ it "forces binmode on tempfile" do
31
29
  assert @subject.instance_variable_get("@tempfile").binmode?
32
30
  end
33
31
 
34
- should "get the content type" do
32
+ it "gets the content type" do
35
33
  assert_equal "image/png", @subject.content_type
36
34
  end
37
35
 
38
- should "get the file's size" do
36
+ it "gets the file's size" do
39
37
  assert_equal 4456, @subject.size
40
38
  end
41
39
 
42
- should "return false for a call to nil?" do
40
+ it "returns false for a call to nil?" do
43
41
  assert ! @subject.nil?
44
42
  end
45
43
 
46
- should "generate a MD5 hash of the contents" do
44
+ it "generates a MD5 hash of the contents" do
47
45
  expected = Digest::MD5.file(@file.path).to_s
48
46
  assert_equal expected, @subject.fingerprint
49
47
  end
50
48
 
51
- should "read the contents of the file" do
49
+ it "reads the contents of the file" do
52
50
  expected = @file.read
53
51
  actual = @subject.read
54
52
  assert expected.length > 0
@@ -59,7 +57,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
59
57
  end
60
58
 
61
59
  context "for a file with restricted characters in the name" do
62
- setup do
60
+ before do
63
61
  file_contents = IO.read(fixture_file("animated.gif"))
64
62
  @file = StringIO.new(file_contents)
65
63
  @file.stubs(:original_filename).returns('image:restricted.gif')
@@ -70,21 +68,21 @@ class AttachmentAdapterTest < Test::Unit::TestCase
70
68
  @subject = Paperclip.io_adapters.for(@attachment)
71
69
  end
72
70
 
73
- teardown do
71
+ after do
74
72
  @subject.close
75
73
  end
76
74
 
77
- should "not generate paths that include restricted characters" do
78
- assert_no_match(/:/, @subject.path)
75
+ it "does not generate paths that include restricted characters" do
76
+ expect(@subject.path).to_not match(/:/)
79
77
  end
80
78
 
81
- should "not generate filenames that include restricted characters" do
79
+ it "does not generate filenames that include restricted characters" do
82
80
  assert_equal 'image_restricted.gif', @subject.original_filename
83
81
  end
84
82
  end
85
83
 
86
84
  context "for a style" do
87
- setup do
85
+ before do
88
86
  @file = File.new(fixture_file("5k.png"))
89
87
  @file.binmode
90
88
 
@@ -97,38 +95,38 @@ class AttachmentAdapterTest < Test::Unit::TestCase
97
95
  @subject = Paperclip.io_adapters.for(@attachment.styles[:thumb])
98
96
  end
99
97
 
100
- teardown do
98
+ after do
101
99
  @file.close
102
100
  @thumb.close
103
101
  @subject.close
104
102
  end
105
103
 
106
- should "get the original filename" do
104
+ it "gets the original filename" do
107
105
  assert_equal "5k.png", @subject.original_filename
108
106
  end
109
107
 
110
- should "force binmode on tempfile" do
108
+ it "forces binmode on tempfile" do
111
109
  assert @subject.instance_variable_get("@tempfile").binmode?
112
110
  end
113
111
 
114
- should "get the content type" do
112
+ it "gets the content type" do
115
113
  assert_equal "image/png", @subject.content_type
116
114
  end
117
115
 
118
- should "get the thumbnail's file size" do
116
+ it "gets the thumbnail's file size" do
119
117
  assert_equal @thumb.size, @subject.size
120
118
  end
121
119
 
122
- should "return false for a call to nil?" do
120
+ it "returns false for a call to nil?" do
123
121
  assert ! @subject.nil?
124
122
  end
125
123
 
126
- should "generate a MD5 hash of the contents" do
124
+ it "generates a MD5 hash of the contents" do
127
125
  expected = Digest::MD5.file(@thumb.path).to_s
128
126
  assert_equal expected, @subject.fingerprint
129
127
  end
130
128
 
131
- should "read the contents of the thumbnail" do
129
+ it "reads the contents of the thumbnail" do
132
130
  @thumb.rewind
133
131
  expected = @thumb.read
134
132
  actual = @subject.read