Permalink
Browse files

Provide interface for accessing underlying IO object

In some cases users may need to work with/manipulate more of the
Tempfile api than provided by Upload. Allow users to get at the
underlying io via the common to_io method of IO/IO-like objects
  • Loading branch information...
1 parent 43f5250 commit e601728dceb779b6b2aae800c66eb8b3f20f9aaa @timlinquist timlinquist committed Apr 15, 2014
Showing with 11 additions and 0 deletions.
  1. +5 −0 actionpack/lib/action_dispatch/http/upload.rb
  2. +6 −0 actionpack/test/dispatch/uploaded_file_test.rb
@@ -31,6 +31,11 @@ def initialize(hash) # :nodoc:
@headers = hash[:head]
end
+ # Shortcut for working directly with +tempfile+
+ def to_io
+ @tempfile
+ end
+
# Shortcut for +tempfile.read+.
def read(length=nil, buffer=nil)
@tempfile.read(length, buffer)
@@ -33,6 +33,12 @@ def test_tempfile
assert_equal 'foo', uf.tempfile
end
+ def test_delegates_to_io_to_tempfile
+ tf = Object.new
+ uf = Http::UploadedFile.new(:tempfile => tf)
+ assert_equal tf, uf.to_io
+ end
+
def test_delegates_path_to_tempfile
tf = Class.new { def path; 'thunderhorse' end }
uf = Http::UploadedFile.new(:tempfile => tf.new)

0 comments on commit e601728

Please sign in to comment.