Commit c2c832d9 by Jon Yurek

Assigning nil to an attachment still deals with validations correctly

parent 5a432071
......@@ -255,7 +255,7 @@ module Paperclip
valid_types = [options[:content_type]].flatten
unless attachment.original_filename.blank?
unless options[:content_type].blank?
unless valid_types.blank?
content_type = attachment.instance_read(:content_type)
unless valid_types.any?{|t| t === content_type }
options[:message] || "is not one of the allowed file types."
......
......@@ -177,6 +177,21 @@ class PaperclipTest < Test::Unit::TestCase
Dummy.send(:"validates_attachment_#{validation}", :avatar, options)
@dummy = Dummy.new
end
context "and assigning nil" do
setup do
@dummy.avatar = nil
@dummy.valid?
end
if validation == :presence
should "have an error on the attachment" do
assert @dummy.errors.on(:avatar)
end
else
should "not have an error on the attachment" do
assert_nil @dummy.errors.on(:avatar)
end
end
end
context "and assigned a valid file" do
setup do
@dummy.avatar = valid_file
......
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