Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
George Guimarães georgeguimaraes authored
9 lib/responders_backport/respond_to.rb
@@ -136,17 +136,14 @@ def response_for(mime)
136 136 def negotiate_mime
137 137 @mime_type_priority.each do |priority|
138 138 if priority == Mime::ALL
139   - return @order.first
  139 + return @order.find { |m| m != Mime::ALL } || Mime::SET.first
  140 + elsif @order.include?(Mime::ALL)
  141 + return @mime_type_priority.find { |m| m != Mime::ALL } || Mime::SET.first
140 142 elsif @order.include?(priority)
141 143 return priority
142 144 end
143 145 end
144 146
145   - if @order.include?(Mime::ALL)
146   - return Mime::SET.first if @mime_type_priority.first == Mime::ALL
147   - return @mime_type_priority.first
148   - end
149   -
150 147 nil
151 148 end
152 149 end
19 test/respond_to_test.rb
@@ -55,6 +55,15 @@ def respond_to_skip_default_template
55 55 class SuperProjectsController < ProjectsController
56 56 end
57 57
  58 +class NonInheritedResourcesController < ActionController::Base
  59 + def index
  60 + respond_to do |format|
  61 + format.xml { render :text => 'Render XML' }
  62 + format.any { render :text => 'Render HTML' }
  63 + end
  64 + end
  65 +end
  66 +
58 67 class RespondToFunctionalTest < ActionController::TestCase
59 68 tests ProjectsController
60 69
@@ -153,3 +162,13 @@ def test_respond_to_skip_default_template_when_it_is_in_block
153 162 assert_equal 'Render HTML', @response.body.strip
154 163 end
155 164 end
  165 +
  166 +class RespondToFunctionalStandardControllerTest < ActionController::TestCase
  167 + tests NonInheritedResourcesController
  168 +
  169 + def test_respond_with_no_specific_format
  170 + @request.accept = 'application/xml,application/xhtml+xml,text/html'
  171 + get :index
  172 + assert_equal 'Render HTML', @response.body.strip
  173 + end
  174 +end

0 comments on commit b143adb

Please sign in to comment.
Something went wrong with that request. Please try again.