Skip to content

Commit

Permalink
Replace with_multi_batch_size with stub_const
Browse files Browse the repository at this point in the history
  • Loading branch information
djmb committed Feb 4, 2025
1 parent 129bc44 commit e5729b4
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions test/models/solid_cache/entry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class EntryTest < ActiveSupport::TestCase
end

test "batching multi queries" do
with_multi_batch_size(2) do
Entry.stubs(:const_get).with(:MULTI_BATCH_SIZE).returns("stubbed_value")

stub_const(Entry, :MULTI_BATCH_SIZE, 2) do
assert_queries_count(2) do
Entry.write_multi([ { key: "hello".b, value: "there" }, { key: "foo".b, value: "bar" }, { key: "baz".b, value: "zab" } ])
end
Expand All @@ -88,15 +86,5 @@ class EntryTest < ActiveSupport::TestCase
def write_entries(count = 20)
Entry.write_multi(count.times.map { |i| { key: "key#{i}", value: "value#{i}" } })
end

def with_multi_batch_size(value)
old_value = Entry::MULTI_BATCH_SIZE
Entry.send(:remove_const, :MULTI_BATCH_SIZE)
Entry.const_set(:MULTI_BATCH_SIZE, value)
yield
ensure
Entry.send(:remove_const, :MULTI_BATCH_SIZE)
Entry.const_set(:MULTI_BATCH_SIZE, old_value)
end
end
end

0 comments on commit e5729b4

Please sign in to comment.