diff options
author | Geoff Lee <geoff.lee@lendesk.com> | 2018-04-03 19:54:27 -0700 |
---|---|---|
committer | Geoff Lee <geoff.lee@lendesk.com> | 2018-04-03 19:54:27 -0700 |
commit | 0ac64470ea3dd39e7285ecb971b5995fb94eb2c2 (patch) | |
tree | 4a9beeef7cca628cd3847c86664c035a941d45b3 /railties/test | |
parent | a07d0680787ced3c04b362fa7a238c918211ac70 (diff) | |
download | rails-0ac64470ea3dd39e7285ecb971b5995fb94eb2c2.tar.gz rails-0ac64470ea3dd39e7285ecb971b5995fb94eb2c2.tar.bz2 rails-0ac64470ea3dd39e7285ecb971b5995fb94eb2c2.zip |
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 <geoff.lee@lendesk.com>
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/rack_logger_test.rb | 20 |
1 files changed, 18 insertions, 2 deletions
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 |