aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-04-19 12:52:44 +0100
committerJon Leighton <j@jonathanleighton.com>2013-06-28 11:47:00 +0100
commit55193e449a377c448e43d8fec42899ea1ff93b27 (patch)
treedfda1e0a1c4ee49d7f40304277afddc26c062b13 /activerecord/test
parent4642f5487a491de283910c662a519f14c21e136f (diff)
downloadrails-55193e449a377c448e43d8fec42899ea1ff93b27.tar.gz
rails-55193e449a377c448e43d8fec42899ea1ff93b27.tar.bz2
rails-55193e449a377c448e43d8fec42899ea1ff93b27.zip
Apply default scope when joining associations.
For example: class Post < ActiveRecord::Base default_scope -> { where published: true } end class Comment belongs_to :post end When calling `Comment.join(:post)`, we expect to receive only comments on published posts, since that is the default scope for posts. Before this change, the default scope from `Post` was not applied, so we'd get comments on unpublished posts.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/inner_join_association_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb
index 9baf94399a..de47a576c6 100644
--- a/activerecord/test/cases/associations/inner_join_association_test.rb
+++ b/activerecord/test/cases/associations/inner_join_association_test.rb
@@ -104,4 +104,12 @@ class InnerJoinAssociationTest < ActiveRecord::TestCase
assert !posts(:welcome).tags.empty?
assert Post.joins(:misc_tags).where(:id => posts(:welcome).id).empty?
end
+
+ test "the default scope of the target is applied when joining associations" do
+ author = Author.create! name: "Jon"
+ author.categorizations.create!
+ author.categorizations.create! special: true
+
+ assert_equal [author], Author.where(id: author).joins(:special_categorizations)
+ end
end