Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 269
Description
Currently running ActsAsTenant v 1.0.1 on a Rails 7.1 app. We use rspec for testing and recently upgraded rspec-rails from 6.1.2 to 6.1.3. We started running into NoTenantSet errors on this upgrade when we were not before.
For some context, we have a helper set up that allows devs to include a tag in the rspec context to disable the tenant check:
RSpec.configuredo |config| # Acts as tenant support - check out documenation here:# https://github.com/ErwinM/acts_as_tenant#testingconfig.arounddo |example| ifexample.metadata[:skip_multitenancy]ActsAsTenant.without_tenantdo# ActsAsTenant::Errors::NoTenantSet error raised hereexample.runendelse## ...endendendDevs can then write specs that ignore the tenant check like so:
require"rails_helper"RSpec.describeSomeModel,type: :modeldocontext"without multi-tenancy",skip_multitenancy: truedoit"allows creating models"doexpect{SomeModel.create!(name: "foo")}.tochange(SomeModel,:count).by(1)endendcontext"with multi-tenancy"doit"raises an error if no tenant is set"doexpect{SomeModel.create!(name: "foo")}.toraise_error(ActsAsTenant::Errors::NoTenantSet)endendendI did some digging and I think this might be related to this PR rspec/rspec-rails#2752 (full changelog here). The ActsAsTenant.unscoped? flag is being reset somehow (confirmed this by stepping through the code) so this code block raises:
acts_as_tenant/lib/acts_as_tenant/model_extensions.rb
Lines 20 to 22 in 7e3bd8a
| ifActsAsTenant.should_require_tenant? && ActsAsTenant.current_tenant.nil? && !ActsAsTenant.unscoped? | |
| raiseActsAsTenant::Errors::NoTenantSet | |
| end |
Any help is appreciated here, and I'm happy to provide more info where I can!