Skip to content
Browse files

Merge pull request #4006 from devton/validation_error_on_message_is_e…

…mpty_part_2

Fixed bug when error message is an empty string.
  • Loading branch information...
2 parents 5f6bcd7 + 66e747b commit 05316ba1278e7feb8ca16907738e10c2ad1a8076 @josevalim josevalim committed Dec 16, 2011
Showing with 8 additions and 1 deletion.
  1. +2 −1 activemodel/lib/active_model/errors.rb
  2. +6 −0 activemodel/test/cases/validations/validates_test.rb
View
3 activemodel/lib/active_model/errors.rb
@@ -176,8 +176,9 @@ def count
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
6 activemodel/test/cases/validations/validates_test.rb
@@ -16,6 +16,12 @@ def reset_callbacks
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

0 comments on commit 05316ba

Please sign in to comment.
Something went wrong with that request. Please try again.