提交 3bfda09f 编写于 作者: S Sean Griffin

Merge pull request #22854 from jcoyne/missing_template

Default rendering behavior if respond_to collector doesn't have a block.
* When a `respond_to` collector with a block doesn't have a response, then
a `:no_content` response should be rendered. This brings the default
rendering behavior introduced by https://github.com/rails/rails/issues/19036
to controller methods employing `respond_to`
*Justin Coyne*
* Add `ActionController::Parameters#dig` on Ruby 2.3 and greater, which
behaves the same as `Hash#dig`.
......
......@@ -198,7 +198,7 @@ def respond_to(*mimes)
_process_format(format)
_set_rendered_content_type format
response = collector.response
response ? response.call : render({})
response.call if response
else
raise ActionController::UnknownFormat
end
......
......@@ -74,6 +74,14 @@ def using_defaults
end
end
def missing_templates
respond_to do |type|
# This test requires a block that is empty
type.json { }
type.xml
end
end
def using_defaults_with_type_list
respond_to(:html, :xml)
end
......@@ -624,6 +632,13 @@ def test_invalid_format
end
end
def test_missing_templates
get :missing_templates, format: :json
assert_response :no_content
get :missing_templates, format: :xml
assert_response :no_content
end
def test_invalid_variant
assert_raises(ActionController::UnknownFormat) do
get :variant_with_implicit_template_rendering, params: { v: :invalid }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册