aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-11-28 01:48:33 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-11-28 01:48:33 +0900
commitba4e68f577efc76f351d30a2914e29942b97830e (patch)
tree9e81b17082652ccfff3d1900bcb18025a625b9a1 /activerecord
parent93c94973ab574083a8cd1868aae03993ca156c34 (diff)
downloadrails-ba4e68f577efc76f351d30a2914e29942b97830e.tar.gz
rails-ba4e68f577efc76f351d30a2914e29942b97830e.tar.bz2
rails-ba4e68f577efc76f351d30a2914e29942b97830e.zip
Ensure that singular association should execute limited query
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb9
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb8
2 files changed, 12 insertions, 5 deletions
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