Skip to content

Commit

Permalink
fix respond_to without blocks not working if one of the blocks is all
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser authored and steveklabnik committed Feb 24, 2013
1 parent c3d001b commit 149e3cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 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*
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/mime_responds.rb
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions actionpack/test/controller/mime_responds_test.rb
Expand Up @@ -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" }
Expand Down Expand Up @@ -301,6 +308,20 @@ def test_using_defaults
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
Expand Down
@@ -0,0 +1 @@
HTML!

0 comments on commit 149e3cd

Please sign in to comment.