mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add MimeResponds::Responder#any for managing multiple types with identical responses
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3876 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
6e283e9dc7
commit
6480d49749
3 changed files with 27 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Add MimeResponds::Responder#any for managing multiple types with identical responses [Jamis Buck]
|
||||
|
||||
* Make the xml_http_request testing method set the HTTP_ACCEPT header [Jamis Buck]
|
||||
|
||||
* Add Verification to scaffolds. Prevent destructive actions using GET [Michael Koziarski]
|
||||
|
|
|
@ -51,6 +51,10 @@ module ActionController #:nodoc:
|
|||
end
|
||||
EOT
|
||||
end
|
||||
|
||||
def any(*args, &block)
|
||||
args.each { |type| send(type, &block) }
|
||||
end
|
||||
|
||||
def respond
|
||||
for priority in @mime_type_priority
|
||||
|
|
|
@ -64,6 +64,13 @@ class RespondToController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def handle_any
|
||||
respond_to do |type|
|
||||
type.html { render :text => "HTML" }
|
||||
type.any(:js, :xml) { render :text => "Either JS or XML" }
|
||||
end
|
||||
end
|
||||
|
||||
def rescue_action(e)
|
||||
raise unless ActionController::MissingTemplate === e
|
||||
end
|
||||
|
@ -195,4 +202,18 @@ class MimeControllerTest < Test::Unit::TestCase
|
|||
get :html_or_xml
|
||||
assert_equal 'HTML', @response.body
|
||||
end
|
||||
|
||||
def test_handle_any
|
||||
@request.env["HTTP_ACCEPT"] = "*/*"
|
||||
get :handle_any
|
||||
assert_equal 'HTML', @response.body
|
||||
|
||||
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
||||
get :handle_any
|
||||
assert_equal 'Either JS or XML', @response.body
|
||||
|
||||
@request.env["HTTP_ACCEPT"] = "text/xml"
|
||||
get :handle_any
|
||||
assert_equal 'Either JS or XML', @response.body
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue