summary refs log tree commit
diff options
context:
space:
mode:
authorJack Xu <Jack_Xu@cable.comcast.com>2015-09-25 12:59:36 -0400
committerJack Xu <Jack_Xu@cable.comcast.com>2015-09-25 12:59:36 -0400
commite8a905d14bf4adbc99553a04365cc7ca5a88f26b (patch)
treecce4348ab4542584af6e1faeb335a3d683d1584b
parent817ad5150c1d9d162c411f8dc636754cededa2af (diff)
downloadrack-e8a905d14bf4adbc99553a04365cc7ca5a88f26b.tar.gz
caches the #to_app value in call method
-rw-r--r--lib/rack/builder.rb2
-rw-r--r--test/spec_builder.rb13
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/rack/builder.rb b/lib/rack/builder.rb
index 975cf1e1..5250aff3 100644
--- a/lib/rack/builder.rb
+++ b/lib/rack/builder.rb
@@ -150,7 +150,7 @@ module Rack
     end
 
     def call(env)
-      to_app.call(env)
+      (@_app ||= to_app).call(env)
     end
 
     private
diff --git a/test/spec_builder.rb b/test/spec_builder.rb
index ae1c4006..cb0bbbd4 100644
--- a/test/spec_builder.rb
+++ b/test/spec_builder.rb
@@ -180,6 +180,19 @@ describe Rack::Builder do
     end.must_raise(RuntimeError)
   end
 
+  it "doesn't dupe #to_app when mapping" do
+    app = builder do
+      map '/' do |outer_env|
+        run lambda { |env|  [200, {"Content-Type" => "text/plain"}, [object_id.to_s]] }
+      end
+    end
+
+    builder_app1_id = Rack::MockRequest.new(app).get("/").body.to_s
+    builder_app2_id = Rack::MockRequest.new(app).get("/").body.to_s
+
+    assert_equal builder_app2_id, builder_app1_id
+  end
+
   describe "parse_file" do
     def config_file(name)
       File.join(File.dirname(__FILE__), 'builder', name)