Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7713 from porras/action-dispatch-upload-delegates…

…-close-to-tempfile

Delegate ActionDispatch::Http::UploadedFile#close to tempfile
  • Loading branch information...
commit 40b57116975cafdd9f81a49a7bc757809f4465f8 2 parents 19fa8fa + e9ba548
@fxn fxn authored
View
2  actionpack/CHANGELOG.md
@@ -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.
View
8 actionpack/lib/action_dispatch/http/upload.rb
@@ -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
View
12 actionpack/test/dispatch/uploaded_file_test.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.