thoughtbot-paperclip 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paperclip.rb +2 -2
- data/lib/paperclip/attachment.rb +5 -3
- data/test/attachment_test.rb +11 -0
- data/test/paperclip_test.rb +15 -0
- metadata +1 -1
data/lib/paperclip.rb
CHANGED
@@ -43,7 +43,7 @@ end
|
|
43
43
|
# documentation for Paperclip::ClassMethods for more useful information.
|
44
44
|
module Paperclip
|
45
45
|
|
46
|
-
VERSION = "2.2.
|
46
|
+
VERSION = "2.2.2"
|
47
47
|
|
48
48
|
class << self
|
49
49
|
# Provides configurability to Paperclip. There are a number of options available, such as:
|
@@ -255,7 +255,7 @@ module Paperclip
|
|
255
255
|
valid_types = [options[:content_type]].flatten
|
256
256
|
|
257
257
|
unless attachment.original_filename.blank?
|
258
|
-
unless
|
258
|
+
unless valid_types.blank?
|
259
259
|
content_type = attachment.instance_read(:content_type)
|
260
260
|
unless valid_types.any?{|t| t === content_type }
|
261
261
|
options[:message] || "is not one of the allowed file types."
|
data/lib/paperclip/attachment.rb
CHANGED
@@ -326,11 +326,13 @@ module Paperclip
|
|
326
326
|
log("Post-processing #{name}")
|
327
327
|
@styles.each do |name, args|
|
328
328
|
begin
|
329
|
-
|
330
|
-
args[:processors].
|
331
|
-
|
329
|
+
raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
|
330
|
+
@queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
|
331
|
+
log("Processing #{name} #{file} in the #{processor} processor.")
|
332
|
+
Paperclip.processor(processor).make(file, args)
|
332
333
|
end
|
333
334
|
rescue PaperclipError => e
|
335
|
+
log("An error was received while processing: #{e.inspect}")
|
334
336
|
(@errors[:processing] ||= []) << e.message if @whiny
|
335
337
|
end
|
336
338
|
end
|
data/test/attachment_test.rb
CHANGED
@@ -210,6 +210,17 @@ class AttachmentTest < Test::Unit::TestCase
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
|
+
context "An attachment with no processors defined" do
|
214
|
+
setup do
|
215
|
+
rebuild_model :processors => [], :styles => {:something => 1}
|
216
|
+
@dummy = Dummy.new
|
217
|
+
@file = StringIO.new("...")
|
218
|
+
end
|
219
|
+
should "raise when assigned to" do
|
220
|
+
assert_raises(RuntimeError){ @dummy.avatar = @file }
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
213
224
|
context "Assigning an attachment with post_process hooks" do
|
214
225
|
setup do
|
215
226
|
rebuild_model :styles => { :something => "100x100#" }
|
data/test/paperclip_test.rb
CHANGED
@@ -177,6 +177,21 @@ class PaperclipTest < Test::Unit::TestCase
|
|
177
177
|
Dummy.send(:"validates_attachment_#{validation}", :avatar, options)
|
178
178
|
@dummy = Dummy.new
|
179
179
|
end
|
180
|
+
context "and assigning nil" do
|
181
|
+
setup do
|
182
|
+
@dummy.avatar = nil
|
183
|
+
@dummy.valid?
|
184
|
+
end
|
185
|
+
if validation == :presence
|
186
|
+
should "have an error on the attachment" do
|
187
|
+
assert @dummy.errors.on(:avatar)
|
188
|
+
end
|
189
|
+
else
|
190
|
+
should "not have an error on the attachment" do
|
191
|
+
assert_nil @dummy.errors.on(:avatar)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
180
195
|
context "and assigned a valid file" do
|
181
196
|
setup do
|
182
197
|
@dummy.avatar = valid_file
|