public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Test for eager loading of STI subclasses from htm associations

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Tarmo Tänav (author)
Sat Aug 16 14:20:55 -0700 2008
lifo (committer)
Sat Aug 16 14:26:11 -0700 2008
commit  96607996eaa826b5299780c7c9142e6e0157d198
tree    bfe3d0a54a0d688c9d9df9c4b78040730b330e93
parent  8cfdcdb35db6e2f6fd5a72a38f4352beab148af1
...
694
695
696
 
 
 
 
 
 
 
697
698
699
...
694
695
696
697
698
699
700
701
702
703
704
705
706
0
@@ -694,6 +694,13 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
0
     assert ! david.categories.include?(category)
0
   end
0
 
0
+  def test_has_many_through_goes_through_all_sti_classes
0
+    sub_sti_post = SubStiPost.create!(:title => 'test', :body => 'test', :author_id => 1)
0
+    new_comment = sub_sti_post.comments.create(:body => 'test')
0
+
0
+    assert_equal [9, 10, new_comment.id], authors(:david).sti_post_comments.map(&:id).sort
0
+  end
0
+
0
   private
0
     # create dynamic Post models to allow different dependency options
0
     def find_post_with_dependency(post_id, association, association_name, dependency)
...
32
33
34
 
 
 
35
36
37
...
32
33
34
35
36
37
38
39
40
0
@@ -32,6 +32,9 @@ class Author < ActiveRecord::Base
0
   has_many :special_posts
0
   has_many :special_post_comments, :through => :special_posts, :source => :comments
0
 
0
+  has_many :sti_posts, :class_name => 'StiPost'
0
+  has_many :sti_post_comments, :through => :sti_posts, :source => :comments
0
+
0
   has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
0
   has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
0
   has_many :nonexistant_comments, :through => :posts

Comments