Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix respond_to without blocks always using all if one of the blocks is all #7823

Closed
wants to merge 1 commit into from

4 participants

@grosser

would also be great to see this included in all minor releases of rails 3

@grosser

FYI: hotfix

# https://github.com/rails/rails/pull/7823
if Rails::VERSION::MAJOR == 3
  ActionController::MimeResponds::Collector.class_eval do
    def custom_with_block_fix(mime_type, &block)
      custom_without_block_fix(mime_type, &(block || lambda{}))
    end
    alias_method_chain :custom, :block_fix
  end
else
  puts "You can remove #{__FILE__}:#{__LINE__} now!"
end
@rafaelfranca
Owner

Are you trying to change the behavior of respond_to with a block argument or without the block?

@grosser

with block, the tests show what I'm up to :)

actionpack/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Fix respond_to without format blocks always using all if one of the blocks is all. *Michael Grosser*
@frodsan
frodsan added a note
`respond_to`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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" }
@frodsan
frodsan added a note

Please, use 1.9 hash syntax. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@grosser

Done and done

actionpack/CHANGELOG.md
@@ -50,6 +50,8 @@
*Francesco Rodriguez*
+* Fix `respond_to` without format blocks always using all if one of the blocks is all. *Michael Grosser*
@frodsan
frodsan added a note

Entries must be on top.

@grosser
grosser added a note

I'll put it on top if someone wants to merge it, keeping it here will keep the merge-button green + I do not get a merge conflict on the next rebase.
If you can + want to merge it, let me know :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@steveklabnik
Collaborator

@rafaelfranca would you merge this if @grosser fixes the CHANGELOG entry?

@rafaelfranca

For the CHANGELOG entry and issue description I could not understand the problem. The CHANGELOG says "without block", but the tests use a block.

Also it needs a rebase and the CHANGELOG should be on the top

@grosser

@rafaelfranca rebased and put on top + hopefully clearer description :)

@grosser

Updated with simpler implementation

@grosser

@rafaelfranca looks good ? / can you merge it ?

@grosser

@rafaelfranca
Rebased once more, please merge

@grosser

@steveklabnik can you merge this ?

@steveklabnik
Collaborator

I just took care of the merge conflict myself and merged. Sorry this took so long to address.

@steveklabnik
Collaborator

Merged in 149e3cd

@grosser

Thanks you so much! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  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*
+
* Determine the controller#action from only the matched path when using the
shorthand syntax. Previously the complete path was used, which led
to problems with nesting (scopes and namespaces).
View
2  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)
View
21 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 "<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
1  actionpack/test/fixtures/respond_to/using_defaults_with_all.html.erb
@@ -0,0 +1 @@
+HTML!
Something went wrong with that request. Please try again.