Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/rack/test/uploaded_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def method_missing(method_name, *args, &block)
def append_to(buffer)
tempfile.rewind

buf = String.new
buffer << tempfile.readpartial(65_536, buf) until tempfile.eof?

tempfile.rewind

nil
begin
buf = String.new
buffer << tempfile.readpartial(65_536, buf) until tempfile.eof?
nil
ensure
tempfile.rewind
end
end

def respond_to_missing?(method_name, include_private = false) #:nodoc:
Expand Down
14 changes: 14 additions & 0 deletions spec/rack/test/uploaded_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ def file_path
File.dirname(__FILE__) + '/../../fixtures/foo.txt'
end

it 'rewinds after appending raises' do
uploaded_file = Rack::Test::UploadedFile.new(
StringIO.new('content'),
original_filename: 'content.txt'
)
buffer = Object.new
def buffer.<<(_chunk)
raise IOError, 'append failed'
end

proc { uploaded_file.append_to(buffer) }.must_raise(IOError)
uploaded_file.pos.must_equal 0
end

it 'returns an instance of `Rack::Test::UploadedFile`' do
uploaded_file = Rack::Test::UploadedFile.new(file_path)

Expand Down