aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/request
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch/request')
-rw-r--r--actionpack/test/dispatch/request/json_params_parsing_test.rb53
-rw-r--r--actionpack/test/dispatch/request/xml_params_parsing_test.rb38
2 files changed, 91 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
diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
index ad9de02eb4..38453dfe48 100644
--- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -115,3 +115,41 @@ class LegacyXmlParamsParsingTest < XmlParamsParsingTest
{'HTTP_X_POST_DATA_FORMAT' => 'xml'}
end
end
+
+class RootLessXmlParamsParsingTest < ActionDispatch::IntegrationTest
+ class TestController < ActionController::Base
+ wrap_parameters :person, :format => :xml
+
+ class << self
+ attr_accessor :last_request_parameters
+ end
+
+ def parse
+ self.class.last_request_parameters = request.request_parameters
+ head :ok
+ end
+ end
+
+ def teardown
+ TestController.last_request_parameters = nil
+ end
+
+ test "parses hash params" do
+ with_test_routing do
+ xml = "<name>David</name>"
+ post "/parse", xml, {'CONTENT_TYPE' => 'application/xml'}
+ assert_response :ok
+ assert_equal({"name" => "David", "person" => {"name" => "David"}}, TestController.last_request_parameters)
+ end
+ end
+
+ private
+ def with_test_routing
+ with_routing do |set|
+ set.draw do
+ match ':action', :to => ::RootLessXmlParamsParsingTest::TestController
+ end
+ yield
+ end
+ end
+end