Skip to content

Commit

Permalink
Replace RequestStore dependency with CurrentAttributes (#313)
Browse files Browse the repository at this point in the history
* Replace RequestStore dependency with CurrentAttributes

* Update appraisals

* Update lib/acts_as_tenant.rb

* Update changelog
  • Loading branch information
excid3 authored Dec 6, 2023
1 parent d29185f commit 0497b29
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased
----------

* Replace RequestStore dependency with CurrentAttributes. #313 - @excid3
* Easy integration with Sidekiq, not requiring to add any configuration to the initializer #314 - @nunommc
* Add `scope` support to `acts_as_tenant :account, ->{ with_deleted }` #282 - @adrian-gomez
The scope will be forwarded to `belongs_to`.
* Add `job_scope` configuration to customize how tenants are loaded in background jobs - @excid3
Expand All @@ -12,8 +14,6 @@ ActsAsTenant.configure do |config|
end
```

* Easy integration with Sidekiq, not requiring to add any configuration to the initializer - @nunommc

0.6.1
-----

Expand Down
1 change: 0 additions & 1 deletion acts_as_tenant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ Gem::Specification.new do |spec|

spec.require_paths = ["lib"]

spec.add_dependency "request_store", ">= 1.0.5"
spec.add_dependency "rails", ">= 5.2"
end
3 changes: 0 additions & 3 deletions gemfiles/rails_5.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
acts_as_tenant (0.6.1)
rails (>= 5.2)
request_store (>= 1.0.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -141,8 +140,6 @@ GEM
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.1)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down
3 changes: 0 additions & 3 deletions gemfiles/rails_6.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
acts_as_tenant (0.6.1)
rails (>= 5.2)
request_store (>= 1.0.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -156,8 +155,6 @@ GEM
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.1)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down
3 changes: 0 additions & 3 deletions gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
acts_as_tenant (0.6.1)
rails (>= 5.2)
request_store (>= 1.0.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -160,8 +159,6 @@ GEM
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.1)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down
3 changes: 0 additions & 3 deletions gemfiles/rails_7.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
acts_as_tenant (0.6.1)
rails (>= 5.2)
request_store (>= 1.0.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -168,8 +167,6 @@ GEM
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.1)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down
3 changes: 0 additions & 3 deletions gemfiles/rails_main.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ PATH
specs:
acts_as_tenant (0.6.1)
rails (>= 5.2)
request_store (>= 1.0.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -244,8 +243,6 @@ GEM
regexp_parser (2.8.1)
reline (0.3.5)
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rubocop (1.52.1)
json (~> 2.3)
Expand Down
3 changes: 0 additions & 3 deletions gemfiles/sidekiq_6.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
acts_as_tenant (0.6.1)
rails (>= 5.2)
request_store (>= 1.0.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -165,8 +164,6 @@ GEM
rake (13.0.6)
redis (4.8.1)
regexp_parser (2.8.1)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down
15 changes: 9 additions & 6 deletions lib/acts_as_tenant.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "request_store"

require "active_support/current_attributes"
require "acts_as_tenant/version"
require "acts_as_tenant/errors"

Expand All @@ -14,6 +13,10 @@ module ActsAsTenant
@@models_with_global_records = []
@@mutable_tenant = false

class Current < ActiveSupport::CurrentAttributes
attribute :current_tenant, :acts_as_tenant_unscoped
end

class << self
attr_writer :default_tenant
end
Expand Down Expand Up @@ -57,11 +60,11 @@ def self.polymorphic_type
end

def self.current_tenant=(tenant)
RequestStore.store[:current_tenant] = tenant
Current.current_tenant = tenant
end

def self.current_tenant
RequestStore.store[:current_tenant] || test_tenant || default_tenant
Current.current_tenant || test_tenant || default_tenant
end

def self.test_tenant=(tenant)
Expand All @@ -73,11 +76,11 @@ def self.test_tenant
end

def self.unscoped=(unscoped)
RequestStore.store[:acts_as_tenant_unscoped] = unscoped
Current.acts_as_tenant_unscoped = unscoped
end

def self.unscoped
RequestStore.store[:acts_as_tenant_unscoped]
Current.acts_as_tenant_unscoped
end

def self.unscoped?
Expand Down
6 changes: 0 additions & 6 deletions spec/models/model_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,5 @@
ActsAsTenant.default_tenant = account
expect(ActsAsTenant.current_tenant).to eq(accounts(:bar))
end

it "survives request resets" do
ActsAsTenant.default_tenant = account
RequestStore.clear!
expect(ActsAsTenant.current_tenant).to eq(account)
end
end
end

0 comments on commit 0497b29

Please sign in to comment.