mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Introduce template factory
This commit is contained in:
@@ -90,4 +90,39 @@ class PartialCacheUnitTest < Minitest::Test
|
||||
# but measuring file reads is an OK proxy for this.
|
||||
assert_equal(1, file_system.file_read_count)
|
||||
end
|
||||
|
||||
def test_uses_default_template_factory_when_no_template_factory_found_in_register
|
||||
context = Liquid::Context.build(
|
||||
registers: {
|
||||
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
|
||||
}
|
||||
)
|
||||
|
||||
partial = Liquid::PartialCache.load(
|
||||
'my_partial',
|
||||
context: context,
|
||||
parse_context: Liquid::ParseContext.new
|
||||
)
|
||||
|
||||
assert_equal('my partial body', partial.render)
|
||||
end
|
||||
|
||||
def test_uses_template_factory_register_if_present
|
||||
template_factory = StubTemplateFactory.new
|
||||
context = Liquid::Context.build(
|
||||
registers: {
|
||||
file_system: StubFileSystem.new('my_partial' => 'my partial body'),
|
||||
template_factory: template_factory,
|
||||
}
|
||||
)
|
||||
|
||||
partial = Liquid::PartialCache.load(
|
||||
'my_partial',
|
||||
context: context,
|
||||
parse_context: Liquid::ParseContext.new
|
||||
)
|
||||
|
||||
assert_equal('my partial body', partial.render)
|
||||
assert_equal(1, template_factory.count)
|
||||
end
|
||||
end
|
||||
|
||||
12
test/unit/template_factory_unit_test.rb
Normal file
12
test/unit/template_factory_unit_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class TemplateFactoryUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_for_returns_liquid_template_instance
|
||||
template = TemplateFactory.new.for("anything")
|
||||
assert_instance_of(Liquid::Template, template)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user