From 4d594cffcfc93b37fad4e423ec8593299e50133c Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Tue, 8 Apr 2008 05:05:54 +0000 Subject: Automatically parse posted JSON content for Mime::JSON requests. [rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9242 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/request_test.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 6916e13417..82ddfec8e8 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -851,8 +851,13 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase end end - class XmlParamsParsingTest < Test::Unit::TestCase + def test_hash_params + person = parse_body("David")[:person] + assert_kind_of Hash, person + assert_equal 'David', person['name'] + end + def test_single_file person = parse_body("David#{ActiveSupport::Base64.encode64('ABC')}") @@ -899,3 +904,19 @@ class LegacyXmlParamsParsingTest < XmlParamsParsingTest ActionController::CgiRequest.new(cgi).request_parameters end end + +class JsonParamsParsingTest < Test::Unit::TestCase + def test_hash_params + person = parse_body({:person => {:name => "David"}}.to_json)[:person] + assert_kind_of Hash, person + assert_equal 'David', person['name'] + end + + private + def parse_body(body) + env = { 'CONTENT_TYPE' => 'application/json', + 'CONTENT_LENGTH' => body.size.to_s } + cgi = ActionController::Integration::Session::StubCGI.new(env, body) + ActionController::CgiRequest.new(cgi).request_parameters + end +end -- cgit v1.2.3