How to set a session for a user while using devise gem
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
精彩评论