diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-11-06 16:55:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-06 16:55:33 -0500 |
commit | 2afc14627c9656004325ae17d028ebe7f7e73c0f (patch) | |
tree | 24b755208ac52073330aa9d1f513a747ce52deb7 | |
parent | 51356a65185d6c74f7e588ec468ad64ca3a49bcb (diff) | |
parent | e8a905d14bf4adbc99553a04365cc7ca5a88f26b (diff) | |
download | rack-2afc14627c9656004325ae17d028ebe7f7e73c0f.tar.gz |
Merge pull request #953 from jackxxu/cache-to-app-in-rack-builder
Avoid re-calculation in Rack::Builder call method
-rw-r--r-- | lib/rack/builder.rb | 2 | ||||
-rw-r--r-- | test/spec_builder.rb | 13 |
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) |