diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-03-11 10:29:10 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-03-11 10:29:10 -0700 |
commit | 3bfda09fa069caf9b28df78a19bb63c23c60169b (patch) | |
tree | dc5d1b31bf7b71a71a439cf3e0acbc33f032ca91 | |
parent | e56b594d323e9c17398e65caa0fad20500868135 (diff) | |
parent | 48f140cf7459c963a54637c897448b959dbbfd26 (diff) | |
download | rails-3bfda09fa069caf9b28df78a19bb63c23c60169b.tar.gz rails-3bfda09fa069caf9b28df78a19bb63c23c60169b.tar.bz2 rails-3bfda09fa069caf9b28df78a19bb63c23c60169b.zip |
Merge pull request #22854 from jcoyne/missing_template
Default rendering behavior if respond_to collector doesn't have a block.
-rw-r--r-- | actionpack/CHANGELOG.md | 7 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/mime_responds.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/mime/respond_to_test.rb | 15 |
3 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 9a13e88ec9..61c608972c 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,10 @@ +* 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`. diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 173a14a1d2..2e89af1a5e 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -198,7 +198,7 @@ module ActionController #:nodoc: _process_format(format) _set_rendered_content_type format response = collector.response - response ? response.call : render({}) + response.call if response else raise ActionController::UnknownFormat end diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index d0c7b2e06a..993f4001de 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -74,6 +74,14 @@ class RespondToController < ActionController::Base 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 @@ class RespondToControllerTest < ActionController::TestCase 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 } |