mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecation warnings from tests
This commit is contained in:
parent
62c955db79
commit
f944d528c4
3 changed files with 28 additions and 13 deletions
|
@ -1144,7 +1144,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_restrict
|
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 = RestrictedFirm.create!(:name => 'restrict')
|
||||||
firm.companies.create(:name => 'child')
|
firm.companies.create(:name => 'child')
|
||||||
|
@ -1153,13 +1154,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
|
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
|
||||||
assert RestrictedFirm.exists?(:name => 'restrict')
|
assert RestrictedFirm.exists?(:name => 'restrict')
|
||||||
assert firm.companies.exists?(:name => 'child')
|
assert firm.companies.exists?(:name => 'child')
|
||||||
|
ensure
|
||||||
|
ActiveRecord::Base.dependent_restrict_raises = option_before
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_restrict_when_dependent_restrict_raises_config_set_to_false
|
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
|
ActiveRecord::Base.dependent_restrict_raises = false
|
||||||
# add an error on the model instead of raising ActiveRecord::DeleteRestrictionError
|
|
||||||
|
|
||||||
firm = RestrictedFirm.create!(:name => 'restrict')
|
firm = RestrictedFirm.create!(:name => 'restrict')
|
||||||
firm.companies.create(:name => 'child')
|
firm.companies.create(:name => 'child')
|
||||||
|
@ -1174,7 +1175,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
assert RestrictedFirm.exists?(:name => 'restrict')
|
assert RestrictedFirm.exists?(:name => 'restrict')
|
||||||
assert firm.companies.exists?(:name => 'child')
|
assert firm.companies.exists?(:name => 'child')
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.dependent_restrict_raises = true
|
ActiveRecord::Base.dependent_restrict_raises = option_before
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_included_in_collection
|
def test_included_in_collection
|
||||||
|
@ -1680,9 +1681,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_building_has_many_association_with_restrict_dependency
|
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)
|
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 }
|
assert_not_deprecated { klass.has_many :companies }
|
||||||
|
ensure
|
||||||
|
ActiveRecord::Base.dependent_restrict_raises = option_before
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -157,7 +157,8 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dependence_with_restrict
|
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 = RestrictedFirm.create!(:name => 'restrict')
|
||||||
firm.create_account(:credit_limit => 10)
|
firm.create_account(:credit_limit => 10)
|
||||||
|
@ -167,13 +168,13 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
||||||
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
|
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
|
||||||
assert RestrictedFirm.exists?(:name => 'restrict')
|
assert RestrictedFirm.exists?(:name => 'restrict')
|
||||||
assert firm.account.present?
|
assert firm.account.present?
|
||||||
|
ensure
|
||||||
|
ActiveRecord::Base.dependent_restrict_raises = option_before
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dependence_with_restrict_with_dependent_restrict_raises_config_set_to_false
|
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
|
ActiveRecord::Base.dependent_restrict_raises = false
|
||||||
# adds an error on the model instead of raising ActiveRecord::DeleteRestrictionError
|
|
||||||
|
|
||||||
firm = RestrictedFirm.create!(:name => 'restrict')
|
firm = RestrictedFirm.create!(:name => 'restrict')
|
||||||
firm.create_account(:credit_limit => 10)
|
firm.create_account(:credit_limit => 10)
|
||||||
|
@ -187,7 +188,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
||||||
assert RestrictedFirm.exists?(:name => 'restrict')
|
assert RestrictedFirm.exists?(:name => 'restrict')
|
||||||
assert firm.account.present?
|
assert firm.account.present?
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.dependent_restrict_raises = true
|
ActiveRecord::Base.dependent_restrict_raises = option_before
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_successful_build_association
|
def test_successful_build_association
|
||||||
|
@ -484,9 +485,14 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_building_has_one_association_with_dependent_restrict
|
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)
|
klass = Class.new(ActiveRecord::Base)
|
||||||
|
|
||||||
assert_deprecated { klass.has_one :account, :dependent => :restrict }
|
assert_deprecated { klass.has_one :account, :dependent => :restrict }
|
||||||
assert_not_deprecated { klass.has_one :account }
|
assert_not_deprecated { klass.has_one :account }
|
||||||
|
ensure
|
||||||
|
ActiveRecord::Base.dependent_restrict_raises = option_before
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,9 @@ ActiveSupport::Deprecation.debug = true
|
||||||
# Enable Identity Map only when ENV['IM'] is set to "true"
|
# Enable Identity Map only when ENV['IM'] is set to "true"
|
||||||
ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "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
|
# Connect to the database
|
||||||
ARTest.connect
|
ARTest.connect
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue