Added test for obj.errors.as_json

This commit is contained in:
Lawrence Pit 2011-09-09 18:34:13 +10:00
parent f5a944f662
commit 8817796167
1 changed files with 11 additions and 0 deletions

View File

@ -102,4 +102,15 @@ class ErrorsTest < ActiveModel::TestCase
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