public
Fork of NZKoz/koz-rails
Description: Koz's rails git-svn clone
Homepage: http://www.rubyonrails.org
Clone URL: git://github.com/eventualbuddha/koz-rails.git
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
pratik (author)
Fri Mar 07 03:17:05 -0800 2008
commit  30829b9c70ca44f7e12d49ca5b053a011ff45778
tree    dbefbd42d08f6ae1c9c732423bd30125e2a4e241
parent  5c27d4040bc0f2f69c9c12e633e8502c888d1659
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Make MimeResponds::Responder#any work without explicit types. Closes #11140 [jaw6]
0
+
0
 * Better error message for type conflicts when parsing params. Closes #7962 [spicycode, matt]
0
 
0
 * Remove unused ActionController::Base.template_class. Closes #10787 [Pratik]
...
125
126
127
128
 
129
130
131
...
133
134
135
136
 
 
 
 
 
137
138
139
...
125
126
127
 
128
129
130
131
...
133
134
135
 
136
137
138
139
140
141
142
143
0
@@ -125,7 +125,7 @@ module ActionController #:nodoc:
0
 
0
         @order << mime_type
0
 
0
- @responses[mime_type] = Proc.new do
0
+ @responses[mime_type] ||= Proc.new do
0
           @response.template.template_format = mime_type.to_sym
0
           @response.content_type = mime_type.to_s
0
           block_given? ? block.call : @controller.send(:render, :action => @controller.action_name)
0
@@ -133,7 +133,11 @@ module ActionController #:nodoc:
0
       end
0
 
0
       def any(*args, &block)
0
- args.each { |type| send(type, &block) }
0
+ if args.any?
0
+ args.each { |type| send(type, &block) }
0
+ else
0
+ custom(@mime_type_priority.first, &block)
0
+ end
0
       end
0
 
0
       def method_missing(symbol, &block)
...
107
108
109
 
 
 
 
 
 
 
110
111
112
...
335
336
337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
339
340
...
107
108
109
110
111
112
113
114
115
116
117
118
119
...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
0
@@ -107,6 +107,13 @@ class RespondToController < ActionController::Base
0
       type.any(:js, :xml) { render :text => "Either JS or XML" }
0
     end
0
   end
0
+
0
+ def handle_any_any
0
+ respond_to do |type|
0
+ type.html { render :text => 'HTML' }
0
+ type.any { render :text => 'Whatever you ask for, I got it' }
0
+ end
0
+ end
0
 
0
   def all_types_with_layout
0
     respond_to do |type|
0
@@ -335,6 +342,35 @@ class MimeControllerTest < Test::Unit::TestCase
0
     assert_equal 'Either JS or XML', @response.body
0
   end
0
 
0
+ def test_handle_any_any
0
+ @request.env["HTTP_ACCEPT"] = "*/*"
0
+ get :handle_any_any
0
+ assert_equal 'HTML', @response.body
0
+ end
0
+
0
+ def test_handle_any_any_parameter_format
0
+ get :handle_any_any, {:format=>'html'}
0
+ assert_equal 'HTML', @response.body
0
+ end
0
+
0
+ def test_handle_any_any_explicit_html
0
+ @request.env["HTTP_ACCEPT"] = "text/html"
0
+ get :handle_any_any
0
+ assert_equal 'HTML', @response.body
0
+ end
0
+
0
+ def test_handle_any_any_javascript
0
+ @request.env["HTTP_ACCEPT"] = "text/javascript"
0
+ get :handle_any_any
0
+ assert_equal 'Whatever you ask for, I got it', @response.body
0
+ end
0
+
0
+ def test_handle_any_any_xml
0
+ @request.env["HTTP_ACCEPT"] = "text/xml"
0
+ get :handle_any_any
0
+ assert_equal 'Whatever you ask for, I got it', @response.body
0
+ end
0
+
0
   def test_rjs_type_skips_layout
0
     @request.env["HTTP_ACCEPT"] = "text/javascript"
0
     get :all_types_with_layout

Comments

    No one has commented yet.