From 812e5f15b27b4961ed019fe9fee77c03e8cd6209 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Wed, 14 Feb 2024 11:51:03 -0800 Subject: [PATCH] More tests for should_use_cache? optimization --- test/fetch_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/fetch_test.rb b/test/fetch_test.rb index 37b50d0f..41b237ce 100644 --- a/test/fetch_test.rb +++ b/test/fetch_test.rb @@ -354,6 +354,30 @@ def test_should_use_cache_not_called_on_prefetched item.fetch_item end + def test_should_use_cache_not_called_on_prefetched_has_many + Item.send(:cache_has_many, :associated_records) + + bob = Item.create!(title: "bob") + bob.associated_records.create!(name: "foo") + bob.associated_records.create!(name: "bar") + + item = Item.fetch(bob.id, includes: [:associated_records]) + IdentityCache.expects(:should_use_cache?).never + item.fetch_associated_records + end + + def test_should_use_cache_not_called_on_prefetched_has_many_multi + Item.send(:cache_has_many, :associated_records) + + bob = Item.create!(title: "bob") + bob.associated_records.create!(name: "foo") + bob.associated_records.create!(name: "bar") + + item = Item.fetch_multi([bob.id], includes: [:associated_records]) + IdentityCache.expects(:should_use_cache?).never + item.first.fetch_associated_records + end + def test_should_use_cache_not_called_on_prefetched_multi Item.send(:cache_belongs_to, :item)