Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Fixes validates_attachment_presence just flat out not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Oct 20, 2011
1 parent 93faccf commit 61a0536
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/paperclip.rb
Expand Up @@ -388,7 +388,9 @@ def validates_attachment_thumbnails name, options = {}
def validates_attachment_presence name, options = {}
message = options[:message] || :empty
validates_each :"#{name}_file_name" do |record, attr, value|
record.errors.add(name, message) if attr.blank?
if_clause_passed = options[:if].nil? || (options[:if].call(record) != false)
unless_clause_passed = options[:unless].nil? || (!!options[:unless].call(record) == false)
record.errors.add(name, message) if if_clause_passed && unless_clause_passed && value.blank?
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/paperclip_test.rb
Expand Up @@ -238,7 +238,7 @@ def self.should_validate validation, options, valid_file, invalid_file
@dummy.avatar = valid_file
@dummy.valid?
end
should "not have an error when assigned a valid file" do
should "not have an error" do
assert_equal 0, @dummy.errors.size, @dummy.errors.full_messages.join(", ")
end
end
Expand All @@ -247,7 +247,7 @@ def self.should_validate validation, options, valid_file, invalid_file
@dummy.avatar = invalid_file
@dummy.valid?
end
should "have an error when assigned a valid file" do
should "have an error" do
assert @dummy.errors.size > 0
end
end
Expand Down

0 comments on commit 61a0536

Please sign in to comment.