开发者

How to set a session for a user while using devise gem

开发者 https://www.devze.com 2023-01-19 09:14 出处:网络
Does anyone know how to handle the session object manually? I know开发者_开发问答 devise stores it in the database, but there must be a way to set the session manually.Try warden.set_user(resource, :s

Does anyone know how to handle the session object manually? I know开发者_开发问答 devise stores it in the database, but there must be a way to set the session manually.


Try warden.set_user(resource, :scope => scope)

This is an example to test that a user can only see contracts to which he has access. (has_role! and has_no_role! is from acl9 - great gem to manage access control)

describe "GET index (logged in)" do
    it "@contracts contains only contracts on which user has admin role" do
        coA = Factory.create(:contract,:contract_name => "contract_A" )
        coB = Factory.create(:contract,:contract_name => "contract_B" )
        userA = Factory.create(:user, :username => "userA")
        userA.has_role! :admin, coA
        userA.has_no_role! coB
        warden.set_user(userA, :scope => "user")
        get :index, :locale => "fr"
        assigns(:contracts).should eq([coA])
    end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消