diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 367f87031c..231aad990d 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1144,7 +1144,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_restrict - # ActiveRecord::Base.dependent_restrict_raises = true, by default + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true firm = RestrictedFirm.create!(:name => 'restrict') firm.companies.create(:name => 'child') @@ -1153,13 +1154,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy } assert RestrictedFirm.exists?(:name => 'restrict') assert firm.companies.exists?(:name => 'child') + ensure + ActiveRecord::Base.dependent_restrict_raises = option_before end def test_restrict_when_dependent_restrict_raises_config_set_to_false - # ActiveRecord::Base.dependent_restrict_raises = true, by default - + option_before = ActiveRecord::Base.dependent_restrict_raises ActiveRecord::Base.dependent_restrict_raises = false - # add an error on the model instead of raising ActiveRecord::DeleteRestrictionError firm = RestrictedFirm.create!(:name => 'restrict') firm.companies.create(:name => 'child') @@ -1174,7 +1175,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert RestrictedFirm.exists?(:name => 'restrict') assert firm.companies.exists?(:name => 'child') ensure - ActiveRecord::Base.dependent_restrict_raises = true + ActiveRecord::Base.dependent_restrict_raises = option_before end def test_included_in_collection @@ -1680,9 +1681,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_building_has_many_association_with_restrict_dependency + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true + klass = Class.new(ActiveRecord::Base) - - assert_deprecated { klass.has_many :companies, :dependent => :restrict } + + assert_deprecated { klass.has_many :companies, :dependent => :restrict } assert_not_deprecated { klass.has_many :companies } + ensure + ActiveRecord::Base.dependent_restrict_raises = option_before end end diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 7c6736fb95..37be6a279d 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -157,7 +157,8 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end def test_dependence_with_restrict - # ActiveRecord::Base.dependent_restrict_raises = true, by default + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true firm = RestrictedFirm.create!(:name => 'restrict') firm.create_account(:credit_limit => 10) @@ -167,13 +168,13 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy } 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 - # ActiveRecord::Base.dependent_restrict_raises = true, by default - + option_before = ActiveRecord::Base.dependent_restrict_raises ActiveRecord::Base.dependent_restrict_raises = false - # adds an error on the model instead of raising ActiveRecord::DeleteRestrictionError firm = RestrictedFirm.create!(:name => 'restrict') firm.create_account(:credit_limit => 10) @@ -187,7 +188,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert RestrictedFirm.exists?(:name => 'restrict') assert firm.account.present? ensure - ActiveRecord::Base.dependent_restrict_raises = true + ActiveRecord::Base.dependent_restrict_raises = option_before end def test_successful_build_association @@ -484,9 +485,14 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end def test_building_has_one_association_with_dependent_restrict + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true + klass = Class.new(ActiveRecord::Base) - + assert_deprecated { klass.has_one :account, :dependent => :restrict } assert_not_deprecated { klass.has_one :account } + ensure + ActiveRecord::Base.dependent_restrict_raises = option_before end end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index b4598ab32a..359cabd016 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -22,6 +22,9 @@ ActiveSupport::Deprecation.debug = true # Enable Identity Map only when ENV['IM'] is set to "true" ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "true") +# Avoid deprecation warning setting dependent_restric_raises to false. The default is true +ActiveRecord::Base.dependent_restrict_raises = false + # Connect to the database ARTest.connect