Merge pull request #4006 from devton/validation_error_on_message_is_empty_part_2

Fixed bug when error message is an empty string.
This commit is contained in:
José Valim 2011-12-16 11:24:45 -08:00
commit 05316ba127
2 changed files with 8 additions and 1 deletions

View File

@ -176,8 +176,9 @@ module ActiveModel
end
# Returns true if no errors are found, false otherwise.
# If the error message is a string it can be empty.
def empty?
all? { |k, v| v && v.empty? }
all? { |k, v| v && v.empty? && !v.is_a?(String) }
end
alias_method :blank?, :empty?

View File

@ -16,6 +16,12 @@ class ValidatesTest < ActiveModel::TestCase
PersonWithValidator.reset_callbacks(:validate)
end
def test_validates_with_messages_empty
Person.validates :title, :presence => {:message => "" }
person = Person.new(:title => '')
assert !person.valid?, 'person should not be valid.'
end
def test_validates_with_built_in_validation
Person.validates :title, :numericality => true
person = Person.new