Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ruby-on-rails-3 – 在功能Rails测试中为authenticate_user抛出了Devise warden错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个资源,其中新操作需要用户登录才能查看.如果用户尝试在未登录的情况下创建新资源,则会将其重定向(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

特别是,不要将include Devise::TestHelpers放入classActiveSupport::TestCase.

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails-3 – 在功能Rails测试中为authenticate_user抛出了Devise warden错误全部内容,希望文章能够帮你解决ruby-on-rails-3 – 在功能Rails测试中为authenticate_user抛出了Devise warden错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。