From 0ac64470ea3dd39e7285ecb971b5995fb94eb2c2 Mon Sep 17 00:00:00 2001 From: Geoff Lee Date: Tue, 3 Apr 2018 19:54:27 -0700 Subject: Stop mutating body response If @app.call returns an object that is saved (for e.g., in a constant), the mutation results in a continuing cycle of wrapping the body in Rack::BodyProxy, eventually leading to SystemStackError ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ On branch fix-return-response-mutation-rack-logger - Tue 3 Apr 2018 19:54:28 PDT by Geoff Lee --- railties/test/rack_logger_test.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rack_logger_test.rb b/railties/test/rack_logger_test.rb index e47f30d5b6..3a4b7ba437 100644 --- a/railties/test/rack_logger_test.rb +++ b/railties/test/rack_logger_test.rb @@ -14,14 +14,21 @@ module Rails attr_reader :logger - def initialize(logger = NULL, taggers = nil, &block) - super(->(_) { block.call; [200, {}, []] }, taggers) + def initialize(logger = NULL, app: nil, taggers: nil, &block) + app ||= ->(_) { block.call; [200, {}, []] } + super(app, taggers) @logger = logger end def development?; false; end end + class TestApp < Struct.new(:response) + def call(_env) + response + end + end + Subscriber = Struct.new(:starts, :finishes) do def initialize(starts = [], finishes = []) super @@ -72,6 +79,15 @@ module Rails end end end + + def test_logger_does_not_mutate_app_return + response = [] + app = TestApp.new(response) + logger = TestLogger.new(app: app) + assert_no_changes('response') do + logger.call('REQUEST_METHOD' => 'GET') + end + end end end end -- cgit v1.2.3