summary refs log tree commit
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2010-12-19 14:17:26 -0600
committerJoshua Peek <josh@joshpeek.com>2010-12-19 14:17:26 -0600
commit94cc9d909bd1eb0f29df209f88103c3667fbcb49 (patch)
treeffae184291244199331753a2395be476fae2d534
parent260fca3dd54d071bd0e69cd6a6381c979acc9f36 (diff)
downloadrack-94cc9d909bd1eb0f29df209f88103c3667fbcb49.tar.gz
Delegate lock proxy to_path
-rw-r--r--lib/rack/lock.rb8
-rw-r--r--test/spec_lock.rb26
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/rack/lock.rb b/lib/rack/lock.rb
index bfc86dd8..b5326a4f 100644
--- a/lib/rack/lock.rb
+++ b/lib/rack/lock.rb
@@ -12,6 +12,14 @@ module Rack
       ensure
         mutex.unlock
       end
+
+      def to_path
+        target.to_path
+      end
+
+      def respond_to?(sym)
+        sym.to_sym == :close || target.respond_to?(sym)
+      end
     end
 
     FLAG = 'rack.multithread'.freeze
diff --git a/test/spec_lock.rb b/test/spec_lock.rb
index 8386c5f2..64849096 100644
--- a/test/spec_lock.rb
+++ b/test/spec_lock.rb
@@ -39,6 +39,32 @@ describe Rack::Lock do
       response.each { |x| list << x }
       list.should.equal %w{ hi mom }
     end
+
+    should 'delegate to_path' do
+      lock = Lock.new
+      env  = Rack::MockRequest.env_for("/")
+
+      res = ['Hello World']
+      def res.to_path ; "/tmp/hello.txt" ; end
+
+      app = Rack::Lock.new(lambda { |inner_env| [200, {}, res] }, lock)
+      body = app.call(env)[2]
+
+      body.should.respond_to :to_path
+      body.to_path.should.equal "/tmp/hello.txt"
+    end
+
+    should 'not delegate to_path if body does not implement it' do
+      lock = Lock.new
+      env  = Rack::MockRequest.env_for("/")
+
+      res = ['Hello World']
+
+      app = Rack::Lock.new(lambda { |inner_env| [200, {}, res] }, lock)
+      body = app.call(env)[2]
+
+      body.should.not.respond_to :to_path
+    end
   end
 
   should 'call super on close' do