aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb18
-rw-r--r--activerecord/test/cases/associations/required_test.rb50
2 files changed, 31 insertions, 37 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 515eb65d37..fe8bdd03ba 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -1007,16 +1007,14 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
end
def test_has_and_belongs_to_many_while_partial_writes_false
- begin
- original_partial_writes = ActiveRecord::Base.partial_writes
- ActiveRecord::Base.partial_writes = false
- developer = Developer.new(name: "Mehmet Emin İNAÇ")
- developer.projects << Project.new(name: "Bounty")
-
- assert developer.save
- ensure
- ActiveRecord::Base.partial_writes = original_partial_writes
- end
+ original_partial_writes = ActiveRecord::Base.partial_writes
+ ActiveRecord::Base.partial_writes = false
+ developer = Developer.new(name: "Mehmet Emin İNAÇ")
+ developer.projects << Project.new(name: "Bounty")
+
+ assert developer.save
+ ensure
+ ActiveRecord::Base.partial_writes = original_partial_writes
end
def test_has_and_belongs_to_many_with_belongs_to
diff --git a/activerecord/test/cases/associations/required_test.rb b/activerecord/test/cases/associations/required_test.rb
index 65a3bb5efe..c7a78e6bc4 100644
--- a/activerecord/test/cases/associations/required_test.rb
+++ b/activerecord/test/cases/associations/required_test.rb
@@ -25,20 +25,18 @@ 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
+ original_value = ActiveRecord::Base.belongs_to_required_by_default
+ ActiveRecord::Base.belongs_to_required_by_default = false
- model = subclass_of(Child) do
- belongs_to :parent, inverse_of: false,
- class_name: "RequiredAssociationsTest::Parent"
- end
-
- assert model.new.save
- assert model.new(parent: Parent.new).save
- ensure
- ActiveRecord::Base.belongs_to_required_by_default = original_value
+ model = subclass_of(Child) do
+ belongs_to :parent, inverse_of: false,
+ class_name: "RequiredAssociationsTest::Parent"
end
+
+ assert model.new.save
+ assert model.new(parent: Parent.new).save
+ ensure
+ ActiveRecord::Base.belongs_to_required_by_default = original_value
end
test "required belongs_to associations have presence validated" do
@@ -56,24 +54,22 @@ 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
+ original_value = ActiveRecord::Base.belongs_to_required_by_default
+ ActiveRecord::Base.belongs_to_required_by_default = true
- model = subclass_of(Child) do
- belongs_to :parent, inverse_of: false,
- class_name: "RequiredAssociationsTest::Parent"
- end
+ model = subclass_of(Child) do
+ belongs_to :parent, inverse_of: false,
+ class_name: "RequiredAssociationsTest::Parent"
+ end
- record = model.new
- assert_not record.save
- assert_equal ["Parent must exist"], record.errors.full_messages
+ record = model.new
+ assert_not record.save
+ assert_equal ["Parent must exist"], record.errors.full_messages
- record.parent = Parent.new
- assert record.save
- ensure
- ActiveRecord::Base.belongs_to_required_by_default = original_value
- end
+ record.parent = Parent.new
+ assert record.save
+ ensure
+ ActiveRecord::Base.belongs_to_required_by_default = original_value
end
test "has_one associations are not required by default" do