Ensure that partial caches are shared with subcontexts

Make Context use StaticRegisters by default. This makes it easier to
ensure that all subcontexts share the same static registers.

Co-authored-by: Dylan Thacker-Smith <[email protected]>
This commit is contained in:
Chris AtLee
2022-04-08 10:05:58 -04:00
co-authored by Dylan Thacker-Smith
parent 1cae1e497f
commit 6c2c621712
7 changed files with 66 additions and 9 deletions
+14
View File
@@ -618,6 +618,20 @@ class ContextTest < Minitest::Test
end
end
def test_context_always_uses_static_registers
registers = {
my_register: :my_value,
}
c = Context.new({}, {}, registers)
assert_instance_of(StaticRegisters, c.registers)
assert_equal(:my_value, c.registers[:my_register])
r = StaticRegisters.new(registers)
c = Context.new({}, {}, r)
assert_instance_of(StaticRegisters, c.registers)
assert_equal(:my_value, c.registers[:my_register])
end
private
def assert_no_object_allocations
+2 -2
View File
@@ -32,7 +32,7 @@ class TestDrop < Liquid::Drop
attr_reader :value
def registers
@context.registers
{ @value => @context.registers[@value] }
end
end
@@ -440,7 +440,7 @@ class StandardFiltersTest < Minitest::Test
end
def test_map_calls_context=
model = TestModel.new(value: "test")
model = TestModel.new(value: :test)
template = Template.parse('{{ foo | map: "registers" }}')
template.registers[:test] = 1234