Permalink
Browse files

Fix how processor's error messages are added to the instance.

  • Loading branch information...
1 parent 1f63051 commit 8a5601fbfb878729d9ac92223e282491359a8655 thedarkone committed Jan 18, 2009
Showing with 18 additions and 1 deletion.
  1. +2 −1 lib/paperclip/attachment.rb
  2. +16 −0 test/attachment_test.rb
View
3 lib/paperclip/attachment.rb
@@ -407,7 +407,8 @@ def all_styles
def flush_errors #:nodoc:
@errors.each do |error, message|
- instance.errors.add(name, message) if message
+ # messages from processors are arrays, so convert everything to an array
+ Array(message).each {|err_message| instance.errors.add(name, err_message) }
end
end
View
16 test/attachment_test.rb
@@ -186,6 +186,22 @@ def thumb; "-thumb"; end
end
end
end
+
+ context "An attachment with erroring processor" do
+ setup do
+ rebuild_model :processor => [:thumbnail], :styles => { :small => '' }, :whiny_thumbnails => true
+ @dummy = Dummy.new
+ Paperclip::Thumbnail.expects(:make).raises(Paperclip::PaperclipError, "cannot be processed.")
+ @file = StringIO.new("...")
+ @file.stubs(:to_tempfile).returns(@file)
+ @dummy.avatar = @file
+ end
+
+ should "correctly forward processing error message to the instance" do
+ @dummy.valid?
+ assert_contains @dummy.errors.full_messages, "Avatar cannot be processed."
+ end
+ end
context "An attachment with multiple processors" do
setup do

0 comments on commit 8a5601f

Please sign in to comment.