diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2011-05-02 19:21:03 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-05-02 19:21:03 -0500 |
commit | b359f9fe7cc3f664e145fae7b0d5b5c309587ef8 (patch) | |
tree | 386bac9ca264c2355741ba967334030f518b73fa /actionpack/test/dispatch/request/json_params_parsing_test.rb | |
parent | b29a905f949dbed5052c55184bd5e0838517ec8d (diff) | |
parent | 35d0d82ae3edf8fe959624999c858a63b2b4ed52 (diff) | |
download | rails-b359f9fe7cc3f664e145fae7b0d5b5c309587ef8.tar.gz rails-b359f9fe7cc3f664e145fae7b0d5b5c309587ef8.tar.bz2 rails-b359f9fe7cc3f664e145fae7b0d5b5c309587ef8.zip |
Merge branch 'master' of github.com:rails/rails
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 |