acts_as_tenant
acts_as_tenant copied to clipboard
Saving wrong tentant when using factory bot
This is how I configure the tenant for request specs on rails_helper.rb
:
config.before(:each, type: :request) do |spec|
unless spec.metadata[:without_agency]
agency = create(:agency, name: 'Default Agency')
ActsAsTenant.test_tenant = agency
host! "#{agency.subdomain}.example.com"
end
end
config.after(:each, type: :request) do
ActsAsTenant.test_tenant = nil
end
This is my test:
let!(:agency) { create(:agency) }
let!(:user) { create(:user, agency: agency) }
let!(:access_token) { create(:access_token, user: user) }
let(:headers) do
{
'Authorization' => "Bearer #{access_token.unhashed_access_token}"
}
end
context 'when agency from subdomain exists' do
it do
host! "#{agency.subdomain}.example.com"
get '/dummies', headers: headers
expect(Current.agency).to be agency
end
end
In the controller, the current_tenant
is the agency created on test, but the user agency is the created on rails_helper.rb
:
I'm probably missing out something. What I doing wrong?