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

Replace RequestStore with ActiveSupport::CurrentAttributes #702

Merged
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
28 changes: 0 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
matrix:
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2]
appraisal:
- rails50
- rails51
- rails52
- rails60
- rails61
Expand All @@ -31,32 +29,6 @@ jobs:
- ruby: 2.3
db: POSTGRES

# Rails 5.0 supports Ruby 2.2-2.4
- appraisal: rails50
ruby: 2.5
- appraisal: rails50
ruby: 2.6
- appraisal: rails50
ruby: 2.7
- appraisal: rails50
ruby: 3.0
- appraisal: rails50
ruby: 3.1
- appraisal: rails50
ruby: 3.2

# Rails 5.1 supports Ruby 2.2-2.5
- appraisal: rails51
ruby: 2.6
- appraisal: rails51
ruby: 2.7
- appraisal: rails51
ruby: 3.0
- appraisal: rails51
ruby: 3.1
- appraisal: rails51
ruby: 3.2

# Rails 5.2 supports Ruby 2.2-2.5
- appraisal: rails52
ruby: 2.6
Expand Down
6 changes: 3 additions & 3 deletions audited.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = ">= 2.3.0"

gem.add_dependency "activerecord", ">= 5.0", "< 7.2"
gem.add_dependency "request_store", "~> 1.2"
gem.add_dependency "activerecord", ">= 5.2", "< 7.2"
gem.add_dependency "activesupport", ">= 5.2", "< 7.2"

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

require "active_record"
require "request_store"

module Audited
# Wrapper around ActiveSupport::CurrentAttributes
class RequestStore < ActiveSupport::CurrentAttributes
attribute :audited_store
end

class << self
attr_accessor \
:auditing_enabled,
Expand All @@ -27,7 +31,7 @@ def audit_class
deprecator: ActiveSupport::Deprecation.new('6.0.0', 'Audited')

def store
RequestStore.store[:audited_store] ||= {}
RequestStore.audited_store ||= {}
end

def config
Expand Down
13 changes: 10 additions & 3 deletions spec/audited_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
describe Audited do
describe "#store" do
describe "maintains state of store" do
let(:current_user) { RequestStore.store[:audited_store] }
before { Audited.store[:current_user] = current_user }
let(:current_user) { Models::ActiveRecord::User.new(name: 'Some User', username: 'some_username') }

it "can store and retrieve current_user" do
expect(Audited.store[:current_user]).to be_nil

Audited.store[:current_user] = current_user

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

it "checks store is not nil" do
expect(Audited.store).not_to be_nil
end
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
config.use_transactional_fixtures = false if Rails.version.start_with?("4.")
config.use_transactional_tests = false if config.respond_to?(:use_transactional_tests=)
end

Loading