Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
04/08/08 05:05:54 (8 months ago)
Author:
rick
Message:

Automatically parse posted JSON content for Mime::JSON requests. [rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/test/controller/request_test.rb

    r9194 r9242  
    852852end 
    853853 
    854  
    855854class XmlParamsParsingTest < Test::Unit::TestCase 
     855  def test_hash_params 
     856    person = parse_body("<person><name>David</name></person>")[:person] 
     857    assert_kind_of Hash, person 
     858    assert_equal 'David', person['name'] 
     859  end 
     860 
    856861  def test_single_file 
    857862    person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>") 
     
    900905    end 
    901906end 
     907 
     908class JsonParamsParsingTest < Test::Unit::TestCase 
     909  def test_hash_params 
     910    person = parse_body({:person => {:name => "David"}}.to_json)[:person] 
     911    assert_kind_of Hash, person 
     912    assert_equal 'David', person['name'] 
     913  end 
     914 
     915  private 
     916    def parse_body(body) 
     917      env = { 'CONTENT_TYPE'   => 'application/json', 
     918              'CONTENT_LENGTH' => body.size.to_s } 
     919      cgi = ActionController::Integration::Session::StubCGI.new(env, body) 
     920      ActionController::CgiRequest.new(cgi).request_parameters 
     921    end 
     922end