From 633f1c01b821c3a87636d11bcfcfa9910b895281 Mon Sep 17 00:00:00 2001 From: Tilmann Singer Date: Sat, 31 Jan 2015 02:05:31 +0100 Subject: [PATCH] Make sure rack_cache[:verbose] can be set Before this change, the following config setting which is provided as example in production.rb of current rails versions: config.action_dispatch.rack_cache = true would result in a startup failure. Fixes https://github.com/roidrage/lograge/issues/52 --- lib/lograge.rb | 3 ++- spec/lograge_spec.rb | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/lograge.rb b/lib/lograge.rb index a09999d0..9384b260 100644 --- a/lib/lograge.rb +++ b/lib/lograge.rb @@ -116,7 +116,8 @@ def self.unsubscribe(component, subscriber) def self.setup(app) self.application = app - app.config.action_dispatch.rack_cache[:verbose] = false if app.config.action_dispatch.rack_cache + app.config.action_dispatch.rack_cache[:verbose] = false if app.config.action_dispatch.rack_cache && + app.config.action_dispatch.rack_cache.respond_to?(:[]=) unless app.config.lograge.keep_original_rails_log require 'lograge/rails_ext/rack/logger' diff --git a/spec/lograge_spec.rb b/spec/lograge_spec.rb index 1d72bad3..8f49209b 100644 --- a/spec/lograge_spec.rb +++ b/spec/lograge_spec.rb @@ -58,6 +58,43 @@ end end + describe 'disabling rack_cache verbosity' do + subject { -> { Lograge.setup(app_config) } } + let(:app_config) do + double(config: ActiveSupport::OrderedOptions.new.tap do |config| + config.action_dispatch = config_option + config.lograge = ActiveSupport::OrderedOptions.new + config.lograge.keep_original_rails_log = true + end + ) + end + let(:config_option) { double(rack_cache: rack_cache) } + + context 'when rack_cache is false' do + let(:rack_cache) { false } + + it 'does not change config option' do + expect(subject).to_not change { config_option.rack_cache } + end + end + + context 'when rack_cache is a hash' do + let(:rack_cache) { { foo: 'bar', verbose: true } } + + it 'sets verbose to false' do + expect(subject).to change { config_option.rack_cache[:verbose] }.to(false) + end + end + + context 'when rack_cache is true' do + let(:rack_cache) { true } + + it 'does not change config option' do + expect(subject).to_not change { config_option.rack_cache } + end + end + end + describe 'deprecated log_format interpreter' do let(:app_config) do double(config: