Skip to content

Commit

Permalink
Fixed bug when error message is an empty string.
Browse files Browse the repository at this point in the history
  • Loading branch information
devton committed Dec 16, 2011
1 parent f307f4d commit 66e747b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activemodel/lib/active_model/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
6 changes: 6 additions & 0 deletions activemodel/test/cases/validations/validates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 66e747b

Please sign in to comment.