Skip to content

Commit ba4e68f

Browse files
committed
Ensure that singular association should execute limited query
1 parent 93c9497 commit ba4e68f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

activerecord/test/cases/associations/belongs_to_associations_test.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
3232
:posts, :tags, :taggings, :comments, :sponsors, :members
3333

3434
def test_belongs_to
35-
firm = Client.find(3).firm
36-
assert_not_nil firm
37-
assert_equal companies(:first_firm).name, firm.name
35+
client = Client.find(3)
36+
assert_sql(/LIMIT|ROWNUM <=|FETCH FIRST/) do
37+
firm = client.firm
38+
assert_not_nil firm
39+
assert_equal companies(:first_firm).name, firm.name
40+
end
3841
end
3942

4043
def test_assigning_belongs_to_on_destroyed_object

activerecord/test/cases/associations/has_one_associations_test.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ def setup
2222
end
2323

2424
def test_has_one
25-
assert_equal companies(:first_firm).account, Account.find(1)
26-
assert_equal Account.find(1).credit_limit, companies(:first_firm).account.credit_limit
25+
firm = companies(:first_firm)
26+
assert_sql(/LIMIT|ROWNUM <=|FETCH FIRST/) do
27+
account = firm.account
28+
assert_equal account, Account.find(1)
29+
assert_equal Account.find(1).credit_limit, account.credit_limit
30+
end
2731
end
2832

2933
def test_has_one_does_not_use_order_by

0 commit comments

Comments
 (0)