diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-25 17:25:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-25 17:25:44 +0000 |
commit | 6a85955642606aa3159ea8e4d24fbc77a1fc5e94 (patch) | |
tree | 616c37e17c1b14fbece4a319fc41ee63dba78072 /actionpack | |
parent | 54bc5ca8d97b7ef8640686e50168ba25d7f23d27 (diff) | |
download | rails-6a85955642606aa3159ea8e4d24fbc77a1fc5e94.tar.gz rails-6a85955642606aa3159ea8e4d24fbc77a1fc5e94.tar.bz2 rails-6a85955642606aa3159ea8e4d24fbc77a1fc5e94.zip |
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
Diffstat (limited to 'actionpack')
-rwxr-xr-x | actionpack/test/controller/cgi_test.rb | 30 |
1 files changed, 29 insertions, 1 deletions
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 = + "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar></person>" + 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 = + "<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 = 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' |