使用Authlogic时如何测试注销/注销(UserSessionsController销毁操作)?

时间:2010-10-31 17:32:08

标签: ruby-on-rails rspec authlogic

我正在为会话控制器(Authlogic 2.1.6)的销毁操作编写一个rspec测试。我无法解决我应该调用的方法,无论是在用户对象还是会话对象上,以确定会话是否仍然“活着”(即用户是否登录)。

我的第一直觉是使用@ user.logged_in?但我了解到这不起作用,因为logged_in根据会话超时而不是会话对象的状态做出决定。

这是我写的代码不起作用,因为be_logged_in在两种情况下都返回true。

    describe "for logged in user" do
      it "should logout the user" do
        activate_authlogic
        @user = Factory.create(:valid_user)
        @session = UserSession.create(@user)
        @user.should be_logged_in
        delete :destroy
        @user.should_not be_logged_in
        response.should redirect_to(root_path)
      end
    end
  end

我应该使用什么而不是'be_logged_in'?我花了一些时间在调试器中查看附加到会话和用户的方法,但没有一个人跳出来对我有用的东西。

1 个答案:

答案 0 :(得分:2)

UserSession.find.should be_nil

怎么样?