mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
adding a test for sti on middle tables with sorting on RHS
This commit is contained in:
parent
9e60f0f630
commit
9b47142ce1
2 changed files with 19 additions and 1 deletions
|
@ -29,7 +29,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
fixtures :posts, :readers, :people, :comments, :authors, :categories, :taggings, :tags,
|
fixtures :posts, :readers, :people, :comments, :authors, :categories, :taggings, :tags,
|
||||||
:owners, :pets, :toys, :jobs, :references, :companies, :members, :author_addresses,
|
:owners, :pets, :toys, :jobs, :references, :companies, :members, :author_addresses,
|
||||||
:subscribers, :books, :subscriptions, :developers, :categorizations, :essays,
|
:subscribers, :books, :subscriptions, :developers, :categorizations, :essays,
|
||||||
:categories_posts
|
:categories_posts, :clubs, :memberships
|
||||||
|
|
||||||
# Dummies to force column loads so query counts are clean.
|
# Dummies to force column loads so query counts are clean.
|
||||||
def setup
|
def setup
|
||||||
|
@ -37,6 +37,19 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
Reader.create :person_id => 0, :post_id => 0
|
Reader.create :person_id => 0, :post_id => 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_preload_sti_middle_relation
|
||||||
|
club = Club.create!(name: 'Aaron cool banana club')
|
||||||
|
member1 = Member.create!(name: 'Aaron')
|
||||||
|
member2 = Member.create!(name: 'Cat')
|
||||||
|
|
||||||
|
SuperMembership.create! club: club, member: member1
|
||||||
|
CurrentMembership.create! club: club, member: member2
|
||||||
|
|
||||||
|
club1 = Club.includes(:members).find_by_id club.id
|
||||||
|
left, right = club1.members.map(&:id)
|
||||||
|
assert_operator left, :>, right
|
||||||
|
end
|
||||||
|
|
||||||
def make_model(name)
|
def make_model(name)
|
||||||
Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } }
|
Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } }
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,11 @@ class CurrentMembership < Membership
|
||||||
belongs_to :club
|
belongs_to :club
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SuperMembership < Membership
|
||||||
|
belongs_to :member, -> { order('members.id DESC') }
|
||||||
|
belongs_to :club
|
||||||
|
end
|
||||||
|
|
||||||
class SelectedMembership < Membership
|
class SelectedMembership < Membership
|
||||||
def self.default_scope
|
def self.default_scope
|
||||||
select("'1' as foo")
|
select("'1' as foo")
|
||||||
|
|
Loading…
Reference in a new issue