From 6a85955642606aa3159ea8e4d24fbc77a1fc5e94 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 25 Apr 2007 17:25:44 +0000 Subject: Added parsing of file type in Hash.xml_in so you can easily do file uploads with base64 from an API [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6578 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/cgi_test.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index d5c8ee0063..5be6cd2ea2 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/../abstract_unit' require 'action_controller/cgi_process' require 'action_controller/cgi_ext/cgi_ext' - require 'stringio' class CGITest < Test::Unit::TestCase @@ -278,6 +277,35 @@ class CGITest < Test::Unit::TestCase end +class XmlCGITest < Test::Unit::TestCase + def test_single_file + raw_post_data = + "David#{Base64.encode64('ABC')}" + person = CGIMethods.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 = CGIMethods.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' -- cgit v1.2.3