aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-03-05 20:10:24 +0000
committerJon Leighton <j@jonathanleighton.com>2011-03-05 20:10:24 +0000
commitddf83d14f1c7ddae07a285a8ad7c45f652edc843 (patch)
treef46cb89576a6267e6a501acec783ee12c1805a89 /activerecord/test
parent4206eff1895dccadcbec471798bfbd129404cc94 (diff)
downloadrails-ddf83d14f1c7ddae07a285a8ad7c45f652edc843.tar.gz
rails-ddf83d14f1c7ddae07a285a8ad7c45f652edc843.tar.bz2
rails-ddf83d14f1c7ddae07a285a8ad7c45f652edc843.zip
Add a test for STI on the through where the through is nested, and change the code which support this
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/nested_through_associations_test.rb9
-rw-r--r--activerecord/test/fixtures/taggings.yml10
-rw-r--r--activerecord/test/models/post.rb1
-rw-r--r--activerecord/test/models/rating.rb1
4 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/nested_through_associations_test.rb b/activerecord/test/cases/associations/nested_through_associations_test.rb
index a4ac69782a..0dd407f342 100644
--- a/activerecord/test/cases/associations/nested_through_associations_test.rb
+++ b/activerecord/test/cases/associations/nested_through_associations_test.rb
@@ -425,6 +425,15 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase
assert !scope.where("comments.type" => "SubSpecialComment").empty?
end
+ def test_has_many_through_with_sti_on_nested_through_reflection
+ taggings = posts(:sti_comments).special_comments_ratings_taggings
+ assert_equal [taggings(:special_comment_rating)], taggings
+
+ scope = Post.joins(:special_comments_ratings_taggings).where(:id => posts(:sti_comments).id)
+ assert scope.where("comments.type" => "Comment").empty?
+ assert !scope.where("comments.type" => "SpecialComment").empty?
+ end
+
def test_nested_has_many_through_writers_should_raise_error
david = authors(:david)
subscriber = subscribers(:first)
diff --git a/activerecord/test/fixtures/taggings.yml b/activerecord/test/fixtures/taggings.yml
index a337cce019..d339c12b25 100644
--- a/activerecord/test/fixtures/taggings.yml
+++ b/activerecord/test/fixtures/taggings.yml
@@ -66,3 +66,13 @@ other_by_mary_blue:
taggable_id: 11
taggable_type: Post
comment: first
+
+special_comment_rating:
+ id: 12
+ taggable_id: 2
+ taggable_type: Rating
+
+normal_comment_rating:
+ id: 13
+ taggable_id: 1
+ taggable_type: Rating
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index b39325f949..c3843fd264 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -50,6 +50,7 @@ class Post < ActiveRecord::Base
has_many :nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
has_many :special_comments_ratings, :through => :special_comments, :source => :ratings
+ has_many :special_comments_ratings_taggings, :through => :special_comments_ratings, :source => :taggings
has_and_belongs_to_many :categories
has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
diff --git a/activerecord/test/models/rating.rb b/activerecord/test/models/rating.rb
index 12c4b5affa..25a52c4ad7 100644
--- a/activerecord/test/models/rating.rb
+++ b/activerecord/test/models/rating.rb
@@ -1,3 +1,4 @@
class Rating < ActiveRecord::Base
belongs_to :comment
+ has_many :taggings, :as => :taggable
end