current_user使用Devise在控制器中返回TrueClass而不是User

我在Rails 2.3.8项目上使用Devise 1.0.8。 在我的控制器测试中,我有:

context "when current_user is admin" do should "render" do sign_in Factory(:admin) get :index assert_response :success end end 

在控制器本身,有以下before_filter:

 def redirect_if_not_admin puts current_user redirect_to root_path unless current_user.try(:admin?) end 

这是我测试的输出:

 true false NoMethodError: undefined method `admin?' for true:TrueClass 

因此,当我在测试中使用sign_in时,current_user为true。 但是当我不这样做时,current_user是nil,所以肯定会受到影响。 在此先感谢您的帮助。

我用过确认! 在after_create / build中的资源上的方法,而不是在工厂中设置属性,并且这样做。 当网站上有未经证实的用户时,current_user等于true(已注册但尚未点击发送给他们的确认链接的用户)。