aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/collection_cache_key_test.rb
diff options
context:
space:
mode:
authorPrathamesh Sonpatki <csonpatki@gmail.com>2016-01-14 10:21:28 +0530
committerPrathamesh Sonpatki <csonpatki@gmail.com>2016-01-24 22:36:13 +0530
commit29cf0dd9f48782c94de924a11b4fd1ad7b939dc5 (patch)
treeaf9ec6ff681e5878e45aea84aca954a8b321c020 /activerecord/test/cases/collection_cache_key_test.rb
parent62aa850fee2070ec3e2d9e4f925dfd7790d27b5e (diff)
downloadrails-29cf0dd9f48782c94de924a11b4fd1ad7b939dc5.tar.gz
rails-29cf0dd9f48782c94de924a11b4fd1ad7b939dc5.tar.bz2
rails-29cf0dd9f48782c94de924a11b4fd1ad7b939dc5.zip
Fix AR::Relation#cache_key to remove select scope added by user
- We don't need the select scope added by user as we only want to max timestamp and size of the collection. So we already know which columns to select. - Additionally having user defined columns in select scope blows the cache_key method with PostGreSQL because it needs all `selected` columns in the group_by clause or aggregate function. - Fixes #23038.
Diffstat (limited to 'activerecord/test/cases/collection_cache_key_test.rb')
-rw-r--r--activerecord/test/cases/collection_cache_key_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/collection_cache_key_test.rb b/activerecord/test/cases/collection_cache_key_test.rb
index 6b34979e4a..a2874438c1 100644
--- a/activerecord/test/cases/collection_cache_key_test.rb
+++ b/activerecord/test/cases/collection_cache_key_test.rb
@@ -79,5 +79,11 @@ module ActiveRecord
developers = Developer.offset(20)
assert_match(/\Adevelopers\/query-(\h+)-0\Z/, developers.cache_key)
end
+
+ test "cache_key with a relation having selected columns" do
+ developers = Developer.select(:salary)
+
+ assert_match(/\Adevelopers\/query-(\h+)-(\d+)-(\d+)\Z/, developers.cache_key)
+ end
end
end