Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding a test for sti on middle tables with sorting on RHS

  • Loading branch information...
commit 9b47142ce120d0a7d715648259ffa238526d1f82 1 parent 9e60f0f
@tenderlove tenderlove authored
View
15 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -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 @@ def setup
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
5 activerecord/test/models/membership.rb
@@ -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")
Please sign in to comment.
Something went wrong with that request. Please try again.