-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TECH-12593: separate Context from ContextHandler
- Loading branch information
1 parent
6c23619
commit de98517
Showing
6 changed files
with
50 additions
and
33 deletions.
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
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module ContextualLogger | ||
class ContextHandler | ||
def initialize(instance, previous_context) | ||
@instance = instance | ||
@previous_context = previous_context | ||
end | ||
|
||
def reset! | ||
@instance.current_context = @previous_context | ||
end | ||
end | ||
end |
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'contextual_logger' | ||
|
||
class ContextualLoggerContextHandlerSpecContainer | ||
include ::ContextualLogger::Context | ||
end | ||
|
||
RSpec.describe ContextualLogger::ContextHandler do | ||
let(:context) { { service: { name: 'tts', description: 'TTS' }, integration: "google" } } | ||
let(:context2) { { service: { description: 'Context 2' }, integration: "google" } } | ||
|
||
let(:instance) { ContextualLoggerContextHandlerSpecContainer.new } | ||
|
||
subject(:handler) { described_class.new(instance, context) } | ||
|
||
it { is_expected.to respond_to(:reset!) } | ||
|
||
it 'resets the thread context on reset!' do | ||
instance.current_context = context2 | ||
handler.reset! | ||
|
||
expect(instance.current_context(nil)).to eq(context) | ||
end | ||
end |
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