Skip to content

Commit

Permalink
Merge pull request #669 from convisoappsec/main
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmorrison authored Apr 20, 2023
2 parents 900303f + 0960dc7 commit 342734c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
1 change: 1 addition & 0 deletions audited.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = ">= 2.3.0"

gem.add_dependency "activerecord", ">= 5.0", "< 7.1"
gem.add_dependency "request_store", "~> 1.2"

gem.add_development_dependency "appraisal"
gem.add_development_dependency "rails", ">= 5.0", "< 7.1"
Expand Down
9 changes: 2 additions & 7 deletions lib/audited.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "active_record"
require "request_store"

module Audited
class << self
Expand All @@ -24,13 +25,7 @@ def audit_class
deprecate audit_model: "use Audited.audit_class instead of Audited.audit_model. This method will be removed."

def store
current_store_value = Thread.current.thread_variable_get(:audited_store)

if current_store_value.nil?
Thread.current.thread_variable_set(:audited_store, {})
else
current_store_value
end
RequestStore.store[:audited_store] ||= {}
end

def config
Expand Down
8 changes: 2 additions & 6 deletions spec/audited_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
describe Audited do
describe "#store" do
describe "maintains state of store" do
let(:current_user) { "current_user" }
let(:current_user) { RequestStore.store[:audited_store] }
before { Audited.store[:current_user] = current_user }

it "when executed without fibers" do
it "checks store is not nil" do
expect(Audited.store[:current_user]).to eq(current_user)
end

it "when executed with Fibers" do
Fiber.new { expect(Audited.store[:current_user]).to eq(current_user) }.resume
end
end
end
end

0 comments on commit 342734c

Please # to comment.