1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Accept parameters in methods delegated to tempfile

This commit is contained in:
Sergio Gil Pérez de la Manga 2012-09-22 22:37:00 +02:00
parent f3afaa64cf
commit e9ba548baf
2 changed files with 8 additions and 6 deletions

View file

@ -12,13 +12,9 @@ module ActionDispatch
@headers = hash[:head]
end
def read(*args)
@tempfile.read(*args)
end
# Delegate these methods to the tempfile.
[:open, :close, :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 file

@ -51,6 +51,12 @@ module ActionDispatch
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)