ruby-on-rails-3 – 在功能Rails测试中为authenticate_user抛出
发布时间:2020-12-16 23:34:25 所属栏目:百科 来源:网络整理
导读:我有一个资源,其中新操作需要用户登录才能查看.如果用户尝试在未登录的情况下创建新资源,则会将其重定向(302’d)到登录页面.我的功能测试看起来像这样: test "should not get new unless logged in" do get :new assert_response :redirect end stacktrace
我有一个资源,其中新操作需要用户登录才能查看.如果用户尝试在未登录的情况下创建新资源,则会将其重定向(302’d)到登录页面.我的功能测试看起来像这样:
test "should not get new unless logged in" do get :new assert_response :redirect end stacktrace看起来像这样: ArgumentError: uncaught throw :warden /.../gems/warden-1.1.1/lib/warden/proxy.rb:114:in `throw' /.../gems/ruby-1.9.2-p318/gems/warden-1.1.1/lib/warden/proxy.rb:114:in `authenticate!' /.../gems/ruby-1.9.2-p318/gems/devise-2.0.4/lib/devise/controllers/helpers.rb:48:in `authenticate_user!' 在新操作之前,我有一个before_filter到authenticate_user. 我理解为什么authenticate_user!失败但我无法理解为什么它会抛出一个错误.它不应该像在webapp中那样表现.将用户重定向到登录页面? 谢谢. 解决方法
按照
documentation说:
class ActionController::TestCase include Devise::TestHelpers end 特别是,不要将 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |