From ba4e68f577efc76f351d30a2914e29942b97830e Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 28 Nov 2018 01:48:33 +0900 Subject: Ensure that singular association should execute limited query --- .../test/cases/associations/belongs_to_associations_test.rb | 9 ++++++--- .../test/cases/associations/has_one_associations_test.rb | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 93dd427951..c1a335bda8 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -32,9 +32,12 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase :posts, :tags, :taggings, :comments, :sponsors, :members def test_belongs_to - firm = Client.find(3).firm - assert_not_nil firm - assert_equal companies(:first_firm).name, firm.name + client = Client.find(3) + assert_sql(/LIMIT|ROWNUM <=|FETCH FIRST/) do + firm = client.firm + assert_not_nil firm + assert_equal companies(:first_firm).name, firm.name + end end def test_assigning_belongs_to_on_destroyed_object diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index adfb3ce072..a032f130ca 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -22,8 +22,12 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end def test_has_one - assert_equal companies(:first_firm).account, Account.find(1) - assert_equal Account.find(1).credit_limit, companies(:first_firm).account.credit_limit + firm = companies(:first_firm) + assert_sql(/LIMIT|ROWNUM <=|FETCH FIRST/) do + account = firm.account + assert_equal account, Account.find(1) + assert_equal Account.find(1).credit_limit, account.credit_limit + end end def test_has_one_does_not_use_order_by -- cgit v1.2.3