diff options
Diffstat (limited to 'activemodel/test/cases/errors_test.rb')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 8ddedb160a..3bc0d58351 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -27,12 +27,27 @@ class ErrorsTest < ActiveModel::TestCase end end + def test_delete + errors = ActiveModel::Errors.new(self) + errors[:foo] = 'omg' + errors.delete(:foo) + assert_empty errors[:foo] + end + def test_include? errors = ActiveModel::Errors.new(self) errors[:foo] = 'omg' assert errors.include?(:foo), 'errors should include :foo' end + def test_dup + errors = ActiveModel::Errors.new(self) + errors[:foo] = 'bar' + errors_dup = errors.dup + errors_dup[:bar] = 'omg' + assert_not_same errors_dup.messages, errors.messages + end + def test_has_key? errors = ActiveModel::Errors.new(self) errors[:foo] = 'omg' @@ -136,10 +151,10 @@ class ErrorsTest < ActiveModel::TestCase assert_equal ["name can not be blank", "name can not be nil"], person.errors.to_a end - test 'to_hash should return an ordered hash' do + test 'to_hash should return a hash' do person = Person.new person.errors.add(:name, "can not be blank") - assert_instance_of ActiveSupport::OrderedHash, person.errors.to_hash + assert_instance_of ::Hash, person.errors.to_hash end test 'full_messages should return an array of error messages, with the attribute name included' do @@ -169,6 +184,16 @@ class ErrorsTest < ActiveModel::TestCase assert_equal ["is invalid"], hash[:email] end + test 'should return a JSON hash representation of the errors with full messages' 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(:full_messages => true) + assert_equal ["name can not be blank", "name can not be nil"], hash[:name] + assert_equal ["email is invalid"], hash[:email] + end + test "generate_message should work without i18n_scope" do person = Person.new assert !Person.respond_to?(:i18n_scope) |