Skip to content

Commit

Permalink
Fix how processor's error messages are added to the instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkone committed Jan 18, 2009
1 parent 1f63051 commit 8a5601f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/paperclip/attachment.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def all_styles


def flush_errors #:nodoc: def flush_errors #:nodoc:
@errors.each do |error, message| @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
end end


Expand Down
16 changes: 16 additions & 0 deletions test/attachment_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ def thumb; "-thumb"; end
end end
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 context "An attachment with multiple processors" do
setup do setup do
Expand Down

0 comments on commit 8a5601f

Please sign in to comment.