我遇到了一个有趣的
ActionController::UrlGenerationError
在测试我的定制设计时
User::RegistrationsController
错误如下:
ActionController::UrlGenerationError:
No route matches {:action=>"create", :controller=>"user/registrations", :user=>{:name=>"Adriane Koepp", :city=>"Nidiafurt", :address=>"14955 Cormier Viaduct", :country=>"Mozambique", :email=>"moshe@kozey.com", :phone_primary=>"(295) 491-0447 x9108", :phone_secondary=>"536.985.9499 x7264", :postal_code=>"93438-7448", :province=>"South Carolina", :password=>"MaH9R5G8XqB", :pets_attributes=>[{:name=>"Patches", :chip_number=>"149793073311890", :species=>"iusto"}]}}
这个错误出现在我对这个控制器的所有测试中,但是为了简单起见,我只列出一个测试
create
行动:
it 'creates a new User' do
expect do
post :create, params: { user: valid_attributes }
end.to change(User, :count).by(1)
end
这个
routes.rb
包含:
devise_for :users, controllers: {
registration: 'user/registration'
}
我可以导航到我的注册页面
http://localhost:3000/users/sign_up
,但出于某种原因,我的测试似乎不认为此控制器具有
创造
行动。为什么呢?
其他步骤
根据d1ceward的建议,我在路由中使用了复数形式的“注册”,现在错误消息变为
AbstractController::ActionNotFound
错误。我通过跟踪
documentation
并将以下块添加到我的测试的顶部:
before(:each) do
@request.env['devise.mapping'] = Devise.mappings[:user]
end