Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/acts_as_tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def self.with_tenant(tenant, &block)
raise ArgumentError, "block required"
end

old_tenant = current_tenant
old_tenant = RequestStore[:current_tenant]
self.current_tenant = tenant
value = block.call
value
Expand All @@ -98,7 +98,7 @@ def self.without_tenant(&block)
raise ArgumentError, "block required"
end

old_tenant = current_tenant
old_tenant = RequestStore[:current_tenant]
old_unscoped = unscoped

self.current_tenant = nil
Expand Down
12 changes: 12 additions & 0 deletions spec/middlewares/test_tenant_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ def self.assert_current_id(id)
expect(subject.status).to eq 200
expect(ActsAsTenant.current_tenant).to eq account2
end

it "does not leak test_tenant into current_tenant when using with_tenant before request" do
ActsAsTenant.with_tenant(account1) {}
expect(TestReceiver).to receive(:assert_current_id).with(nil)
expect(subject.status).to eq 200
end

it "does not leak test_tenant into current_tenant when using without_tenant before request" do
ActsAsTenant.without_tenant {}
expect(TestReceiver).to receive(:assert_current_id).with(nil)
expect(subject.status).to eq 200
end
end
end
end