test/attachment_processing_test.rb in paperclip-3.4.2 vs test/attachment_processing_test.rb in paperclip-3.5.0

- old
+ new

@@ -5,25 +5,79 @@ class AttachmentProcessingTest < Test::Unit::TestCase def setup rebuild_model end - should 'process attachments given a valid assignment' do - file = File.new(fixture_file("5k.png")) - Dummy.validates_attachment_content_type :avatar, :content_type => "image/png" - instance = Dummy.new - attachment = instance.avatar - attachment.expects(:post_process) + context 'using validates_attachment_content_type' do + should 'process attachments given a valid assignment' do + file = File.new(fixture_file("5k.png")) + Dummy.validates_attachment_content_type :avatar, :content_type => "image/png" + instance = Dummy.new + attachment = instance.avatar + attachment.expects(:post_process_styles) - attachment.assign(file) + attachment.assign(file) + end + + should 'not process attachments given an invalid assignment with :not' do + file = File.new(fixture_file("5k.png")) + Dummy.validates_attachment_content_type :avatar, :not => "image/png" + instance = Dummy.new + attachment = instance.avatar + attachment.expects(:post_process_styles).never + + attachment.assign(file) + end + + should 'not process attachments given an invalid assignment with :content_type' do + file = File.new(fixture_file("5k.png")) + Dummy.validates_attachment_content_type :avatar, :content_type => "image/tiff" + instance = Dummy.new + attachment = instance.avatar + attachment.expects(:post_process_styles).never + + attachment.assign(file) + end + + should 'when validation :if clause returns false, allow what would be an invalid assignment' do + invalid_assignment = File.new(fixture_file("5k.png")) + Dummy.validates_attachment_content_type :avatar, :content_type => "image/tiff", :if => lambda{false} + instance = Dummy.new + attachment = instance.avatar + attachment.expects(:post_process_styles) + + attachment.assign(invalid_assignment) + end end - should 'not process attachments if the assignment does not pass validation' do - file = File.new(fixture_file("5k.png")) - Dummy.validates_attachment_content_type :avatar, :content_type => "image/tiff" - instance = Dummy.new - attachment = instance.avatar - attachment.expects(:post_process).never + context 'using validates_attachment' do + should 'process attachments given a valid assignment' do + file = File.new(fixture_file("5k.png")) + Dummy.validates_attachment :avatar, :content_type => {:content_type => "image/png"} + instance = Dummy.new + attachment = instance.avatar + attachment.expects(:post_process_styles) - attachment.assign(file) + attachment.assign(file) + end + + should 'not process attachments given an invalid assignment with :not' do + file = File.new(fixture_file("5k.png")) + Dummy.validates_attachment :avatar, :content_type => {:not => "image/png"} + instance = Dummy.new + attachment = instance.avatar + attachment.expects(:post_process_styles).never + + attachment.assign(file) + end + + should 'not process attachments given an invalid assignment with :content_type' do + file = File.new(fixture_file("5k.png")) + Dummy.validates_attachment :avatar, :content_type => {:content_type => "image/tiff"} + instance = Dummy.new + attachment = instance.avatar + attachment.expects(:post_process_styles).never + + attachment.assign(file) + end end end