Ticket #11140: mime_responds2.diff
| File mime_responds2.diff, 2.5 kB (added by jaw6, 7 months ago) |
|---|
-
actionpack/test/controller/mime_responds_test.rb
old new 107 107 type.any(:js, :xml) { render :text => "Either JS or XML" } 108 108 end 109 109 end 110 111 def handle_any_any 112 respond_to do |type| 113 type.html { render :text => 'HTML' } 114 type.any { render :text => 'Whatever you ask for, I got it' } 115 end 116 end 110 117 111 118 def all_types_with_layout 112 119 respond_to do |type| … … 335 342 assert_equal 'Either JS or XML', @response.body 336 343 end 337 344 345 def test_handle_any_any 346 @request.env["HTTP_ACCEPT"] = "*/*" 347 get :handle_any_any 348 assert_equal 'HTML', @response.body 349 end 350 351 def test_handle_any_any_parameter_format 352 get :handle_any_any, {:format=>'html'} 353 assert_equal 'HTML', @response.body 354 end 355 356 def test_handle_any_any_explicit_html 357 @request.env["HTTP_ACCEPT"] = "text/html" 358 get :handle_any_any 359 assert_equal 'HTML', @response.body 360 end 361 362 def test_handle_any_any_javascript 363 @request.env["HTTP_ACCEPT"] = "text/javascript" 364 get :handle_any_any 365 assert_equal 'Whatever you ask for, I got it', @response.body 366 end 367 368 def test_handle_any_any_xml 369 @request.env["HTTP_ACCEPT"] = "text/xml" 370 get :handle_any_any 371 assert_equal 'Whatever you ask for, I got it', @response.body 372 end 373 338 374 def test_rjs_type_skips_layout 339 375 @request.env["HTTP_ACCEPT"] = "text/javascript" 340 376 get :all_types_with_layout -
actionpack/lib/action_controller/mime_responds.rb
old new 125 125 126 126 @order << mime_type 127 127 128 @responses[mime_type] = Proc.new do128 @responses[mime_type] ||= Proc.new do 129 129 @response.template.template_format = mime_type.to_sym 130 130 @response.content_type = mime_type.to_s 131 131 block_given? ? block.call : @controller.send(:render, :action => @controller.action_name) … … 133 133 end 134 134 135 135 def any(*args, &block) 136 args.each { |type| send(type, &block) } 136 if args.any? 137 args.each { |type| send(type, &block) } 138 else 139 custom(@mime_type_priority.first, &block) 140 end 137 141 end 138 142 139 143 def method_missing(symbol, &block)