Permalink
Browse files

Fixed a bug where errors in processing would create further errors in…

… attachment saving. Will also raise if there are no processors defined for a style.
  • Loading branch information...
1 parent c2c832d commit 04a9a83161544437a12175477e37e681fcbc4dd0 @jyurek jyurek committed Dec 30, 2008
Showing with 16 additions and 3 deletions.
  1. +5 −3 lib/paperclip/attachment.rb
  2. +11 −0 test/attachment_test.rb
@@ -326,11 +326,13 @@ def post_process #:nodoc:
log("Post-processing #{name}")
@styles.each do |name, args|
begin
- @queued_for_write[name] = @queued_for_write[:original]
- args[:processors].each do |processor|
- @queued_for_write[name] = Paperclip.processor(processor).make(@queued_for_write[name], args)
+ raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
+ @queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
+ log("Processing #{name} #{file} in the #{processor} processor.")
+ Paperclip.processor(processor).make(file, args)
end
rescue PaperclipError => e
+ log("An error was received while processing: #{e.inspect}")
(@errors[:processing] ||= []) << e.message if @whiny
end
end
View
@@ -210,6 +210,17 @@ class Paperclip::Test < Paperclip::Processor; end
end
end
+ context "An attachment with no processors defined" do
+ setup do
+ rebuild_model :processors => [], :styles => {:something => 1}
+ @dummy = Dummy.new
+ @file = StringIO.new("...")
+ end
+ should "raise when assigned to" do
+ assert_raises(RuntimeError){ @dummy.avatar = @file }
+ end
+ end
+
context "Assigning an attachment with post_process hooks" do
setup do
rebuild_model :styles => { :something => "100x100#" }

0 comments on commit 04a9a83

Please sign in to comment.