Permalink
Browse files

Fixed Ruby 1.9.2 StringIO bug.

  • Loading branch information...
1 parent c1baab8 commit abb54501ecb43e554723c9fa2a814a19b6348bbe @arsduo committed May 13, 2011
Showing with 15 additions and 3 deletions.
  1. +3 −1 lib/composite_io.rb
  2. +1 −2 test/test_composite_io.rb
  3. +11 −0 test/test_upload_io.rb
View
@@ -66,7 +66,9 @@ def initialize(filename_or_io, content_type, filename = nil)
io = filename_or_io
local_path = ""
if io.respond_to? :read
- local_path = filename_or_io.path
+ # in Ruby 1.9.2, StringIOs no longer respond to path
+ # (since they respond to :length, so we don't need their local path, see parts.rb:41)
+ local_path = filename_or_io.respond_to?(:path) ? filename_or_io.path : "local.path"
else
io = File.open(filename_or_io)
local_path = filename_or_io
@@ -12,7 +12,7 @@ def test_full_read_from_several_ios
assert_equal 'the quick brown fox', @io.read
end
- unless RUBY_VERSION < '1.9'
+ unless RUBY_VERSION < '1.9'
def test_read_from_multibyte
utf8 = File.open(File.dirname(__FILE__)+'/multibyte.txt')
binary = StringIO.new("\x86")
@@ -21,7 +21,6 @@ def test_read_from_multibyte
end
end
-
def test_partial_read
assert_equal 'the quick', @io.read(9)
end
View
@@ -0,0 +1,11 @@
+require 'composite_io'
+require 'stringio'
+require 'test/unit'
+
+class UploadIOTest < Test::Unit::TestCase
+ if RUBY_VERSION >= '1.9'
+ def test_works_with_ruby_192_string_ios
+ assert_nothing_raised { UploadIO.new(StringIO.new, "test/content") }
+ end
+ end
+end

0 comments on commit abb5450

Please sign in to comment.