Permalink
Browse files

Make MimeResponds::Responder#any work without explicit types. Closes #…

…11140 [jaw6]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8987 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 8670631 commit 011e4694107f294e2b57cd885f9917205fccdcff @lifo lifo committed Mar 7, 2008
View
@@ -1,5 +1,7 @@
*SVN*
+* Make MimeResponds::Responder#any work without explicit types. Closes #11140 [jaw6]
+
* Better error message for type conflicts when parsing params. Closes #7962 [spicycode, matt]
* Remove unused ActionController::Base.template_class. Closes #10787 [Pratik]
@@ -125,15 +125,19 @@ def custom(mime_type, &block)
@order << mime_type
- @responses[mime_type] = Proc.new do
+ @responses[mime_type] ||= Proc.new do
@response.template.template_format = mime_type.to_sym
@response.content_type = mime_type.to_s
block_given? ? block.call : @controller.send(:render, :action => @controller.action_name)
end
end
def any(*args, &block)
- args.each { |type| send(type, &block) }
+ if args.any?
+ args.each { |type| send(type, &block) }
+ else
+ custom(@mime_type_priority.first, &block)
+ end
end
def method_missing(symbol, &block)
@@ -107,6 +107,13 @@ def handle_any
type.any(:js, :xml) { render :text => "Either JS or XML" }
end
end
+
+ def handle_any_any
+ respond_to do |type|
+ type.html { render :text => 'HTML' }
+ type.any { render :text => 'Whatever you ask for, I got it' }
+ end
+ end
def all_types_with_layout
respond_to do |type|
@@ -335,6 +342,35 @@ def test_handle_any
assert_equal 'Either JS or XML', @response.body
end
+ def test_handle_any_any
+ @request.env["HTTP_ACCEPT"] = "*/*"
+ get :handle_any_any
+ assert_equal 'HTML', @response.body
+ end
+
+ def test_handle_any_any_parameter_format
+ get :handle_any_any, {:format=>'html'}
+ assert_equal 'HTML', @response.body
+ end
+
+ def test_handle_any_any_explicit_html
+ @request.env["HTTP_ACCEPT"] = "text/html"
+ get :handle_any_any
+ assert_equal 'HTML', @response.body
+ end
+
+ def test_handle_any_any_javascript
+ @request.env["HTTP_ACCEPT"] = "text/javascript"
+ get :handle_any_any
+ assert_equal 'Whatever you ask for, I got it', @response.body
+ end
+
+ def test_handle_any_any_xml
+ @request.env["HTTP_ACCEPT"] = "text/xml"
+ get :handle_any_any
+ assert_equal 'Whatever you ask for, I got it', @response.body
+ end
+
def test_rjs_type_skips_layout
@request.env["HTTP_ACCEPT"] = "text/javascript"
get :all_types_with_layout

0 comments on commit 011e469

Please sign in to comment.