Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes validates_attachment_presence just flat out not working

  • Loading branch information...
commit 61a05368ab5298171bc70209ef2c4f184643bfad 1 parent 93faccf
Jon Yurek jyurek authored
Showing with 5 additions and 3 deletions.
  1. +3 −1 lib/paperclip.rb
  2. +2 −2 test/paperclip_test.rb
4 lib/paperclip.rb
View
@@ -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
4 test/paperclip_test.rb
View
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.