paperclip 3.0.3 → 3.5.1
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.
- checksums.yaml +15 -0
- data/.gitignore +2 -1
- data/.travis.yml +3 -0
- data/Appraisals +8 -3
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/NEWS +198 -35
- data/README.md +332 -113
- data/features/basic_integration.feature +24 -12
- data/features/migration.feature +94 -0
- data/features/rake_tasks.feature +2 -3
- data/features/step_definitions/attachment_steps.rb +28 -0
- data/features/step_definitions/rails_steps.rb +94 -8
- data/features/step_definitions/s3_steps.rb +1 -1
- data/features/step_definitions/web_steps.rb +3 -3
- data/features/support/fakeweb.rb +4 -1
- data/features/support/file_helpers.rb +10 -0
- data/features/support/rails.rb +18 -2
- data/gemfiles/3.0.gemfile +2 -2
- data/gemfiles/3.1.gemfile +2 -2
- data/gemfiles/3.2.gemfile +2 -2
- data/gemfiles/4.0.gemfile +11 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +4 -8
- data/lib/paperclip/attachment.rb +96 -43
- data/lib/paperclip/attachment_registry.rb +57 -0
- data/lib/paperclip/callbacks.rb +2 -2
- data/lib/paperclip/content_type_detector.rb +78 -0
- data/lib/paperclip/file_command_content_type_detector.rb +32 -0
- data/lib/paperclip/filename_cleaner.rb +16 -0
- data/lib/paperclip/geometry.rb +66 -30
- data/lib/paperclip/geometry_detector_factory.rb +41 -0
- data/lib/paperclip/geometry_parser_factory.rb +31 -0
- data/lib/paperclip/glue.rb +2 -8
- data/lib/paperclip/has_attached_file.rb +99 -0
- data/lib/paperclip/helpers.rb +12 -15
- data/lib/paperclip/interpolations/plural_cache.rb +17 -0
- data/lib/paperclip/interpolations.rb +15 -5
- data/lib/paperclip/io_adapters/abstract_adapter.rb +45 -0
- data/lib/paperclip/io_adapters/attachment_adapter.rb +14 -49
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +27 -0
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +18 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +8 -69
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/nil_adapter.rb +2 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +16 -45
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +17 -40
- data/lib/paperclip/io_adapters/uri_adapter.rb +44 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +1 -5
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +36 -17
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +5 -1
- data/lib/paperclip/matchers.rb +3 -3
- data/lib/paperclip/missing_attachment_styles.rb +11 -16
- data/lib/paperclip/processor.rb +12 -0
- data/lib/paperclip/railtie.rb +5 -1
- data/lib/paperclip/schema.rb +59 -23
- data/lib/paperclip/storage/filesystem.rb +23 -5
- data/lib/paperclip/storage/fog.rb +64 -25
- data/lib/paperclip/storage/s3.rb +93 -52
- data/lib/paperclip/style.rb +2 -2
- data/lib/paperclip/tempfile_factory.rb +21 -0
- data/lib/paperclip/thumbnail.rb +18 -3
- data/lib/paperclip/validators/attachment_content_type_validator.rb +38 -10
- data/lib/paperclip/validators/attachment_presence_validator.rb +8 -8
- data/lib/paperclip/validators/attachment_size_validator.rb +12 -7
- data/lib/paperclip/validators.rb +21 -2
- data/lib/paperclip/version.rb +1 -1
- data/lib/paperclip.rb +15 -44
- data/lib/tasks/paperclip.rake +26 -7
- data/paperclip.gemspec +11 -7
- data/test/attachment_definitions_test.rb +12 -0
- data/test/attachment_processing_test.rb +83 -0
- data/test/attachment_registry_test.rb +77 -0
- data/test/attachment_test.rb +253 -44
- data/test/content_type_detector_test.rb +50 -0
- data/test/file_command_content_type_detector_test.rb +25 -0
- data/test/filename_cleaner_test.rb +14 -0
- data/test/fixtures/animated +0 -0
- data/test/fixtures/animated.unknown +0 -0
- data/test/fixtures/rotated.jpg +0 -0
- data/test/generator_test.rb +26 -24
- data/test/geometry_detector_test.rb +24 -0
- data/test/geometry_parser_test.rb +73 -0
- data/test/geometry_test.rb +55 -4
- data/test/has_attached_file_test.rb +125 -0
- data/test/helper.rb +38 -7
- data/test/integration_test.rb +105 -89
- data/test/interpolations_test.rb +12 -0
- data/test/io_adapters/abstract_adapter_test.rb +58 -0
- data/test/io_adapters/attachment_adapter_test.rb +120 -33
- data/test/io_adapters/data_uri_adapter_test.rb +60 -0
- data/test/io_adapters/empty_string_adapter_test.rb +17 -0
- data/test/io_adapters/file_adapter_test.rb +32 -1
- data/test/io_adapters/stringio_adapter_test.rb +29 -10
- data/test/io_adapters/uploaded_file_adapter_test.rb +53 -5
- data/test/io_adapters/uri_adapter_test.rb +102 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +22 -0
- data/test/meta_class_test.rb +32 -0
- data/test/paperclip_missing_attachment_styles_test.rb +4 -8
- data/test/paperclip_test.rb +27 -51
- data/test/plural_cache_test.rb +36 -0
- data/test/processor_test.rb +16 -0
- data/test/rake_test.rb +103 -0
- data/test/schema_test.rb +179 -77
- data/test/storage/filesystem_test.rb +26 -3
- data/test/storage/fog_test.rb +181 -3
- data/test/storage/s3_test.rb +239 -4
- data/test/style_test.rb +18 -14
- data/test/tempfile_factory_test.rb +13 -0
- data/test/thumbnail_test.rb +96 -16
- data/test/validators/attachment_content_type_validator_test.rb +181 -55
- data/test/validators/attachment_size_validator_test.rb +10 -0
- data/test/validators_test.rb +8 -1
- metadata +126 -92
- data/Gemfile.lock +0 -157
- data/features/support/fixtures/.boot_config.rb.swo +0 -0
- data/images.rake +0 -21
- data/lib/.DS_Store +0 -0
- data/lib/paperclip/.DS_Store +0 -0
- data/lib/paperclip/attachment_options.rb +0 -9
- data/lib/paperclip/instance_methods.rb +0 -35
- data/test/attachment_options_test.rb +0 -27
@@ -50,6 +50,32 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
context "with a failing validation" do
|
54
|
+
setup do
|
55
|
+
build_validator :content_type => "image/png", :allow_nil => false
|
56
|
+
@dummy.stubs(:avatar_content_type => nil)
|
57
|
+
@validator.validate(@dummy)
|
58
|
+
end
|
59
|
+
|
60
|
+
should "add error to the base object" do
|
61
|
+
assert @dummy.errors[:avatar].present?,
|
62
|
+
"Error not added to base attribute"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with a successful validation" do
|
67
|
+
setup do
|
68
|
+
build_validator :content_type => "image/png", :allow_nil => false
|
69
|
+
@dummy.stubs(:avatar_content_type => "image/png")
|
70
|
+
@validator.validate(@dummy)
|
71
|
+
end
|
72
|
+
|
73
|
+
should "not add error to the base object" do
|
74
|
+
assert @dummy.errors[:avatar].blank?,
|
75
|
+
"Error was added to base attribute"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
53
79
|
context "with :allow_blank option" do
|
54
80
|
context "as true" do
|
55
81
|
setup do
|
@@ -76,93 +102,189 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
|
|
76
102
|
end
|
77
103
|
end
|
78
104
|
|
79
|
-
context "
|
80
|
-
context "
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
105
|
+
context "whitelist format" do
|
106
|
+
context "with an allowed type" do
|
107
|
+
context "as a string" do
|
108
|
+
setup do
|
109
|
+
build_validator :content_type => "image/jpg"
|
110
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
111
|
+
@validator.validate(@dummy)
|
112
|
+
end
|
86
113
|
|
87
|
-
|
88
|
-
|
114
|
+
should "not set an error message" do
|
115
|
+
assert @dummy.errors[:avatar_content_type].blank?
|
116
|
+
end
|
89
117
|
end
|
90
|
-
end
|
91
118
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
119
|
+
context "as an regexp" do
|
120
|
+
setup do
|
121
|
+
build_validator :content_type => /^image\/.*/
|
122
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
123
|
+
@validator.validate(@dummy)
|
124
|
+
end
|
125
|
+
|
126
|
+
should "not set an error message" do
|
127
|
+
assert @dummy.errors[:avatar_content_type].blank?
|
128
|
+
end
|
97
129
|
end
|
98
130
|
|
99
|
-
|
100
|
-
|
131
|
+
context "as a list" do
|
132
|
+
setup do
|
133
|
+
build_validator :content_type => ["image/png", "image/jpg", "image/jpeg"]
|
134
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
135
|
+
@validator.validate(@dummy)
|
136
|
+
end
|
137
|
+
|
138
|
+
should "not set an error message" do
|
139
|
+
assert @dummy.errors[:avatar_content_type].blank?
|
140
|
+
end
|
101
141
|
end
|
102
142
|
end
|
103
143
|
|
104
|
-
context "
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
144
|
+
context "with a disallowed type" do
|
145
|
+
context "as a string" do
|
146
|
+
setup do
|
147
|
+
build_validator :content_type => "image/png"
|
148
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
149
|
+
@validator.validate(@dummy)
|
150
|
+
end
|
151
|
+
|
152
|
+
should "set a correct default error message" do
|
153
|
+
assert @dummy.errors[:avatar_content_type].present?
|
154
|
+
assert_includes @dummy.errors[:avatar_content_type], "is invalid"
|
155
|
+
end
|
109
156
|
end
|
110
157
|
|
111
|
-
|
112
|
-
|
158
|
+
context "as a regexp" do
|
159
|
+
setup do
|
160
|
+
build_validator :content_type => /^text\/.*/
|
161
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
162
|
+
@validator.validate(@dummy)
|
163
|
+
end
|
164
|
+
|
165
|
+
should "set a correct default error message" do
|
166
|
+
assert @dummy.errors[:avatar_content_type].present?
|
167
|
+
assert_includes @dummy.errors[:avatar_content_type], "is invalid"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "with :message option" do
|
172
|
+
context "without interpolation" do
|
173
|
+
setup do
|
174
|
+
build_validator :content_type => "image/png", :message => "should be a PNG image"
|
175
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
176
|
+
@validator.validate(@dummy)
|
177
|
+
end
|
178
|
+
|
179
|
+
should "set a correct error message" do
|
180
|
+
assert_includes @dummy.errors[:avatar_content_type], "should be a PNG image"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "with interpolation" do
|
185
|
+
setup do
|
186
|
+
build_validator :content_type => "image/png", :message => "should have content type %{types}"
|
187
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
188
|
+
@validator.validate(@dummy)
|
189
|
+
end
|
190
|
+
|
191
|
+
should "set a correct error message" do
|
192
|
+
assert_includes @dummy.errors[:avatar_content_type], "should have content type image/png"
|
193
|
+
end
|
194
|
+
end
|
113
195
|
end
|
114
196
|
end
|
115
197
|
end
|
116
198
|
|
117
|
-
context "
|
118
|
-
context "
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
199
|
+
context "blacklist format" do
|
200
|
+
context "with an allowed type" do
|
201
|
+
context "as a string" do
|
202
|
+
setup do
|
203
|
+
build_validator :not => "image/gif"
|
204
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
205
|
+
@validator.validate(@dummy)
|
206
|
+
end
|
124
207
|
|
125
|
-
|
126
|
-
|
127
|
-
|
208
|
+
should "not set an error message" do
|
209
|
+
assert @dummy.errors[:avatar_content_type].blank?
|
210
|
+
end
|
128
211
|
end
|
129
|
-
end
|
130
212
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
213
|
+
context "as an regexp" do
|
214
|
+
setup do
|
215
|
+
build_validator :not => /^text\/.*/
|
216
|
+
@dummy.stubs(:avatar_content_type => "image/jpg")
|
217
|
+
@validator.validate(@dummy)
|
218
|
+
end
|
219
|
+
|
220
|
+
should "not set an error message" do
|
221
|
+
assert @dummy.errors[:avatar_content_type].blank?
|
222
|
+
end
|
136
223
|
end
|
137
224
|
|
138
|
-
|
139
|
-
|
140
|
-
|
225
|
+
context "as a list" do
|
226
|
+
setup do
|
227
|
+
build_validator :not => ["image/png", "image/jpg", "image/jpeg"]
|
228
|
+
@dummy.stubs(:avatar_content_type => "image/gif")
|
229
|
+
@validator.validate(@dummy)
|
230
|
+
end
|
231
|
+
|
232
|
+
should "not set an error message" do
|
233
|
+
assert @dummy.errors[:avatar_content_type].blank?
|
234
|
+
end
|
141
235
|
end
|
142
236
|
end
|
143
237
|
|
144
|
-
context "with
|
145
|
-
context "
|
238
|
+
context "with a disallowed type" do
|
239
|
+
context "as a string" do
|
146
240
|
setup do
|
147
|
-
build_validator :
|
148
|
-
@dummy.stubs(:avatar_content_type => "image/
|
241
|
+
build_validator :not => "image/png"
|
242
|
+
@dummy.stubs(:avatar_content_type => "image/png")
|
149
243
|
@validator.validate(@dummy)
|
150
244
|
end
|
151
245
|
|
152
|
-
should "set a correct error message" do
|
153
|
-
|
246
|
+
should "set a correct default error message" do
|
247
|
+
assert @dummy.errors[:avatar_content_type].present?
|
248
|
+
assert_includes @dummy.errors[:avatar_content_type], "is invalid"
|
154
249
|
end
|
155
250
|
end
|
156
251
|
|
157
|
-
context "
|
252
|
+
context "as a regexp" do
|
158
253
|
setup do
|
159
|
-
build_validator :
|
160
|
-
@dummy.stubs(:avatar_content_type => "
|
254
|
+
build_validator :not => /^text\/.*/
|
255
|
+
@dummy.stubs(:avatar_content_type => "text/plain")
|
161
256
|
@validator.validate(@dummy)
|
162
257
|
end
|
163
258
|
|
164
|
-
should "set a correct error message" do
|
165
|
-
|
259
|
+
should "set a correct default error message" do
|
260
|
+
assert @dummy.errors[:avatar_content_type].present?
|
261
|
+
assert_includes @dummy.errors[:avatar_content_type], "is invalid"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "with :message option" do
|
266
|
+
context "without interpolation" do
|
267
|
+
setup do
|
268
|
+
build_validator :not => "image/png", :message => "should not be a PNG image"
|
269
|
+
@dummy.stubs(:avatar_content_type => "image/png")
|
270
|
+
@validator.validate(@dummy)
|
271
|
+
end
|
272
|
+
|
273
|
+
should "set a correct error message" do
|
274
|
+
assert_includes @dummy.errors[:avatar_content_type], "should not be a PNG image"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context "with interpolation" do
|
279
|
+
setup do
|
280
|
+
build_validator :not => "image/png", :message => "should not have content type %{types}"
|
281
|
+
@dummy.stubs(:avatar_content_type => "image/png")
|
282
|
+
@validator.validate(@dummy)
|
283
|
+
end
|
284
|
+
|
285
|
+
should "set a correct error message" do
|
286
|
+
assert_includes @dummy.errors[:avatar_content_type], "should not have content type image/png"
|
287
|
+
end
|
166
288
|
end
|
167
289
|
end
|
168
290
|
end
|
@@ -185,8 +307,12 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
|
|
185
307
|
end
|
186
308
|
end
|
187
309
|
|
188
|
-
should "not raise
|
310
|
+
should "not raise argument error if :content_type was given" do
|
189
311
|
build_validator :content_type => "image/jpg"
|
190
312
|
end
|
313
|
+
|
314
|
+
should "not raise argument error if :not was given" do
|
315
|
+
build_validator :not => "image/jpg"
|
316
|
+
end
|
191
317
|
end
|
192
318
|
end
|
@@ -20,6 +20,11 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
|
|
20
20
|
assert @dummy.errors[:avatar_file_size].blank?,
|
21
21
|
"Expect an error message on :avatar_file_size, got none."
|
22
22
|
end
|
23
|
+
|
24
|
+
should "not add error to the base dummy object" do
|
25
|
+
assert @dummy.errors[:avatar].blank?,
|
26
|
+
"Error added to base attribute"
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
@@ -35,6 +40,11 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
|
|
35
40
|
"Unexpected error message on :avatar_file_size"
|
36
41
|
end
|
37
42
|
|
43
|
+
should "add error to the base dummy object" do
|
44
|
+
assert @dummy.errors[:avatar].present?,
|
45
|
+
"Error not added to base attribute"
|
46
|
+
end
|
47
|
+
|
38
48
|
if options[:message]
|
39
49
|
should "return a correct error message" do
|
40
50
|
assert_includes @dummy.errors[:avatar_file_size], options[:message]
|
data/test/validators_test.rb
CHANGED
@@ -7,7 +7,7 @@ class ValidatorsTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
context "using the helper" do
|
9
9
|
setup do
|
10
|
-
Dummy.validates_attachment :avatar, :presence => true, :content_type => { :content_type => "image/
|
10
|
+
Dummy.validates_attachment :avatar, :presence => true, :content_type => { :content_type => "image/jpeg" }, :size => { :in => 0..10.kilobytes }
|
11
11
|
end
|
12
12
|
|
13
13
|
should "add the attachment_presence validator to the class" do
|
@@ -21,5 +21,12 @@ class ValidatorsTest < Test::Unit::TestCase
|
|
21
21
|
should "add the attachment_size validator to the class" do
|
22
22
|
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
|
23
23
|
end
|
24
|
+
|
25
|
+
should 'prevent you from attaching a file that violates that validation' do
|
26
|
+
Dummy.class_eval{ validate(:name) { raise "DO NOT RUN THIS" } }
|
27
|
+
dummy = Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
28
|
+
assert_equal [:avatar_content_type, :avatar, :avatar_file_size], dummy.errors.keys
|
29
|
+
assert_raise(RuntimeError){ dummy.valid? }
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|