我使用 authlogic 对用户进行身份验证。在我的控制器中,我使用 current_user,定义(如记录)如下:
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
我还使用 declarative_authorization 来管理当前用户的权限。在正常的运行时场景中一切正常,但是当我创建使用诸如“get_with”之类的请求语句的功能测试时,控制器中的 current_user 为 nil。我查看了 declarative_authorization 测试助手代码,发现在这种情况下,declarative_authorization gem 实际上将当前用户存储在 Authorization.current_user 中(它又来自 Thread.current["current_user"])。因此,当前用户在不同场景中的处理方式似乎相当混乱。
我的问题:在正常运行时和测试场景中找到 current_user 的适当方法是什么?