From e8a905d14bf4adbc99553a04365cc7ca5a88f26b Mon Sep 17 00:00:00 2001 From: Jack Xu Date: Fri, 25 Sep 2015 12:59:36 -0400 Subject: caches the #to_app value in call method --- lib/rack/builder.rb | 2 +- test/spec_builder.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3-24-ge0c7