mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure that tests will reset belongs_to_requierd_by_default config
This commit is contained in:
parent
835bf75125
commit
6ff8518868
1 changed files with 28 additions and 24 deletions
|
@ -23,6 +23,7 @@ class RequiredAssociationsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
test "belongs_to associations can be optional by default" do
|
||||
begin
|
||||
original_value = ActiveRecord::Base.belongs_to_required_by_default
|
||||
ActiveRecord::Base.belongs_to_required_by_default = false
|
||||
|
||||
|
@ -33,9 +34,10 @@ class RequiredAssociationsTest < ActiveRecord::TestCase
|
|||
|
||||
assert model.new.save
|
||||
assert model.new(parent: Parent.new).save
|
||||
|
||||
ensure
|
||||
ActiveRecord::Base.belongs_to_required_by_default = original_value
|
||||
end
|
||||
end
|
||||
|
||||
test "required belongs_to associations have presence validated" do
|
||||
model = subclass_of(Child) do
|
||||
|
@ -52,6 +54,7 @@ class RequiredAssociationsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
test "belongs_to associations can be required by default" do
|
||||
begin
|
||||
original_value = ActiveRecord::Base.belongs_to_required_by_default
|
||||
ActiveRecord::Base.belongs_to_required_by_default = true
|
||||
|
||||
|
@ -66,9 +69,10 @@ class RequiredAssociationsTest < ActiveRecord::TestCase
|
|||
|
||||
record.parent = Parent.new
|
||||
assert record.save
|
||||
|
||||
ensure
|
||||
ActiveRecord::Base.belongs_to_required_by_default = original_value
|
||||
end
|
||||
end
|
||||
|
||||
test "has_one associations are not required by default" do
|
||||
model = subclass_of(Parent) do
|
||||
|
|
Loading…
Reference in a new issue