@@ -39,15 +39,11 @@ def test_strict_loading!
39
39
assert developer . strict_loading_n_plus_one_only?
40
40
end
41
41
42
- def test_strict_loading_n_plus_one_only_mode
42
+ def test_strict_loading_n_plus_one_only_mode_with_has_many
43
43
developer = Developer . first
44
- ship = Ship . first
45
- ShipPart . create! ( name : "Stern" , ship : ship )
46
44
firm = Firm . create! ( name : "NASA" )
47
- project = Project . create! ( name : "Apollo" , firm : firm )
45
+ developer . projects << Project . create! ( name : "Apollo" , firm : firm )
48
46
49
- ship . update_column ( :developer_id , developer . id )
50
- developer . projects << project
51
47
developer . reload
52
48
53
49
developer . strict_loading! ( mode : :n_plus_one_only )
@@ -63,6 +59,18 @@ def test_strict_loading_n_plus_one_only_mode
63
59
assert_raises ActiveRecord ::StrictLoadingViolationError do
64
60
developer . projects . last . firm
65
61
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?
66
74
67
75
# Does not raise when a belongs_to association (:ship) loads its
68
76
# has_many association (:parts)
0 commit comments