简体   繁体   中英

Acts_as_tenant, cached data for different tenants?

I made a user with two accounts, a user should have documents that are scoped to the account they belong to. I'm writing tests that @user.documents should be different if they are under @account_1 vs @account_2

ActsAsTenant.with_tenant(@account_1) do
  @account_1_documents = @user.documents
end

ActsAsTenant.with_tenant(@account_2) do
  @account_2_documents = @user.reload.documents
end

expect(@account_1_documents).not_to eq @account_2_documents

Unfortunately this fails, maybe because it is cached? If I do it in console and set the current tenant, I get back different documents.

I think my intuition was right, @user.documents is cached, and you can't count on @user.reload or @user.documents.reload to get the current object, you have to call reload on both at the same time.

So doing @user.reload.documents.reload ended up working and making the tests pass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM