Skip to content

Commit

Permalink
More tests for should_use_cache? optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Feb 14, 2024
1 parent d1e53f7 commit 812e5f1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/fetch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 812e5f1

Please sign in to comment.