set context's template_name with template's name

This commit is contained in:
Michael Go
2023-02-28 10:55:38 -04:00
parent 428c66ffac
commit 24dceef552
7 changed files with 63 additions and 57 deletions
+17 -9
View File
@@ -357,16 +357,24 @@ class IncludeTagTest < Minitest::Test
)
end
def test_include_tag_renders_actual_template_name_for_error
original_file_system = Liquid::Template.file_system
Liquid::Template.file_system = MemoryFileSystem.new(
'/some/path/snippets/foo.liquid' => "{{ foo.standard_error }}",
def test_render_tag_renders_error_with_template_name
assert_template_result(
'Liquid error (foo line 1): standard error',
"{% include 'foo' with errors %}",
{ 'errors' => ErrorDrop.new },
partials: { 'foo' => '{{ foo.standard_error }}' },
render_errors: true,
)
end
template = Liquid::Template.parse("{% include 'foo' with errors %}", line_numbers: true)
assert_equal('Liquid error (/some/path/snippets/foo line 1): standard error', template.render('errors' => ErrorDrop.new))
ensure
Liquid::Template.file_system = original_file_system
def test_render_tag_renders_error_with_template_name_from_template_factory
assert_template_result(
'Liquid error (some/path/foo line 1): standard error',
"{% include 'foo' with errors %}",
{ 'errors' => ErrorDrop.new },
partials: { 'foo' => '{{ foo.standard_error }}' },
template_factory: StubTemplateFactory.new,
render_errors: true,
)
end
end # IncludeTagTest
+17 -11
View File
@@ -265,18 +265,24 @@ class RenderTagTest < Minitest::Test
)
end
def test_render_tag_renders_actual_template_name_for_error
original_file_system = Liquid::Template.file_system
context = Liquid::Context.new('errors' => ErrorDrop.new)
context.registers[:file_system] = MemoryFileSystem.new(
'/some/path/snippets/foo.liquid' => "{{ foo.standard_error }}",
def test_render_tag_renders_error_with_template_name
assert_template_result(
'Liquid error (foo line 1): standard error',
"{% render 'foo' with errors %}",
{ 'errors' => ErrorDrop.new },
partials: { 'foo' => '{{ foo.standard_error }}' },
render_errors: true,
)
end
template = Liquid::Template.parse("{% render 'foo' with errors %}", line_numbers: true)
assert_equal('Liquid error (/some/path/snippets/foo line 1): standard error', template.render(context))
ensure
Liquid::Template.file_system = original_file_system
def test_render_tag_renders_error_with_template_name_from_template_factory
assert_template_result(
'Liquid error (some/path/foo line 1): standard error',
"{% render 'foo' with errors %}",
{ 'errors' => ErrorDrop.new },
partials: { 'foo' => '{{ foo.standard_error }}' },
template_factory: StubTemplateFactory.new,
render_errors: true,
)
end
end