aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/errors_test.rb
diff options
context:
space:
mode:
authorLawrence Pit <lawrence.pit@gmail.com>2011-09-09 18:34:13 +1000
committerLawrence Pit <lawrence.pit@gmail.com>2011-09-09 18:34:13 +1000
commit8817796167d6aba16e67b99ad4010500a797f2c4 (patch)
treecc1255506b4e74f2d9a6d4b5cbbc4027b1e9f0e8 /activemodel/test/cases/errors_test.rb
parentf5a944f662d3236f7bf3162d3b61850c61339b50 (diff)
downloadrails-8817796167d6aba16e67b99ad4010500a797f2c4.tar.gz
rails-8817796167d6aba16e67b99ad4010500a797f2c4.tar.bz2
rails-8817796167d6aba16e67b99ad4010500a797f2c4.zip
Added test for obj.errors.as_json
Diffstat (limited to 'activemodel/test/cases/errors_test.rb')
-rw-r--r--activemodel/test/cases/errors_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 51668a0689..4c76bb43a8 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -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
+