Permalink
Browse files

making sure respond_to? works properly

  • Loading branch information...
1 parent d752447 commit fc9e9ed406d1c4f9c231f48aa2418fa21fcc42b6 @tenderlove tenderlove committed Oct 5, 2010
Showing with 20 additions and 0 deletions.
  1. +5 −0 actionpack/lib/action_dispatch/http/upload.rb
  2. +15 −0 actionpack/test/dispatch/uploaded_file_test.rb
@@ -13,7 +13,12 @@ def initialize(hash)
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
@@ -45,5 +45,20 @@ def test_delegates_to_tempfile_with_block
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

0 comments on commit fc9e9ed

Please sign in to comment.