How to write controller tests when you override devise registration controller?

雨燕双飞 提交于 2019-11-30 01:55:57
David Tuite

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
Kevin Tsoi

Your route should look like this:

devise_for :users, :controllers => { :registrations => "registrations" } do
  get "/users/sign_up/:invitation_token" => 'registrations#new'
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!