summary refs log tree commit
diff options
context:
space:
mode:
authorKonstantin Haase <konstantin.mailinglists@googlemail.com>2014-10-02 21:29:17 +0200
committerKonstantin Haase <konstantin.mailinglists@googlemail.com>2014-10-02 21:29:17 +0200
commit022b0076b0eacad03eac48060198f05aa776a866 (patch)
tree080c124d7779562441bb02f0c984a47c5dd23f95
parentab172af1b63f0d8e91ce579dd2907c43b96cf82a (diff)
parenta9c0e350170420bc051b319792bde54755ba0a99 (diff)
downloadrack-022b0076b0eacad03eac48060198f05aa776a866.tar.gz
Merge pull request #739 from schneems/schneems/fix-respond_to
Fix: `respond_to?` takes 2 arguments
-rw-r--r--lib/rack/body_proxy.rb11
-rw-r--r--test/spec_body_proxy.rb16
2 files changed, 19 insertions, 8 deletions
diff --git a/lib/rack/body_proxy.rb b/lib/rack/body_proxy.rb
index b35167c8..95a74626 100644
--- a/lib/rack/body_proxy.rb
+++ b/lib/rack/body_proxy.rb
@@ -4,14 +4,9 @@ module Rack
       @body, @block, @closed = body, block, false
     end
 
-    def respond_to?(method_name)
-      case method_name
-      when :to_ary
-        return false
-      when String
-        return false if /^to_ary$/ =~ method_name
-      end
-      super or @body.respond_to?(method_name)
+    def respond_to?(*args)
+      return false if args.first.to_s =~ /^to_ary$/
+      super or @body.respond_to?(*args)
     end
 
     def close
diff --git a/test/spec_body_proxy.rb b/test/spec_body_proxy.rb
index c65e10d2..8b6e6a5e 100644
--- a/test/spec_body_proxy.rb
+++ b/test/spec_body_proxy.rb
@@ -1,5 +1,6 @@
 require 'rack/body_proxy'
 require 'stringio'
+require 'ostruct'
 
 describe Rack::BodyProxy do
   should 'call each on the wrapped body' do
@@ -49,6 +50,21 @@ describe Rack::BodyProxy do
     called.should.equal true
   end
 
+  should 'allow multiple arguments in respond_to?' do
+    body  = []
+    proxy = Rack::BodyProxy.new(body) { }
+    proc { proxy.respond_to?(:foo, false) }.should.not.raise
+  end
+
+  should 'not respond to :to_ary' do
+    body = OpenStruct.new(:to_ary => true)
+    body.respond_to?(:to_ary).should.equal true
+
+    proxy = Rack::BodyProxy.new(body) { }
+    proxy.respond_to?(:to_ary).should.equal false
+    proxy.respond_to?("to_ary").should.equal false
+  end
+
   should 'not close more than one time' do
     count = 0
     proxy = Rack::BodyProxy.new([]) { count += 1; raise "Block invoked more than 1 time!" if count > 1 }