-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Resolves #42] After switch callback not working with nil argument
- Each adapter is responsible for resetting the tenant info based on the way they behave - `switch` relies on the `connect_to_new` implementation of each of the adapters - Added test coverage for raised issue
- Loading branch information
Showing
8 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
shared_examples_for 'a generic apartment adapter callbacks' do | ||
class MyProc | ||
def self.call(tenant_name); end | ||
end | ||
|
||
include Apartment::Spec::AdapterRequirements | ||
|
||
before do | ||
Apartment.prepend_environment = false | ||
Apartment.append_environment = false | ||
end | ||
|
||
describe '#switch!' do | ||
before do | ||
Apartment::Adapters::AbstractAdapter.set_callback :switch, :before do | ||
MyProc.call(Apartment::Tenant.current) | ||
end | ||
|
||
Apartment::Adapters::AbstractAdapter.set_callback :switch, :after do | ||
MyProc.call(Apartment::Tenant.current) | ||
end | ||
|
||
allow(MyProc).to receive(:call) | ||
end | ||
|
||
# NOTE: Part of the test setup creates and switches tenants, so we need | ||
# to reset the callbacks to ensure that each test run has the correct | ||
# counts | ||
after do | ||
Apartment::Adapters::AbstractAdapter.reset_callbacks :switch | ||
end | ||
|
||
context 'when tenant is nil' do | ||
before do | ||
Apartment::Tenant.switch!(nil) | ||
end | ||
|
||
it 'runs both before and after callbacks' do | ||
expect(MyProc).to have_received(:call).twice | ||
end | ||
end | ||
|
||
context 'when tenant is not nil' do | ||
before do | ||
Apartment::Tenant.switch!(db1) | ||
end | ||
|
||
it 'runs both before and after callbacks' do | ||
expect(MyProc).to have_received(:call).twice | ||
end | ||
end | ||
end | ||
end |