Test for eager loading of STI subclasses from htm associations
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
parent
8cfdcdb35d
commit
96607996ea
|
@ -694,6 +694,13 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
||||||
assert ! david.categories.include?(category)
|
assert ! david.categories.include?(category)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_has_many_through_goes_through_all_sti_classes
|
||||||
|
sub_sti_post = SubStiPost.create!(:title => 'test', :body => 'test', :author_id => 1)
|
||||||
|
new_comment = sub_sti_post.comments.create(:body => 'test')
|
||||||
|
|
||||||
|
assert_equal [9, 10, new_comment.id], authors(:david).sti_post_comments.map(&:id).sort
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# create dynamic Post models to allow different dependency options
|
# create dynamic Post models to allow different dependency options
|
||||||
def find_post_with_dependency(post_id, association, association_name, dependency)
|
def find_post_with_dependency(post_id, association, association_name, dependency)
|
||||||
|
|
|
@ -32,6 +32,9 @@ class Author < ActiveRecord::Base
|
||||||
has_many :special_posts
|
has_many :special_posts
|
||||||
has_many :special_post_comments, :through => :special_posts, :source => :comments
|
has_many :special_post_comments, :through => :special_posts, :source => :comments
|
||||||
|
|
||||||
|
has_many :sti_posts, :class_name => 'StiPost'
|
||||||
|
has_many :sti_post_comments, :through => :sti_posts, :source => :comments
|
||||||
|
|
||||||
has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
|
has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
|
||||||
has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
|
has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
|
||||||
has_many :nonexistant_comments, :through => :posts
|
has_many :nonexistant_comments, :through => :posts
|
||||||
|
|
Loading…
Reference in New Issue