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

Changeset 3843

Show
Ignore:
Timestamp:
03/12/06 05:13:55 (2 years ago)
Author:
david
Message:

Assume that we accept what we give [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/mime_type.rb

    r3838 r3843  
    4040  XML        = Type.new "application/xml" 
    4141  RSS        = Type.new "application/rss+xml" 
    42   ATOM       = Type.new "application/rss+atom
     42  ATOM       = Type.new "application/atom+xml
    4343  YAML       = Type.new "application/x-yaml" 
    4444end 
  • trunk/actionpack/lib/action_controller/request.rb

    r3838 r3843  
    5252 
    5353      @content_type = @env['CONTENT_TYPE'].to_s.downcase 
    54        
     54 
    5555      if @env['HTTP_X_POST_DATA_FORMAT']           
    5656        case @env['HTTP_X_POST_DATA_FORMAT'].downcase.to_sym 
     
    6666 
    6767    def accepts 
    68       @accepts ||= (@env['HTTP_ACCEPT'].strip.blank? ? "*/*" : @env['HTTP_ACCEPT']).split(";").collect! do |mime_type|  
    69         Mime::Type.new(mime_type.strip) 
     68      return @accepts if @accepts 
     69       
     70      @accepts = if @env['HTTP_ACCEPT'].to_s.strip.blank? 
     71        [ content_type, Mime::ALL ] 
     72      else 
     73        @env['HTTP_ACCEPT'].split(";").collect! do |mime_type| 
     74          Mime::Type.new(mime_type.strip) 
     75        end 
    7076      end 
    7177    end 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r3842 r3843  
    4646      type.html 
    4747      type.xml(person_in_xml) 
     48    end 
     49  end 
     50 
     51  def made_for_content_type 
     52    respond_to do |type| 
     53      type.rss  { render :text => "RSS"  } 
     54      type.atom { render :text => "ATOM" } 
     55      type.all  { render :text => "Nothing" } 
    4856    end 
    4957  end 
     
    138146    assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n  <name>David</name>\n</person>\n", @response.body 
    139147  end 
     148   
     149  def test_with_content_type 
     150    @request.env["CONTENT_TYPE"] = "application/atom+xml" 
     151    get :made_for_content_type 
     152    assert_equal "ATOM", @response.body 
     153 
     154    @request.env["CONTENT_TYPE"] = "application/rss+xml" 
     155    get :made_for_content_type 
     156    assert_equal "RSS", @response.body 
     157  end 
    140158end