diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-05-08 03:54:55 +0100 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-05-08 03:54:55 +0100 |
commit | aec7456f81985b88d6d604679d754636183b5b3a (patch) | |
tree | 798fcab8ae0c6e2c8c5a63e1f39308ff4bb5a20c /actionpack/test/dispatch/request/json_params_parsing_test.rb | |
parent | 1c2b2233c3a7ec76c0a0eddf5b8be45c489be133 (diff) | |
parent | 70f9558d0e4b8e605576693cbb489caa5cf6a2bc (diff) | |
download | rails-aec7456f81985b88d6d604679d754636183b5b3a.tar.gz rails-aec7456f81985b88d6d604679d754636183b5b3a.tar.bz2 rails-aec7456f81985b88d6d604679d754636183b5b3a.zip |
Merge branch 'master' of https://github.com/rails/rails into performance_test
Conflicts:
activesupport/lib/active_support/testing/performance.rb
Diffstat (limited to 'actionpack/test/dispatch/request/json_params_parsing_test.rb')
-rw-r--r-- | actionpack/test/dispatch/request/json_params_parsing_test.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index 34db7a4c66..d854d55173 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -63,3 +63,56 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest end end end + +class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest + class UsersController < ActionController::Base + wrap_parameters :format => :json + + class << self + attr_accessor :last_request_parameters, :last_parameters + end + + def parse + self.class.last_request_parameters = request.request_parameters + self.class.last_parameters = params + head :ok + end + end + + def teardown + UsersController.last_request_parameters = nil + end + + test "parses json params for application json" do + assert_parses( + {"user" => {"username" => "sikachu"}, "username" => "sikachu"}, + "{\"username\": \"sikachu\"}", { 'CONTENT_TYPE' => 'application/json' } + ) + end + + test "parses json params for application jsonrequest" do + assert_parses( + {"user" => {"username" => "sikachu"}, "username" => "sikachu"}, + "{\"username\": \"sikachu\"}", { 'CONTENT_TYPE' => 'application/jsonrequest' } + ) + end + + private + def assert_parses(expected, actual, headers = {}) + with_test_routing(UsersController) do + post "/parse", actual, headers + assert_response :ok + assert_equal(expected, UsersController.last_request_parameters) + assert_equal(expected.merge({"action" => "parse"}), UsersController.last_parameters) + end + end + + def with_test_routing(controller) + with_routing do |set| + set.draw do + match ':action', :to => controller + end + yield + end + end +end |