From dab08597417d55a1e9819781427aa2097ecdf2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Gil=20P=C3=A9rez=20de=20la=20Manga?= Date: Thu, 20 Sep 2012 11:57:38 +0200 Subject: Delegate ActionDispatch::Http::UploadedFile#close to tempfile --- actionpack/lib/action_dispatch/http/upload.rb | 2 +- actionpack/test/dispatch/uploaded_file_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index ce8c2729e9..42da35edec 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -17,7 +17,7 @@ module ActionDispatch end # Delegate these methods to the tempfile. - [:open, :path, :rewind, :size, :eof?].each do |method| + [:open, :close, :path, :rewind, :size, :eof?].each do |method| class_eval "def #{method}; @tempfile.#{method}; end" end diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index e69c1fbed4..c921a16a4f 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -45,6 +45,12 @@ module ActionDispatch 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_delegates_to_tempfile tf = Class.new { def read; 'thunderhorse' end } uf = Http::UploadedFile.new(:tempfile => tf.new) -- cgit v1.2.3 From f3afaa64cf13f15b2a6199d1be8fa4ce9f3fd612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Gil=20P=C3=A9rez=20de=20la=20Manga?= Date: Fri, 21 Sep 2012 08:34:05 +0200 Subject: Update CHANGELOG.md --- actionpack/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 9f0f214137..c5007828c2 100644 --- a/actionpack/CHANGELOG.md +++ b/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. -- cgit v1.2.3 From e9ba548baf74cc3a5ec65135dac385d81e14f06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Gil=20P=C3=A9rez=20de=20la=20Manga?= Date: Sat, 22 Sep 2012 22:37:00 +0200 Subject: Accept parameters in methods delegated to tempfile --- actionpack/lib/action_dispatch/http/upload.rb | 8 ++------ actionpack/test/dispatch/uploaded_file_test.rb | 6 ++++++ 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index 42da35edec..d50c8cad17 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -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 diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index c921a16a4f..f72afe745c 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -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) -- cgit v1.2.3