Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    107107      type.any(:js, :xml) { render :text => "Either JS or XML" } 
    108108    end 
    109109  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 
    110117 
    111118  def all_types_with_layout 
    112119    respond_to do |type| 
     
    335342    assert_equal 'Either JS or XML', @response.body 
    336343  end 
    337344 
     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 
    338374  def test_rjs_type_skips_layout 
    339375    @request.env["HTTP_ACCEPT"] = "text/javascript" 
    340376    get :all_types_with_layout 
  • actionpack/lib/action_controller/mime_responds.rb

    old new  
    125125 
    126126        @order << mime_type 
    127127 
    128         @responses[mime_type] = Proc.new do 
     128        @responses[mime_type] ||= Proc.new do 
    129129          @response.template.template_format = mime_type.to_sym 
    130130          @response.content_type = mime_type.to_s 
    131131          block_given? ? block.call : @controller.send(:render, :action => @controller.action_name) 
     
    133133      end 
    134134 
    135135      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 
    137141      end 
    138142 
    139143      def method_missing(symbol, &block)