aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-09-26 17:59:46 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-09-26 17:59:46 +0000
commit9852197f83e19939951e700b51f806477ada2769 (patch)
tree5138179687466e0ba66661c829735f01b6d4885c /actionpack/test/controller
parenta68557952fd6caac526769beb699c7936cef001f (diff)
downloadrails-9852197f83e19939951e700b51f806477ada2769.tar.gz
rails-9852197f83e19939951e700b51f806477ada2769.tar.bz2
rails-9852197f83e19939951e700b51f806477ada2769.zip
r3573@asus: jeremy | 2005-09-26 11:38:44 -0700
Ticket 1507 - IE file uploads give the filename as a full Windows path, but Ruby on UNIX doesn't know how to File.basename('C:\\blah\blah.foo'). r3574@asus: jeremy | 2005-09-26 14:32:11 -0700 Get rid of constant redefine warning. r3575@asus: jeremy | 2005-09-26 14:33:07 -0700 Override the file upload's original_filename singleton method in CGIMethods.get_typed_value. r3576@asus: jeremy | 2005-09-26 14:33:49 -0700 Unit test overridden original_filename against normal filenames and full Windows paths. r3577@asus: jeremy | 2005-09-26 14:33:57 -0700 Update change log. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2345 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rwxr-xr-xactionpack/test/controller/cgi_test.rb51
1 files changed, 32 insertions, 19 deletions
diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb
index 74f4fc9e8b..a896128168 100755
--- a/actionpack/test/controller/cgi_test.rb
+++ b/actionpack/test/controller/cgi_test.rb
@@ -4,16 +4,6 @@ require 'test/unit'
require 'action_controller/cgi_ext/cgi_methods'
require 'stringio'
-class MockUploadedFile < StringIO
- def content_type
- "img/jpeg"
- end
-
- def original_filename
- "my_file.doc"
- end
-end
-
class CGITest < Test::Unit::TestCase
def setup
@query_string = "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1"
@@ -116,15 +106,20 @@ class CGITest < Test::Unit::TestCase
end
def test_parse_params_from_multipart_upload
- mock_file = MockUploadedFile.new
+ mockup = Struct.new(:content_type, :original_filename)
+ file = mockup.new('img/jpeg', 'foo.jpg')
+ ie_file = mockup.new('img/jpeg', 'c:\\Documents and Settings\\foo\\Desktop\\bar.jpg')
input = {
"something" => [ StringIO.new("") ],
"array_of_stringios" => [[ StringIO.new("One"), StringIO.new("Two") ]],
"mixed_types_array" => [[ StringIO.new("Three"), "NotStringIO" ]],
- "mixed_types_as_checkboxes[strings][nested]" => [[ mock_file, "String", StringIO.new("StringIO")]],
+ "mixed_types_as_checkboxes[strings][nested]" => [[ file, "String", StringIO.new("StringIO")]],
+ "ie_mixed_types_as_checkboxes[strings][nested]" => [[ ie_file, "String", StringIO.new("StringIO")]],
"products[string]" => [ StringIO.new("Apple Computer") ],
- "products[file]" => [ mock_file ]
+ "products[file]" => [ file ],
+ "ie_products[string]" => [ StringIO.new("Microsoft") ],
+ "ie_products[file]" => [ ie_file ]
}
expected_output = {
@@ -132,17 +127,35 @@ class CGITest < Test::Unit::TestCase
"array_of_stringios" => ["One", "Two"],
"mixed_types_array" => [ "Three", "NotStringIO" ],
"mixed_types_as_checkboxes" => {
- "strings"=> {
- "nested"=>[ mock_file, "String", "StringIO" ]
+ "strings" => {
+ "nested" => [ file, "String", "StringIO" ]
+ },
+ },
+ "ie_mixed_types_as_checkboxes" => {
+ "strings" => {
+ "nested" => [ ie_file, "String", "StringIO" ]
},
},
- "products" => {
- "string" => "Apple Computer",
- "file" => mock_file
+ "products" => {
+ "string" => "Apple Computer",
+ "file" => file
+ },
+ "ie_products" => {
+ "string" => "Microsoft",
+ "file" => ie_file
}
}
- assert_equal expected_output, CGIMethods.parse_request_parameters(input)
+ params = CGIMethods.parse_request_parameters(input)
+ assert_equal expected_output, params
+
+ # Lone filenames are preserved.
+ assert_equal 'foo.jpg', params['mixed_types_as_checkboxes']['strings']['nested'].first.original_filename
+ assert_equal 'foo.jpg', params['products']['file'].original_filename
+
+ # But full Windows paths are reduced to their basename.
+ assert_equal 'bar.jpg', params['ie_mixed_types_as_checkboxes']['strings']['nested'].first.original_filename
+ assert_equal 'bar.jpg', params['ie_products']['file'].original_filename
end
def test_parse_params_with_file