aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/collection_cache_key_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/collection_cache_key_test.rb')
-rw-r--r--activerecord/test/cases/collection_cache_key_test.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/test/cases/collection_cache_key_test.rb b/activerecord/test/cases/collection_cache_key_test.rb
index 724234d7f4..a2874438c1 100644
--- a/activerecord/test/cases/collection_cache_key_test.rb
+++ b/activerecord/test/cases/collection_cache_key_test.rb
@@ -53,7 +53,7 @@ module ActiveRecord
test "cache_key with custom timestamp column" do
topics = Topic.where("title like ?", "%Topic%")
- last_topic_timestamp = topics(:fifth).written_on.utc.to_s(:nsec)
+ last_topic_timestamp = topics(:fifth).written_on.utc.to_s(:usec)
assert_match(last_topic_timestamp, topics.cache_key(:written_on))
end
@@ -66,5 +66,24 @@ module ActiveRecord
developers = projects(:active_record).developers
assert_match(/\Adevelopers\/query-(\h+)-(\d+)-(\d+)\Z/, developers.cache_key)
end
+
+ test "cache_key for loaded collection with zero size" do
+ Comment.delete_all
+ posts = Post.includes(:comments)
+ empty_loaded_collection = posts.first.comments
+
+ assert_match(/\Acomments\/query-(\h+)-0\Z/, empty_loaded_collection.cache_key)
+ end
+
+ test "cache_key for queries with offset which return 0 rows" do
+ 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