且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

覆盖设计注册控制器时如何编写控制器测试?

更新时间:2023-02-12 12:30:51

问题是 Devise 无法将路由从测试映射回原始控制器.这意味着,虽然如果您在浏览器中打开您的应用实际上可以正常工作,但您的控制器测试仍然会失败.

The problem is that Devise is unable to map routes from the test back to the original controller. That means that while your app actually works fine if you open it in the browser, your controller tests will still fail.

解决方案是在每次测试之前将设计映射添加到请求中,如下所示:

The solution is to add the devise mapping to the request before each test like so:

before :each do
  request.env['devise.mapping'] = Devise.mappings[:user]
end