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

Changeset 8987

Show
Ignore:
Timestamp:
03/07/08 11:17:05 (1 year ago)
Author:
pratik
Message:

Make MimeResponds::Responder#any work without explicit types. Closes #11140 [jaw6]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r8986 r8987  
    11*SVN* 
     2 
     3* Make MimeResponds::Responder#any work without explicit types. Closes #11140 [jaw6] 
    24 
    35* Better error message for type conflicts when parsing params.  Closes #7962 [spicycode, matt] 
  • trunk/actionpack/lib/action_controller/mime_responds.rb

    r8027 r8987  
    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 
     
    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 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r8683 r8987  
    106106      type.html { render :text => "HTML" } 
    107107      type.any(:js, :xml) { render :text => "Either JS or XML" } 
     108    end 
     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' } 
    108115    end 
    109116  end 
     
    334341    get :handle_any 
    335342    assert_equal 'Either JS or XML', @response.body 
     343  end 
     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 
    336372  end 
    337373