diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-15 22:10:03 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-15 22:10:03 +0000 |
commit | f73e1c2ec0711782870b7935da84b40596ad3577 (patch) | |
tree | 5f63f0663938316398b10bd82ad41056ef7779ec /actionpack/test/controller | |
parent | 6d3dc90c33861d7fa8f12e74f18f3c71ac064b65 (diff) | |
download | rails-f73e1c2ec0711782870b7935da84b40596ad3577.tar.gz rails-f73e1c2ec0711782870b7935da84b40596ad3577.tar.bz2 rails-f73e1c2ec0711782870b7935da84b40596ad3577.zip |
Move request parameter parsing from CGI to AbstractRequest.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6742 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rwxr-xr-x | actionpack/test/controller/cgi_test.rb | 35 | ||||
-rw-r--r-- | actionpack/test/controller/request_test.rb | 36 |
2 files changed, 37 insertions, 34 deletions
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 = - "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar></person>" - 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 = - "<person><name>David</name><avatars>" + - "<avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar>" + - "<avatar type='file' name='you.gif' content_type='image/gif'>#{Base64.encode64('DEF')}</avatar>" + - "</avatars></person>" - 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 = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar></person>" + + 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 + <person> + <name>David</name> + <avatars> + <avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar> + <avatar type='file' name='you.gif' content_type='image/gif'>#{Base64.encode64('DEF')}</avatar> + </avatars> + </person> + 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 + |