ruby on rails 3.2 - Testing acts_as_tenant with rspec -


i have multi-tenancy app using ascts_as_tenant. trying write spec tests scope. want test output of user.active.

in general works fine code such following

it "returns correct active user"   user_active = fabricate(:user, curremp: true)   user_scope2_active = fabricate(:user, curremp: true)   user_not_active = fabricate(:user, account_id: user_active.account_id, curremp: false)   expect(user.active).should include(user_active)   #expect(user.active).to_not include(user_scope2_active)   expect(user.active).to_not include(user_not_active)  end 

however, i'm lost on how use acts_as_tenant functionality use current_tenant , therefore validate lists active users 1 tenant. i'm sure has been done before haven't found documentation on yet.

therefore how test acts_as_tenant user model rspec?

this do:

in general, don't need deal scoping information tenants in unit tests. write these tests if there no scoping going on.

the exception if want test related scoping. rarely. acts_as_tenant has own test suite test scoping (but that, since wrote ;).

if must deal aat in unit tests can set current_tenant directly:

actsastenant.current_tenant = account.first 

it's important clean tenant in after filter (set nil), or in debug hell.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -