Skip to content

Commit

Permalink
Merge pull request #7713 from porras/action-dispatch-upload-delegates…
Browse files Browse the repository at this point in the history
…-close-to-tempfile

Delegate ActionDispatch::Http::UploadedFile#close to tempfile
  • Loading branch information
fxn committed Sep 22, 2012
2 parents 19fa8fa + e9ba548 commit 40b5711
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,6 @@
* `ActionView::Helpers::TextHelper#highlight` now defaults to the
HTML5 `mark` element. *Brian Cardarella*

* `ActionDispatch::Http::UploadedFile` now delegates `close` to its tempfile. *Sergio Gil*

Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionpack/CHANGELOG.md) for previous changes.
8 changes: 2 additions & 6 deletions actionpack/lib/action_dispatch/http/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ def initialize(hash)
@headers = hash[:head]
end

def read(*args)
@tempfile.read(*args)
end

# Delegate these methods to the tempfile.
[:open, :path, :rewind, :size, :eof?].each do |method|
class_eval "def #{method}; @tempfile.#{method}; end"
[:read, :open, :close, :path, :rewind, :size, :eof?].each do |method|
class_eval "def #{method}(*args); @tempfile.#{method}(*args); end"
end

private
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/dispatch/uploaded_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def test_delegates_open_to_tempfile
assert_equal 'thunderhorse', uf.open
end

def test_delegates_close_to_tempfile
tf = Class.new { def close; 'thunderhorse' end }
uf = Http::UploadedFile.new(:tempfile => tf.new)
assert_equal 'thunderhorse', uf.close
end

def test_close_accepts_parameter
tf = Class.new { def close(optional = false); "thunderhorse: #{optional}" end }
uf = Http::UploadedFile.new(:tempfile => tf.new)
assert_equal 'thunderhorse: true', uf.close(true)
end

def test_delegates_to_tempfile
tf = Class.new { def read; 'thunderhorse' end }
uf = Http::UploadedFile.new(:tempfile => tf.new)
Expand Down

0 comments on commit 40b5711

Please sign in to comment.