aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2006-03-15 18:27:26 +0000
committerJamis Buck <jamis@37signals.com>2006-03-15 18:27:26 +0000
commit6480d4974920ba3a22606770b49cb4140fa3ad40 (patch)
tree935a79655b67cf2c66634ac616be404dbdd1a5e1 /actionpack
parent6e283e9dc747e01444b9f17e6aab5f9240d5b5d7 (diff)
downloadrails-6480d4974920ba3a22606770b49cb4140fa3ad40.tar.gz
rails-6480d4974920ba3a22606770b49cb4140fa3ad40.tar.bz2
rails-6480d4974920ba3a22606770b49cb4140fa3ad40.zip
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
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/mime_responds.rb4
-rw-r--r--actionpack/test/controller/mime_responds_test.rb21
3 files changed, 27 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 9327105989..94c0a6bf95 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb
index 44b9dd933c..04ec1e5dd8 100644
--- a/actionpack/lib/action_controller/mime_responds.rb
+++ b/actionpack/lib/action_controller/mime_responds.rb
@@ -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
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 94273cf4af..a2b8eaad60 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -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 \ No newline at end of file