Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure rack_cache[:verbose] can be set #103

Merged
merged 1 commit into from
Feb 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/lograge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ 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 rack_cache_hashlike?(app)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.config.action_dispatch.rack_cache[:verbose] = !rack_cache_hashlike?(app)

More concise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would not work - because then :[]= would always be called on rack_cache, raising the error that this commit is trying to fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mybad. I see now. I guess it's a somewhat confusing use of a predicate.


unless app.config.lograge.keep_original_rails_log
require 'lograge/rails_ext/rack/logger'
Expand All @@ -135,6 +135,11 @@ def self.setup(app)
Lograge.ignore(lograge_config.ignore_custom)
end

def rack_cache_hashlike?(app)
app.config.action_dispatch.rack_cache && app.config.action_dispatch.rack_cache.respond_to?(:[]=)
end
private_class_method :rack_cache_hashlike?

# TODO: Remove with version 1.0

def support_deprecated_config
Expand Down
38 changes: 38 additions & 0 deletions spec/lograge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,44 @@
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