English 中文(简体)
如何在使用designgem时为用户设置会话
原标题:How to set a session for a user while using devise gem
  • 时间:2010-10-06 11:20:26
  •  标签:
  • devise

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.

最佳回答

尝试warder.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
问题回答

暂无回答




相关问题
Testing devise with shoulda

I m having some difficulties in testing devise with shoulda: 2) Error: test: handle :index logged as admin should redirect to Daily page. (Admin::DailyClosesControllerTest): NoMethodError: undefined ...

Problem with Devise authentication on Rails

I tried to use Devise 1.0.6 over Rails 2.3. I followed the installation instructions and the user can successfully sign up. However, when I use the registered user account to sign in, the password ...

Creating an admin user in Devise on Rails beta 3

Ok, I m probably going to feel quite dumb when someone answers this one with a simple thing that I m missing but... here goes: I ve got a brand new app on rails 3 beta and I m using devise for the ...

Using devise with Rails 3 beta

I m currently trying to use Devise 1.1.pre3 as authentication in my upcoming project, but I can t get it to work properly. I have done everything it says in the documentation, installed warden and ...

热门标签