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

Saving wrong tentant when using factory bot #317

Open
leoncruz opened this issue Jul 19, 2023 · 0 comments
Open

Saving wrong tentant when using factory bot #317

leoncruz opened this issue Jul 19, 2023 · 0 comments

Comments

@leoncruz
Copy link

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:

image

image

image

I'm probably missing out something. What I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant