有谁知道如何手动处理会话对象? 我知道devise将它存储在数据库中,但必须有一种方法来手动设置会话。
答案 0 :(得分:2)
尝试warden.set_user(resource, :scope => scope)
这是一个测试用户只能查看他有权访问的合同的示例。 (has_role!和has_no_role!来自acl9 - 管理访问控制的伟大宝石)
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