Permalink
Browse files

Added TestRequest#raw_post that simulate raw_post from CgiRequest (cl…

…oses #3042) [francois.beausoleil@gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3888 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Mar 16, 2006
1 parent c3c69d9 commit 275ea6de499c009e51fbe4c1abcfa4f50bdfeb12
Showing with 29 additions and 0 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +10 −0 actionpack/lib/action_controller/test_process.rb
  3. +17 −0 actionpack/test/controller/test_test.rb
View
@@ -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]
@@ -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
@@ -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']

0 comments on commit 275ea6d

Please sign in to comment.