diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-04 17:11:50 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-04 17:11:50 -0700 |
commit | 3370ad0b1e883c9ec24c771f6c52b296a71eff40 (patch) | |
tree | a1180927a1d7595ae395820c695c792517dc43ea | |
parent | 8a9747021085c569f0118db1093bc12cfa2ba915 (diff) | |
download | rails-3370ad0b1e883c9ec24c771f6c52b296a71eff40.tar.gz rails-3370ad0b1e883c9ec24c771f6c52b296a71eff40.tar.bz2 rails-3370ad0b1e883c9ec24c771f6c52b296a71eff40.zip |
making sure respond_to? works properly
-rw-r--r-- | actionpack/lib/action_dispatch/http/upload.rb | 5 | ||||
-rw-r--r-- | actionpack/test/dispatch/uploaded_file_test.rb | 15 |
2 files changed, 20 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index d4fabe1eaf..53f8039121 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -13,7 +13,12 @@ module ActionDispatch raise(ArgumentError, ':tempfile is required') unless @tempfile end + def respond_to?(name) + super || @tempfile.respond_to?(name) + end + def method_missing(name, *args, &block) + return super unless respond_to?(name) @tempfile.send(name, *args, &block) end end diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index 4173ce0a44..c81797a73f 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -45,5 +45,20 @@ module ActionDispatch uf = Http::UploadedFile.new(:tempfile => tf.new) assert_equal('thunderhorse', uf.tenderlove { 'thunderhorse' }) end + + def test_delegate_respects_respond_to? + tf = Class.new { def tenderlove; yield end; private :tenderlove } + uf = Http::UploadedFile.new(:tempfile => tf.new) + assert_raises(NoMethodError) do + uf.tenderlove + end + end + + def test_respond_to? + tf = Class.new { def tenderlove; yield end } + uf = Http::UploadedFile.new(:tempfile => tf.new) + assert uf.respond_to?(:headers), 'responds to headers' + assert uf.respond_to?(:tenderlove), 'responds to tenderlove' + end end end |