diff options
author | Rick Olson <technoweenie@gmail.com> | 2008-04-08 05:05:54 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2008-04-08 05:05:54 +0000 |
commit | 4d594cffcfc93b37fad4e423ec8593299e50133c (patch) | |
tree | 59643ee7a1eec4e3208f81f6e344a66207f648ec /actionpack/test/controller | |
parent | 0ff7a2d89fc95dcb0a32ed92aab7156b0778a7ea (diff) | |
download | rails-4d594cffcfc93b37fad4e423ec8593299e50133c.tar.gz rails-4d594cffcfc93b37fad4e423ec8593299e50133c.tar.bz2 rails-4d594cffcfc93b37fad4e423ec8593299e50133c.zip |
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
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/request_test.rb | 23 |
1 files changed, 22 insertions, 1 deletions
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("<person><name>David</name></person>")[:person] + assert_kind_of Hash, person + assert_equal 'David', person['name'] + end + def test_single_file person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>") @@ -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 |