-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop
RequestStore
in favour of ActiveSupport::CurrentAttributes
- Loading branch information
Showing
6 changed files
with
103 additions
and
58 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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module PaperTrail | ||
module Request | ||
# Thread-isolated attributes for managing the current request. | ||
class CurrentAttributes < ActiveSupport::CurrentAttributes | ||
attribute :enabled | ||
attribute :enabled_for | ||
attribute :controller_info | ||
attribute :whodunnit | ||
attribute :skip_reset | ||
|
||
def enabled_for | ||
super || self.enabled_for = {} | ||
end | ||
|
||
def controller_info | ||
super || self.controller_info = {} | ||
end | ||
|
||
# Overrides ActiveSupport::CurrentAttributes#reset to support skipping. | ||
def reset | ||
return if skip_reset | ||
super | ||
end | ||
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
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module PaperTrail | ||
module Request | ||
::RSpec.describe CurrentAttributes.new do | ||
describe ".enabled_for" do | ||
context "when enabled_for is nil" do | ||
it "sets enabled_for to an empty hash to and returns it" do | ||
expect(described_class.attributes[:enabled_for]).to be_nil | ||
expect(described_class.enabled_for).to eq({}) | ||
expect(described_class.attributes[:enabled_for]).to eq({}) | ||
end | ||
end | ||
end | ||
|
||
describe ".controller_info" do | ||
context "when controller_info is nil" do | ||
it "sets controller_info to an empty hash to and returns it" do | ||
expect(described_class.attributes[:controller_info]).to be_nil | ||
expect(described_class.controller_info).to eq({}) | ||
expect(described_class.attributes[:controller_info]).to eq({}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |