From f73e1c2ec0711782870b7935da84b40596ad3577 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 15 May 2007 22:10:03 +0000 Subject: Move request parameter parsing from CGI to AbstractRequest. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6742 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/cgi_test.rb | 35 +---------------------------- actionpack/test/controller/request_test.rb | 36 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 34 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index 877423a0d1..b8535548b7 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -274,35 +274,6 @@ class CGITest < Test::Unit::TestCase end -class XmlCGITest < Test::Unit::TestCase - def test_single_file - raw_post_data = - "David#{Base64.encode64('ABC')}" - person = CGI.parse_formatted_request_parameters(Mime::XML, raw_post_data) - assert_equal "image/jpg", person['person']['avatar'].content_type - assert_equal "me.jpg", person['person']['avatar'].original_filename - assert_equal "ABC", person['person']['avatar'].read - end - - def test_multiple_files - raw_post_data = - "David" + - "#{Base64.encode64('ABC')}" + - "#{Base64.encode64('DEF')}" + - "" - person = CGI.parse_formatted_request_parameters(Mime::XML, raw_post_data) - - assert_equal "image/jpg", person['person']['avatars']['avatar'].first.content_type - assert_equal "me.jpg", person['person']['avatars']['avatar'].first.original_filename - assert_equal "ABC", person['person']['avatars']['avatar'].first.read - - assert_equal "image/gif", person['person']['avatars']['avatar'].last.content_type - assert_equal "you.gif", person['person']['avatars']['avatar'].last.original_filename - assert_equal "DEF", person['person']['avatars']['avatar'].last.read - end -end - - class MultipartCGITest < Test::Unit::TestCase FIXTURE_PATH = File.dirname(__FILE__) + '/../fixtures/multipart' @@ -379,15 +350,11 @@ class MultipartCGITest < Test::Unit::TestCase private def process(name) - old_stdin = $stdin File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| ENV['CONTENT_LENGTH'] = file.stat.size.to_s - $stdin = file - @cgi = CGI.new + @cgi = CGI.new('query', file) CGI.parse_request_parameters @cgi.params end - ensure - $stdin = old_stdin end end diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index b939f6f975..9da2cf485f 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -355,3 +355,39 @@ class RequestTest < Test::Unit::TestCase @request.instance_eval { @request_method = nil } end end + + +class RequestParameterParsingTest < Test::Unit::TestCase + def test_xml_with_single_file + body = "David#{Base64.encode64('ABC')}" + + person = ActionController::AbstractRequest.parse_formatted_request_parameters(Mime::XML, body) + + assert_equal "image/jpg", person['person']['avatar'].content_type + assert_equal "me.jpg", person['person']['avatar'].original_filename + assert_equal "ABC", person['person']['avatar'].read + end + + def test_xml_with_multiple_files + body = <<-end_body + + David + + #{Base64.encode64('ABC')} + #{Base64.encode64('DEF')} + + + end_body + + person = ActionController::AbstractRequest.parse_formatted_request_parameters(Mime::XML, body) + + assert_equal "image/jpg", person['person']['avatars']['avatar'].first.content_type + assert_equal "me.jpg", person['person']['avatars']['avatar'].first.original_filename + assert_equal "ABC", person['person']['avatars']['avatar'].first.read + + assert_equal "image/gif", person['person']['avatars']['avatar'].last.content_type + assert_equal "you.gif", person['person']['avatars']['avatar'].last.original_filename + assert_equal "DEF", person['person']['avatars']['avatar'].last.read + end +end + -- cgit v1.2.3