Skip to content

Commit 71d6e94

Browse files
committed
Split strict_loading with :n_plus_one_only tests
The current test handles a lot of different cases. Splitting it on the type of association makes the tests easier to understand.
1 parent b8448bc commit 71d6e94

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

activerecord/test/cases/strict_loading_test.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@ def test_strict_loading!
3939
assert developer.strict_loading_n_plus_one_only?
4040
end
4141

42-
def test_strict_loading_n_plus_one_only_mode
42+
def test_strict_loading_n_plus_one_only_mode_with_has_many
4343
developer = Developer.first
44-
ship = Ship.first
45-
ShipPart.create!(name: "Stern", ship: ship)
4644
firm = Firm.create!(name: "NASA")
47-
project = Project.create!(name: "Apollo", firm: firm)
45+
developer.projects << Project.create!(name: "Apollo", firm: firm)
4846

49-
ship.update_column(:developer_id, developer.id)
50-
developer.projects << project
5147
developer.reload
5248

5349
developer.strict_loading!(mode: :n_plus_one_only)
@@ -63,6 +59,18 @@ def test_strict_loading_n_plus_one_only_mode
6359
assert_raises ActiveRecord::StrictLoadingViolationError do
6460
developer.projects.last.firm
6561
end
62+
end
63+
64+
def test_strict_loading_n_plus_one_only_mode_with_belongs_to
65+
developer = Developer.first
66+
ship = Ship.first
67+
ShipPart.create!(name: "Stern", ship: ship)
68+
69+
ship.update_column(:developer_id, developer.id)
70+
developer.reload
71+
72+
developer.strict_loading!(mode: :n_plus_one_only)
73+
assert_predicate developer, :strict_loading?
6674

6775
# Does not raise when a belongs_to association (:ship) loads its
6876
# has_many association (:parts)

0 commit comments

Comments
 (0)