Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changes from InheritedResources v1.0:

*  Handle some edge cases in respond_to.
*  Fix mime negotiation if no specific format is requested.
  • Loading branch information...
commit b143adbb671c99f84e2d36ff683486eca9ec679f 1 parent 9ac0a5f
@georgeguimaraes georgeguimaraes authored
Showing with 22 additions and 6 deletions.
  1. +3 −6 lib/responders_backport/respond_to.rb
  2. +19 −0 test/respond_to_test.rb
View
9 lib/responders_backport/respond_to.rb
@@ -136,17 +136,14 @@ def response_for(mime)
def negotiate_mime
@mime_type_priority.each do |priority|
if priority == Mime::ALL
- return @order.first
+ return @order.find { |m| m != Mime::ALL } || Mime::SET.first
+ elsif @order.include?(Mime::ALL)
+ return @mime_type_priority.find { |m| m != Mime::ALL } || Mime::SET.first
elsif @order.include?(priority)
return priority
end
end
- if @order.include?(Mime::ALL)
- return Mime::SET.first if @mime_type_priority.first == Mime::ALL
- return @mime_type_priority.first
- end
-
nil
end
end
View
19 test/respond_to_test.rb
@@ -55,6 +55,15 @@ def respond_to_skip_default_template
class SuperProjectsController < ProjectsController
end
+class NonInheritedResourcesController < ActionController::Base
+ def index
+ respond_to do |format|
+ format.xml { render :text => 'Render XML' }
+ format.any { render :text => 'Render HTML' }
+ end
+ end
+end
+
class RespondToFunctionalTest < ActionController::TestCase
tests ProjectsController
@@ -153,3 +162,13 @@ def test_respond_to_skip_default_template_when_it_is_in_block
assert_equal 'Render HTML', @response.body.strip
end
end
+
+class RespondToFunctionalStandardControllerTest < ActionController::TestCase
+ tests NonInheritedResourcesController
+
+ def test_respond_with_no_specific_format
+ @request.accept = 'application/xml,application/xhtml+xml,text/html'
+ get :index
+ assert_equal 'Render HTML', @response.body.strip
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.