| 1 |
Index: test/controller/mime_responds_test.rb |
|---|
| 2 |
=================================================================== |
|---|
| 3 |
--- test/controller/mime_responds_test.rb (revision 8887) |
|---|
| 4 |
+++ test/controller/mime_responds_test.rb (working copy) |
|---|
| 5 |
@@ -107,6 +107,13 @@ |
|---|
| 6 |
type.any(:js, :xml) { render :text => "Either JS or XML" } |
|---|
| 7 |
end |
|---|
| 8 |
end |
|---|
| 9 |
+ |
|---|
| 10 |
+ def handle_any_any |
|---|
| 11 |
+ respond_to do |type| |
|---|
| 12 |
+ type.html { render :text => 'HTML' } |
|---|
| 13 |
+ type.any { render :text => 'Whatever you ask for, I got it' } |
|---|
| 14 |
+ end |
|---|
| 15 |
+ end |
|---|
| 16 |
|
|---|
| 17 |
def all_types_with_layout |
|---|
| 18 |
respond_to do |type| |
|---|
| 19 |
@@ -335,6 +342,35 @@ |
|---|
| 20 |
assert_equal 'Either JS or XML', @response.body |
|---|
| 21 |
end |
|---|
| 22 |
|
|---|
| 23 |
+ def test_handle_any_any |
|---|
| 24 |
+ @request.env["HTTP_ACCEPT"] = "*/*" |
|---|
| 25 |
+ get :handle_any_any |
|---|
| 26 |
+ assert_equal 'HTML', @response.body |
|---|
| 27 |
+ end |
|---|
| 28 |
+ |
|---|
| 29 |
+ def test_handle_any_any_parameter_format |
|---|
| 30 |
+ get :handle_any_any, {:format=>'html'} |
|---|
| 31 |
+ assert_equal 'HTML', @response.body |
|---|
| 32 |
+ end |
|---|
| 33 |
+ |
|---|
| 34 |
+ def test_handle_any_any_explicit_html |
|---|
| 35 |
+ @request.env["HTTP_ACCEPT"] = "text/html" |
|---|
| 36 |
+ get :handle_any_any |
|---|
| 37 |
+ assert_equal 'HTML', @response.body |
|---|
| 38 |
+ end |
|---|
| 39 |
+ |
|---|
| 40 |
+ def test_handle_any_any_javascript |
|---|
| 41 |
+ @request.env["HTTP_ACCEPT"] = "text/javascript" |
|---|
| 42 |
+ get :handle_any_any |
|---|
| 43 |
+ assert_equal 'Whatever you ask for, I got it', @response.body |
|---|
| 44 |
+ end |
|---|
| 45 |
+ |
|---|
| 46 |
+ def test_handle_any_any_xml |
|---|
| 47 |
+ @request.env["HTTP_ACCEPT"] = "text/xml" |
|---|
| 48 |
+ get :handle_any_any |
|---|
| 49 |
+ assert_equal 'Whatever you ask for, I got it', @response.body |
|---|
| 50 |
+ end |
|---|
| 51 |
+ |
|---|
| 52 |
def test_rjs_type_skips_layout |
|---|
| 53 |
@request.env["HTTP_ACCEPT"] = "text/javascript" |
|---|
| 54 |
get :all_types_with_layout |
|---|
| 55 |
Index: lib/action_controller/mime_responds.rb |
|---|
| 56 |
=================================================================== |
|---|
| 57 |
--- lib/action_controller/mime_responds.rb (revision 8887) |
|---|
| 58 |
+++ lib/action_controller/mime_responds.rb (working copy) |
|---|
| 59 |
@@ -125,15 +125,20 @@ |
|---|
| 60 |
|
|---|
| 61 |
@order << mime_type |
|---|
| 62 |
|
|---|
| 63 |
- @responses[mime_type] = Proc.new do |
|---|
| 64 |
+ @responses[mime_type] ||= Proc.new do |
|---|
| 65 |
@response.template.template_format = mime_type.to_sym |
|---|
| 66 |
@response.content_type = mime_type.to_s |
|---|
| 67 |
block_given? ? block.call : @controller.send(:render, :action => @controller.action_name) |
|---|
| 68 |
end |
|---|
| 69 |
+ # raise @responses.inspect |
|---|
| 70 |
end |
|---|
| 71 |
|
|---|
| 72 |
def any(*args, &block) |
|---|
| 73 |
- args.each { |type| send(type, &block) } |
|---|
| 74 |
+ if args.any? |
|---|
| 75 |
+ args.each { |type| send(type, &block) } |
|---|
| 76 |
+ else |
|---|
| 77 |
+ custom(@mime_type_priority.first, &block) |
|---|
| 78 |
+ end |
|---|
| 79 |
end |
|---|
| 80 |
|
|---|
| 81 |
def method_missing(symbol, &block) |
|---|