diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-11-28 03:34:20 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-11-28 03:34:20 +0900 |
commit | e4aec40578ea0dd2944f97f1ad60cfbdf4b3a44d (patch) | |
tree | bb7151ae8ec058b96338a95405f307f1cf5513eb /activerecord/test | |
parent | ba4e68f577efc76f351d30a2914e29942b97830e (diff) | |
download | rails-e4aec40578ea0dd2944f97f1ad60cfbdf4b3a44d.tar.gz rails-e4aec40578ea0dd2944f97f1ad60cfbdf4b3a44d.tar.bz2 rails-e4aec40578ea0dd2944f97f1ad60cfbdf4b3a44d.zip |
More exercise singular association query
Follow up ba4e68f577efc76f351d30a2914e29942b97830e.
Diffstat (limited to 'activerecord/test')
4 files changed, 14 insertions, 7 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index c1a335bda8..d1e4ebe86b 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -33,10 +33,10 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase def test_belongs_to client = Client.find(3) + first_firm = companies(:first_firm) assert_sql(/LIMIT|ROWNUM <=|FETCH FIRST/) do - firm = client.firm - assert_not_nil firm - assert_equal companies(:first_firm).name, firm.name + assert_equal first_firm, client.firm + assert_equal first_firm.name, client.firm.name end end diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index a032f130ca..bf574f6637 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -23,10 +23,10 @@ class HasOneAssociationsTest < ActiveRecord::TestCase def test_has_one firm = companies(:first_firm) + first_account = Account.find(1) 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 + assert_equal first_account, firm.account + assert_equal first_account.credit_limit, firm.account.credit_limit end end diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index 0309663943..69b4872519 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -35,6 +35,13 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase assert_equal clubs(:boring_club), @member.club end + def test_has_one_through_executes_limited_query + boring_club = clubs(:boring_club) + assert_sql(/LIMIT|ROWNUM <=|FETCH FIRST/) do + assert_equal boring_club, @member.general_club + end + end + def test_creating_association_creates_through_record new_member = Member.create(name: "Chris") new_member.club = Club.create(name: "LRUG") diff --git a/activerecord/test/models/club.rb b/activerecord/test/models/club.rb index 2006e05fcf..13e72e9c50 100644 --- a/activerecord/test/models/club.rb +++ b/activerecord/test/models/club.rb @@ -10,7 +10,7 @@ class Club < ActiveRecord::Base has_many :favourites, -> { where(memberships: { favourite: true }) }, through: :memberships, source: :member - scope :general, -> { left_joins(:category).where(categories: { name: "General" }) } + scope :general, -> { left_joins(:category).where(categories: { name: "General" }).unscope(:limit) } private |