1
0
Fork 0
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:
Aaron Patterson 2013-09-23 18:13:08 -07:00
parent 9e60f0f630
commit 9b47142ce1
2 changed files with 19 additions and 1 deletions

View file

@ -29,7 +29,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :posts, :readers, :people, :comments, :authors, :categories, :taggings, :tags,
:owners, :pets, :toys, :jobs, :references, :companies, :members, :author_addresses,
:subscribers, :books, :subscriptions, :developers, :categorizations, :essays,
:categories_posts
:categories_posts, :clubs, :memberships
# Dummies to force column loads so query counts are clean.
def setup
@ -37,6 +37,19 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
Reader.create :person_id => 0, :post_id => 0
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)
Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } }
end

View file

@ -8,6 +8,11 @@ class CurrentMembership < Membership
belongs_to :club
end
class SuperMembership < Membership
belongs_to :member, -> { order('members.id DESC') }
belongs_to :club
end
class SelectedMembership < Membership
def self.default_scope
select("'1' as foo")