Skip to content

Commit

Permalink
Assigning nil to an attachment still deals with validations correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Dec 30, 2008
1 parent 5a43207 commit c2c832d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paperclip.rb
Expand Up @@ -255,7 +255,7 @@ def validates_attachment_content_type name, options = {}
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."
Expand Down
15 changes: 15 additions & 0 deletions test/paperclip_test.rb
Expand Up @@ -177,6 +177,21 @@ def self.should_validate validation, options, valid_file, invalid_file
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
Expand Down

0 comments on commit c2c832d

Please sign in to comment.