diff --git a/CHANGELOG.md b/CHANGELOG.md index f6242faf..42c0fa63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 ----- diff --git a/acts_as_tenant.gemspec b/acts_as_tenant.gemspec index 96a686f5..784f9e9a 100644 --- a/acts_as_tenant.gemspec +++ b/acts_as_tenant.gemspec @@ -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 diff --git a/gemfiles/rails_5.gemfile.lock b/gemfiles/rails_5.gemfile.lock index 75fe9c9d..af1e2d7d 100644 --- a/gemfiles/rails_5.gemfile.lock +++ b/gemfiles/rails_5.gemfile.lock @@ -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/ @@ -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) diff --git a/gemfiles/rails_6.gemfile.lock b/gemfiles/rails_6.gemfile.lock index 813516fb..9ed60cfd 100644 --- a/gemfiles/rails_6.gemfile.lock +++ b/gemfiles/rails_6.gemfile.lock @@ -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/ @@ -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) diff --git a/gemfiles/rails_6_1.gemfile.lock b/gemfiles/rails_6_1.gemfile.lock index c229e2a9..f1aa5878 100644 --- a/gemfiles/rails_6_1.gemfile.lock +++ b/gemfiles/rails_6_1.gemfile.lock @@ -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/ @@ -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) diff --git a/gemfiles/rails_7.gemfile.lock b/gemfiles/rails_7.gemfile.lock index dbfa5e38..c52a8c6f 100644 --- a/gemfiles/rails_7.gemfile.lock +++ b/gemfiles/rails_7.gemfile.lock @@ -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/ @@ -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) diff --git a/gemfiles/rails_main.gemfile.lock b/gemfiles/rails_main.gemfile.lock index e65ef47b..d205e266 100644 --- a/gemfiles/rails_main.gemfile.lock +++ b/gemfiles/rails_main.gemfile.lock @@ -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/ @@ -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) diff --git a/gemfiles/sidekiq_6.gemfile.lock b/gemfiles/sidekiq_6.gemfile.lock index c2560f8a..b11da8f8 100644 --- a/gemfiles/sidekiq_6.gemfile.lock +++ b/gemfiles/sidekiq_6.gemfile.lock @@ -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/ @@ -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) diff --git a/lib/acts_as_tenant.rb b/lib/acts_as_tenant.rb index ca4160fd..6e896f1e 100644 --- a/lib/acts_as_tenant.rb +++ b/lib/acts_as_tenant.rb @@ -1,5 +1,4 @@ -require "request_store" - +require "active_support/current_attributes" require "acts_as_tenant/version" require "acts_as_tenant/errors" @@ -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 @@ -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) @@ -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? diff --git a/spec/models/model_extensions_spec.rb b/spec/models/model_extensions_spec.rb index ec1a92a9..ef6f25ba 100644 --- a/spec/models/model_extensions_spec.rb +++ b/spec/models/model_extensions_spec.rb @@ -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