Skip to content

Commit

Permalink
Make sure rack_cache[:verbose] can be set
Browse files Browse the repository at this point in the history
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 #52
  • Loading branch information
til committed Jan 31, 2015
1 parent a2538a6 commit 633f1c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/lograge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
37 changes: 37 additions & 0 deletions spec/lograge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 633f1c0

Please sign in to comment.