Create templates with format=nil

This commit is contained in:
John Hawthorn 2019-02-25 19:33:50 -08:00
parent ff4b2cf241
commit c214546217
6 changed files with 11 additions and 9 deletions

@ -973,10 +973,11 @@ def collect_responses_from_templates(headers)
templates_name = headers[:template_name] || action_name
each_template(Array(templates_path), templates_name).map do |template|
self.formats = [template.format]
format = template.format || self.formats.first
self.formats = [format]
{
body: render(template: template),
content_type: template.type.to_s
content_type: Mime[format].to_s
}
end
end

@ -118,7 +118,8 @@ def _render_template(options)
renderer.render_to_object(context, options)
end
@rendered_format = Template::Types[rendered_template.format]
rendered_format = rendered_template.format || lookup_context.formats.first
@rendered_format = Template::Types[rendered_format]
rendered_template.body
end

@ -294,12 +294,12 @@ def extract_handler_and_format_and_variant(path, query_format)
if handler.respond_to?(:default_format) # default_format can return nil
handler.default_format
else
query_format
nil
end
end
# Template::Types[format] and handler.default_format can return nil
[handler, format || query_format, variant]
[handler, format, variant]
end
end

@ -121,11 +121,11 @@ def teardown
assert_equal "Hello texty phone!", template.source
end
test "found templates respects given formats if one cannot be found from template or handler" do
test "found templates have nil format if one cannot be found from template or handler" do
assert_called(ActionView::Template::Handlers::Builder, :default_format, returns: nil) do
@lookup_context.formats = [:text]
template = @lookup_context.find("hello", %w(test))
assert_equal :text, template.format
assert_nil template.format
end
end

@ -19,7 +19,7 @@ def test_should_return_template_for_declared_path
assert_equal 1, templates.size, "expected one template"
assert_equal "Hello custom patterns!", templates.first.source
assert_equal "custom_pattern/path", templates.first.virtual_path
assert_equal :html, templates.first.format
assert_nil templates.first.format
end
def test_should_return_all_templates_when_ambiguous_pattern

@ -15,6 +15,6 @@ def test_should_return_template_for_declared_path
assert_equal 1, templates.size, "expected one template"
assert_equal "this text", templates.first.source
assert_equal "arbitrary/path", templates.first.virtual_path
assert_equal :html, templates.first.format
assert_nil templates.first.format
end
end