Merge pull request #7713 from porras/action-dispatch-upload-delegates-close-to-tempfile

Delegate ActionDispatch::Http::UploadedFile#close to tempfile
This commit is contained in:
Xavier Noria 2012-09-22 13:52:19 -07:00
commit 40b5711697
3 changed files with 16 additions and 6 deletions

@ -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.

@ -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

@ -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)