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

Changeset 5695

Show
Ignore:
Timestamp:
12/06/06 23:06:38 (2 years ago)
Author:
bitsweat
Message:

More thorough JSON tests. Use application/json by default, per rfc4627. References #4185.

Files:

Legend:

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

    r5694 r5695  
    33Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml ) 
    44Mime::Type.register "text/javascript", :js, %w( application/javascript application/x-javascript ) 
    5 Mime::Type.register "text/x-json", :json, %w( application/x-json ) 
    65Mime::Type.register "text/calendar", :ics 
    76Mime::Type.register "text/csv", :csv 
     
    109Mime::Type.register "application/atom+xml", :atom 
    1110Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml ) 
     11 
     12# http://www.ietf.org/rfc/rfc4627.txt 
     13Mime::Type.register "application/json", :json, %w( text/x-json ) 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r5694 r5695  
    171171    assert_response 406 
    172172  end 
    173    
     173 
    174174  def test_json_or_yaml 
    175175    get :json_or_yaml 
    176176    assert_equal 'JSON', @response.body 
    177      
    178     @request.env["HTTP_ACCEPT"] = "text/yaml" 
    179     get :json_or_yaml 
     177 
     178    get :json_or_yaml, :format => 'json' 
     179    assert_equal 'JSON', @response.body 
     180 
     181    get :json_or_yaml, :format => 'yaml' 
    180182    assert_equal 'YAML', @response.body 
    181      
    182     @request.env["HTTP_ACCEPT"] = "text/x-json" 
    183     get :json_or_yaml 
    184     assert_equal 'JSON', @response.body 
     183 
     184    { 'YAML' => %w(text/yaml), 
     185      'JSON' => %w(application/json text/x-json) 
     186    }.each do |body, content_types| 
     187      content_types.each do |content_type| 
     188        @request.env['HTTP_ACCEPT'] = content_type 
     189        get :json_or_yaml 
     190        assert_equal body, @response.body 
     191      end 
     192    end 
    185193  end 
    186194 
  • trunk/actionpack/test/controller/render_test.rb

    r5694 r5695  
    3939    render_text "hello world" 
    4040  end 
    41    
     41 
    4242  def render_json_hello_world 
    4343    render_json({:hello => 'world'}.to_json) 
    4444  end 
    45    
     45 
    4646  def render_json_hello_world_with_callback 
    4747    render_json({:hello => 'world'}.to_json, 'alert') 
     
    172172    assert_equal "hello world", @response.body 
    173173  end 
    174    
     174 
    175175  def test_do_with_render_json 
    176176    get :render_json_hello_world 
    177177    assert_equal '{hello: "world"}', @response.body 
    178   end 
    179    
     178    assert_equal 'application/json', @response.content_type 
     179  end 
     180 
    180181  def test_do_with_render_json_with_callback 
    181182    get :render_json_hello_world_with_callback 
    182183    assert_equal 'alert({hello: "world"})', @response.body 
     184    assert_equal 'application/json', @response.content_type 
    183185  end 
    184186