aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-03-17 14:20:23 +0100
committerYves Senn <yves.senn@gmail.com>2014-03-17 14:20:23 +0100
commit8ba60912ca42a66cb59a31346623a6f9d2439192 (patch)
treeff1a786634dad3141a8084b8a224dd47b529eaac /activerecord/test
parent378c8d2c996558aa4108280d5f0db8daf040d0fc (diff)
downloadrails-8ba60912ca42a66cb59a31346623a6f9d2439192.tar.gz
rails-8ba60912ca42a66cb59a31346623a6f9d2439192.tar.bz2
rails-8ba60912ca42a66cb59a31346623a6f9d2439192.zip
`where.not` adds `references` for `includes`.
Closes #14406.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb10
-rw-r--r--activerecord/test/cases/relations_test.rb8
2 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 416a39ea4c..e59161fc5b 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1203,4 +1203,14 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal 5, author.posts.size
}
end
+
+ test "including associations with where.not adds implicit references" do
+ author = assert_queries(2) {
+ Author.includes(:posts).where.not(posts: { title: 'Welcome to the weblog'} ).last
+ }
+
+ assert_no_queries {
+ assert_equal 2, author.posts.size
+ }
+ end
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 3b4b4c92f0..fddb7c204a 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1366,6 +1366,14 @@ class RelationTest < ActiveRecord::TestCase
assert_equal ['comments'], scope.references_values
end
+ def test_automatically_added_where_not_references
+ scope = Post.where.not(comments: { body: "Bla" })
+ assert_equal ['comments'], scope.references_values
+
+ scope = Post.where.not('comments.body' => 'Bla')
+ assert_equal ['comments'], scope.references_values
+ end
+
def test_automatically_added_having_references
scope = Post.having(:comments => { :body => "Bla" })
assert_equal ['comments'], scope.references_values