summary refs log tree commit
diff options
context:
space:
mode:
-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 11f596bd..f11c66bc 100644
--- a/lib/rack/builder.rb
+++ b/lib/rack/builder.rb
@@ -157,7 +157,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 111d7b55..326f6b6c 100644
--- a/test/spec_builder.rb
+++ b/test/spec_builder.rb
@@ -201,6 +201,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)