diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 96eb8ac77dc5c97241ed53b6314dd57c0734ffe6..3b63e4b44c3d1e58d140b039f65e62bf68aa8163 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added TestRequest#raw_post that simulate raw_post from CgiRequest #3042 [francois.beausoleil@gmail.com] + * Underscore dasherized keys in formatted requests [Jamis Buck] * Add MimeResponds::Responder#any for managing multiple types with identical responses [Jamis Buck] diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 7dfc16785a6d57c924c5ec002cc5fefd7ee7fe15..85bcc7372db2aa70efff4bd171a7ecc33817ef27 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -41,7 +41,17 @@ def initialize(query_parameters = nil, request_parameters = nil, session = nil) def reset_session @session = {} end + + def raw_post + params = self.request_parameters.dup + %w(controller action only_path).each do |k| + params.delete(k) + params.delete(k.to_sym) + end + params.map { |k,v| [ CGI.escape(k.to_s), CGI.escape(v.to_s) ].join('=') }.sort.join('&') + end + def port=(number) @env["SERVER_PORT"] = number.to_i @port_as_int = nil diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index dcb16841aeb57243bb21b891a03c39732d2e148a..25c514d5a3bd12f1d814f5c0709928ef96ff8f4c 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -8,6 +8,11 @@ def set_flash render :text => 'ignore me' end + def render_raw_post + raise Test::Unit::AssertionFailedError, "#raw_post is blank" if request.raw_post.blank? + render :text => request.raw_post + end + def test_params render :text => params.inspect end @@ -44,6 +49,10 @@ def test_only_one_param def test_remote_addr render :text => (request.remote_addr || "not specified") end + + def rescue_action(e) + raise e + end end def setup @@ -57,6 +66,14 @@ def teardown ActionController::Routing::Routes.reload end + def test_raw_post_handling + params = {:page => {:name => 'page name'}, 'some key' => 123} + get :render_raw_post, params.dup + + raw_post = params.map {|k,v| [CGI::escape(k.to_s), CGI::escape(v.to_s)].join('=')}.sort.join('&') + assert_equal raw_post, @response.body + end + def test_process_without_flash process :set_flash assert_equal '><', flash['test']