Skip to content

Commit

Permalink
Added test for obj.errors.as_json
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencepit committed Sep 9, 2011
1 parent f5a944f commit 8817796
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions activemodel/test/cases/errors_test.rb
Expand Up @@ -102,4 +102,15 @@ def test_has_key?
assert_equal "name can not be blank", person.errors.full_message(:name, "can not be blank")
end

test 'should return a JSON hash representation of the errors' do
person = Person.new
person.errors.add(:name, "can not be blank")
person.errors.add(:name, "can not be nil")
person.errors.add(:email, "is invalid")
hash = person.errors.as_json
assert_equal ["can not be blank", "can not be nil"], hash[:name]
assert_equal ["is invalid"], hash[:email]
end

end

0 comments on commit 8817796

Please sign in to comment.