From 149e3cd376caa23cf4d8c4b711b95e157186fc94 Mon Sep 17 00:00:00 2001 From: grosser Date: Tue, 2 Oct 2012 09:22:26 -0700 Subject: [PATCH] fix respond_to without blocks not working if one of the blocks is all --- actionpack/CHANGELOG.md | 2 ++ .../action_controller/metal/mime_responds.rb | 2 +- .../test/controller/mime_responds_test.rb | 21 +++++++++++++++++++ .../using_defaults_with_all.html.erb | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_all.html.erb diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 528fa291c5..5be7f34331 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Fix `respond_to` not using formats that have no block if all is present. *Michael Grosser* + * New applications use an encrypted session store by default. *Santiago Pastorino* diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 93568da9ef..834d44f045 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -420,7 +420,7 @@ def custom(mime_type, &block) end def response - @responses[format] || @responses[Mime::ALL] + @responses.fetch(format, @responses[Mime::ALL]) end def negotiate_format(request) diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index ed013e2185..a9c62899b5 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -80,6 +80,13 @@ def using_defaults_with_type_list respond_to(:html, :xml) end + def using_defaults_with_all + respond_to do |type| + type.html + type.all{ render text: "ALL" } + end + end + def made_for_content_type respond_to do |type| type.rss { render :text => "RSS" } @@ -301,6 +308,20 @@ def test_using_defaults assert_equal "

Hello world!

\n", @response.body end + def test_using_defaults_with_all + @request.accept = "*/*" + get :using_defaults_with_all + assert_equal "HTML!", @response.body.strip + + @request.accept = "text/html" + get :using_defaults_with_all + assert_equal "HTML!", @response.body.strip + + @request.accept = "application/json" + get :using_defaults_with_all + assert_equal "ALL", @response.body + end + def test_using_defaults_with_type_list @request.accept = "*/*" get :using_defaults_with_type_list diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_all.html.erb b/actionpack/test/fixtures/respond_to/using_defaults_with_all.html.erb new file mode 100644 index 0000000000..9f1f855269 --- /dev/null +++ b/actionpack/test/fixtures/respond_to/using_defaults_with_all.html.erb @@ -0,0 +1 @@ +HTML! -- GitLab