Commit 1544a7b2 by Jon Yurek

Don't process if the attachment isn't valid.

parent 3f4180ef
...@@ -105,7 +105,7 @@ module Paperclip ...@@ -105,7 +105,7 @@ module Paperclip
@dirty = true @dirty = true
post_process(*only_process) if post_processing post_process(*only_process) if post_processing && valid_assignment?
# Reset the file size if the original file was reprocessed. # Reset the file size if the original file was reprocessed.
instance_write(:file_size, @queued_for_write[:original].size) instance_write(:file_size, @queued_for_write[:original].size)
...@@ -369,8 +369,14 @@ module Paperclip ...@@ -369,8 +369,14 @@ module Paperclip
Paperclip.log(message) Paperclip.log(message)
end end
def valid_assignment? file #:nodoc: def valid_assignment? #:nodoc:
file.nil? || (file.respond_to?(:original_filename) && file.respond_to?(:content_type)) if instance.valid?
true
else
instance.errors.none? do |attr, message|
attr.to_s.start_with?(@name.to_s)
end
end
end end
def initialize_storage #:nodoc: def initialize_storage #:nodoc:
......
# encoding: utf-8
require './test/helper'
require 'paperclip/attachment'
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)
attachment.assign(file)
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
attachment.assign(file)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment