Commit 61a05368 by Jon Yurek

Fixes validates_attachment_presence just flat out not working

parent 93faccfa
......@@ -388,7 +388,9 @@ module Paperclip
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
......
......@@ -238,7 +238,7 @@ class PaperclipTest < Test::Unit::TestCase
@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 @@ class PaperclipTest < Test::Unit::TestCase
@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
......
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