From 37283a6aaec244cb484e24b3e9ff165e89eadd64 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 20 Mar 2009 17:36:22 +0000 Subject: Deprecate Error#on(attribute) in favour of Errors#[attribute] --- .../associations/has_one_associations_test.rb | 4 +-- .../test/cases/autosave_association_test.rb | 32 +++++++++++----------- .../validations/association_validation_test.rb | 6 ++-- .../test/cases/validations/i18n_validation_test.rb | 4 +-- activerecord/test/cases/validations_test.rb | 4 +-- 5 files changed, 25 insertions(+), 25 deletions(-) (limited to 'activerecord') diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 1ddb3f49bf..7140de77ea 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -183,7 +183,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase account = firm.build_account assert !account.save - assert_equal "can't be empty", account.errors.on("credit_limit") + assert_equal ["can't be empty"], account.errors["credit_limit"] end def test_build_association_twice_without_saving_affects_nothing @@ -219,7 +219,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert_equal account, firm.account assert !account.save assert_equal account, firm.account - assert_equal "can't be empty", account.errors.on("credit_limit") + assert_equal ["can't be empty"], account.errors["credit_limit"] end def test_create diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 4018036a9f..2712b2a05c 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -47,7 +47,7 @@ class TestDefaultAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCas assert !firm.account.valid? assert !firm.valid? assert !firm.save - assert_equal "is invalid", firm.errors.on("account") + assert_equal ["is invalid"], firm.errors["account"] end def test_save_succeeds_for_invalid_has_one_with_validate_false @@ -133,7 +133,7 @@ class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::Test assert !log.developer.valid? assert !log.valid? assert !log.save - assert_equal "is invalid", log.errors.on("developer") + assert_equal ["is invalid"], log.errors["developer"] end def test_save_succeeds_for_invalid_belongs_to_with_validate_false @@ -623,16 +623,16 @@ class TestAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCase def test_should_automatically_validate_the_associated_model @pirate.ship.name = '' - assert !@pirate.valid? - assert !@pirate.errors.on(:ship_name).blank? + assert @pirate.invalid? + assert @pirate.errors[:ship_name].any? end def test_should_merge_errors_on_the_associated_models_onto_the_parent_even_if_it_is_not_valid @pirate.ship.name = nil @pirate.catchphrase = nil - assert !@pirate.valid? - assert !@pirate.errors.on(:ship_name).blank? - assert !@pirate.errors.on(:catchphrase).blank? + assert @pirate.invalid? + assert @pirate.errors[:ship_name].any? + assert @pirate.errors[:catchphrase].any? end def test_should_still_allow_to_bypass_validations_on_the_associated_model @@ -720,9 +720,9 @@ class TestAutosaveAssociationOnABelongsToAssociation < ActiveRecord::TestCase def test_should_merge_errors_on_the_associated_model_onto_the_parent_even_if_it_is_not_valid @ship.name = nil @ship.pirate.catchphrase = nil - assert !@ship.valid? - assert !@ship.errors.on(:name).blank? - assert !@ship.errors.on(:pirate_catchphrase).blank? + assert @ship.invalid? + assert @ship.errors[:name].any? + assert @ship.errors[:pirate_catchphrase].any? end def test_should_still_allow_to_bypass_validations_on_the_associated_model @@ -784,16 +784,16 @@ module AutosaveAssociationOnACollectionAssociationTests @pirate.send(@association_name).each { |child| child.name = '' } assert !@pirate.valid? - assert_equal "can't be blank", @pirate.errors.on("#{@association_name}_name") - assert @pirate.errors.on(@association_name).blank? + assert_equal ["can't be blank"], @pirate.errors["#{@association_name}_name"] + assert @pirate.errors[@association_name].empty? end def test_should_not_use_default_invalid_error_on_associated_models @pirate.send(@association_name).build(:name => '') assert !@pirate.valid? - assert_equal "can't be blank", @pirate.errors.on("#{@association_name}_name") - assert @pirate.errors.on(@association_name).blank? + assert_equal ["can't be blank"], @pirate.errors["#{@association_name}_name"] + assert @pirate.errors[@association_name].empty? end def test_should_merge_errors_on_the_associated_models_onto_the_parent_even_if_it_is_not_valid @@ -801,8 +801,8 @@ module AutosaveAssociationOnACollectionAssociationTests @pirate.catchphrase = nil assert !@pirate.valid? - assert_equal "can't be blank", @pirate.errors.on("#{@association_name}_name") - assert !@pirate.errors.on(:catchphrase).blank? + assert_equal ["can't be blank"], @pirate.errors["#{@association_name}_name"] + assert @pirate.errors[:catchphrase].any? end def test_should_allow_to_bypass_validations_on_the_associated_models_on_update diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb index 9d9a5e65e4..b1203c12ed 100644 --- a/activerecord/test/cases/validations/association_validation_test.rb +++ b/activerecord/test/cases/validations/association_validation_test.rb @@ -14,7 +14,7 @@ class AssociationValidationTest < ActiveRecord::TestCase assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 } o = Owner.new('name' => 'nopets') assert !o.save - assert o.errors.on(:pets) + assert o.errors[:pets].any? pet = o.pets.build('name' => 'apet') assert o.valid? end @@ -25,14 +25,14 @@ class AssociationValidationTest < ActiveRecord::TestCase assert_nothing_raised { Owner.validates_size_of :pets, :within => 1..2 } o = Owner.new('name' => 'nopets') assert !o.save - assert o.errors.on(:pets) + assert o.errors[:pets].any? pet = o.pets.build('name' => 'apet') assert o.valid? 2.times { o.pets.build('name' => 'apet') } assert !o.save - assert o.errors.on(:pets) + assert o.errors[:pets].any? end end diff --git a/activerecord/test/cases/validations/i18n_validation_test.rb b/activerecord/test/cases/validations/i18n_validation_test.rb index 59730f17b4..c453672815 100644 --- a/activerecord/test/cases/validations/i18n_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_validation_test.rb @@ -76,7 +76,7 @@ class I18nValidationTest < ActiveRecord::TestCase Topic.validates_associated :replies replied_topic.valid? - assert_equal 'custom message', replied_topic.errors.on(:replies) + assert_equal ['custom message'], replied_topic.errors[:replies] end def test_validates_associated_finds_global_default_translation @@ -84,6 +84,6 @@ class I18nValidationTest < ActiveRecord::TestCase Topic.validates_associated :replies replied_topic.valid? - assert_equal 'global message', replied_topic.errors.on(:replies) + assert_equal ['global message'], replied_topic.errors[:replies] end end diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index b10b291872..ba2fb04d2f 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -28,7 +28,7 @@ class ValidationsTest < ActiveRecord::TestCase r.title = "Wrong Create" assert !r.valid? assert r.errors.invalid?("title"), "A reply with a bad title should mark that attribute as invalid" - assert_equal "is Wrong Create", r.errors.on(:title), "A reply with a bad content should contain an error" + assert_equal ["is Wrong Create"], r.errors[:title], "A reply with a bad content should contain an error" end def test_error_on_update @@ -41,7 +41,7 @@ class ValidationsTest < ActiveRecord::TestCase assert !r.save, "Second save should fail" assert r.errors.invalid?("title"), "A reply with a bad title should mark that attribute as invalid" - assert_equal "is Wrong Update", r.errors.on(:title), "A reply with a bad content should contain an error" + assert_equal ["is Wrong Update"], r.errors[:title], "A reply with a bad content should contain an error" end def test_invalid_record_exception -- cgit v1.2.3