1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fix respond_to without blocks not working if one of the blocks is all

This commit is contained in:
grosser 2012-10-02 09:22:26 -07:00 committed by Steve Klabnik
parent c3d001b048
commit 149e3cd376
4 changed files with 25 additions and 1 deletions

View file

@ -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*

View file

@ -420,7 +420,7 @@ module ActionController #:nodoc:
end
def response
@responses[format] || @responses[Mime::ALL]
@responses.fetch(format, @responses[Mime::ALL])
end
def negotiate_format(request)

View file

@ -80,6 +80,13 @@ class RespondToController < ActionController::Base
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 @@ class RespondToControllerTest < ActionController::TestCase
assert_equal "<p>Hello world!</p>\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

View file

@ -0,0 +1 @@
HTML!