aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-07-15 21:09:58 +0200
committerGitHub <noreply@github.com>2017-07-15 21:09:58 +0200
commit5153c0c21daa2f19b01e8ed2738e9f154bd948f7 (patch)
tree79959ebc75dd4fe596450befd01fce6898212879 /activerecord
parenta07ddbf5e3e4e6fbced0f9bd8da48f1abb4013c1 (diff)
parentd3303c31c23e7fdbd9e523c628c111ef6bea0e74 (diff)
downloadrails-5153c0c21daa2f19b01e8ed2738e9f154bd948f7.tar.gz
rails-5153c0c21daa2f19b01e8ed2738e9f154bd948f7.tar.bz2
rails-5153c0c21daa2f19b01e8ed2738e9f154bd948f7.zip
Merge pull request #29679 from kamipo/add_test_case_for_27724
Add a test case for overwriting existing condition on associations
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb7
-rw-r--r--activerecord/test/models/post.rb5
2 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 1c2138a3d0..a76159fb99 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -946,6 +946,13 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_has_many_through_polymorphic_with_rewhere
+ post = TaggedPost.create!(title: "Tagged", body: "Post")
+ tag = post.tags.create!(name: "Tag")
+ assert_equal [tag], TaggedPost.preload(:tags).last.tags
+ assert_equal [tag], TaggedPost.eager_load(:tags).last.tags
+ end
+
def test_has_many_through_polymorphic_with_primary_key_option
assert_equal [categories(:general)], authors(:david).essay_categories
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index a99ab12b19..4aba336b01 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -199,6 +199,11 @@ class FirstPost < ActiveRecord::Base
has_one :comment, foreign_key: :post_id
end
+class TaggedPost < Post
+ has_many :taggings, -> { rewhere(taggable_type: "TaggedPost") }, as: :taggable
+ has_many :tags, through: :taggings
+end
+
class PostWithDefaultInclude < ActiveRecord::Base
self.inheritance_column = :disabled
self.table_name = "posts"