aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-02-01 15:45:11 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-02-01 17:03:15 -0200
commita73662f3d8d9ce1a0c54bc0254024c5ecc7cb1a2 (patch)
tree70d8a1e9029a4ea54ec7be1bd52758ee579d9d17 /activerecord/test/cases/associations
parent403cce77f19bc6c2a3d8acaf547991078a540eaf (diff)
downloadrails-a73662f3d8d9ce1a0c54bc0254024c5ecc7cb1a2.tar.gz
rails-a73662f3d8d9ce1a0c54bc0254024c5ecc7cb1a2.tar.bz2
rails-a73662f3d8d9ce1a0c54bc0254024c5ecc7cb1a2.zip
Use human attribute name to show the dependent destroy message
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index c2548e33c5..331358bd61 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -184,13 +184,37 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
firm.destroy
assert !firm.errors.empty?
- assert_equal "Cannot delete record because a dependent account exists", firm.errors[:base].first
+ assert_equal "Cannot delete record because a dependent account exist", firm.errors[:base].first
assert RestrictedFirm.exists?(:name => 'restrict')
assert firm.account.present?
ensure
ActiveRecord::Base.dependent_restrict_raises = option_before
end
+ def test_dependence_with_restrict_with_dependent_restrict_raises_config_set_to_false_and_attribute_name
+ old_backend = I18n.backend
+ I18n.backend = I18n::Backend::Simple.new
+ I18n.backend.store_translations 'en', :activerecord => {:attributes => {:restricted_firm => {:account => "account model"}}}
+
+ option_before = ActiveRecord::Base.dependent_restrict_raises
+ ActiveRecord::Base.dependent_restrict_raises = false
+
+ firm = RestrictedFirm.create!(:name => 'restrict')
+ firm.create_account(:credit_limit => 10)
+
+ assert_not_nil firm.account
+
+ firm.destroy
+
+ assert !firm.errors.empty?
+ assert_equal "Cannot delete record because a dependent account model exist", firm.errors[:base].first
+ assert RestrictedFirm.exists?(:name => 'restrict')
+ assert firm.account.present?
+ ensure
+ ActiveRecord::Base.dependent_restrict_raises = option_before
+ I18n.backend = old_backend
+ end
+
def test_successful_build_association
firm = Firm.new("name" => "GlobalMegaCorp")
firm.save