-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard LogSubscriber against tagged logger with absent formatter (#504)
- Loading branch information
1 parent
68fb960
commit f02da16
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe GoodJob::LogSubscriber do | ||
let(:subscriber) { described_class.new } | ||
|
||
around do |example| | ||
orig_loggers = described_class.loggers.dup | ||
described_class.loggers.clear | ||
described_class.reset_logger | ||
|
||
example.run | ||
|
||
described_class.loggers.replace(orig_loggers) | ||
described_class.reset_logger | ||
end | ||
|
||
describe "loggers" do | ||
let(:logs) { StringIO.new } | ||
|
||
it 'logs output with a simple logger' do | ||
described_class.loggers << Logger.new(logs) | ||
event = ActiveSupport::Notifications::Event.new("", nil, nil, "id", {}) | ||
|
||
subscriber.scheduler_create_pool(event) | ||
expect(logs.string).to include("GoodJob started scheduler with queues= max_threads=") | ||
end | ||
|
||
it 'logs output with a tagged logger with missing formatter' do | ||
logger = ActiveSupport::TaggedLogging.new(Logger.new(logs)) | ||
logger.formatter = nil | ||
described_class.loggers << logger | ||
|
||
event = ActiveSupport::Notifications::Event.new("", nil, nil, "id", {}) | ||
|
||
subscriber.scheduler_create_pool(event) | ||
expect(logs.string).to include("GoodJob started scheduler with queues= max_threads=") | ||
end | ||
end | ||
end |