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

Fix bleeding test_tenant into current_tenant #337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -115,7 +115,7 @@ def self.with_tenant(tenant, &block)
raise ArgumentError, "block required"
end

old_tenant = current_tenant
old_tenant = Current.current_tenant
self.current_tenant = tenant
value = block.call
value
Expand All @@ -128,7 +128,7 @@ def self.without_tenant(&block)
raise ArgumentError, "block required"
end

old_tenant = current_tenant
old_tenant = Current.current_tenant
old_test_tenant = test_tenant
old_unscoped = unscoped

Expand Down
20 changes: 20 additions & 0 deletions spec/models/model_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@
it "should raise an error when no block is provided" do
expect { ActsAsTenant.with_tenant(nil) }.to raise_error(ArgumentError, /block required/)
end

it "does not bleed test_tenant into current_tenant" do
ActsAsTenant.current_tenant = nil
ActsAsTenant.test_tenant = account

ActsAsTenant.with_tenant(accounts(:bar)) {}

ActsAsTenant.test_tenant = nil
expect(ActsAsTenant.current_tenant).to eq(nil)
end
end

describe "::without_tenant" do
Expand Down Expand Up @@ -412,6 +422,16 @@
expect(ActsAsTenant.test_tenant).to eq(account)
end

it "does not bleed test_tenant into current_tenant" do
ActsAsTenant.current_tenant = nil
ActsAsTenant.test_tenant = account

ActsAsTenant.without_tenant {}

ActsAsTenant.test_tenant = nil
expect(ActsAsTenant.current_tenant).to eq(nil)
end

it "should return the value of the block" do
value = ActsAsTenant.without_tenant { "something" }
expect(value).to eq "something"
Expand Down