rspec用于资源的创建路由

时间:2013-12-19 21:16:07

标签: ruby-on-rails ruby rspec

我有这个规格:

specify { expect(:post => admin_featured_path()).to route_to(:controller => 'admin/featured', :action => 'create')}

我不能让它通过但是路线的帖子应该路由到创建动作似乎合乎逻辑......

这是我的路线档案:

namespace :admin do
    resources :featured, only: [:index, :update, :destroy, :create]
end

这是失败消息:

1) Featured routes 
     Failure/Error: specify { expect(:post => admin_featured_path()).to route_to(:controller => 'admin/featured', :action => 'create')}
     ActionController::UrlGenerationError:
       No route matches {:action=>"update", :controller=>"admin/featured"} missing required keys: [:id]
     # ./spec/routing/featured_spec.rb:7:in `block (2 levels) in <top (required)>'

2 个答案:

答案 0 :(得分:1)

这应该有效(未经测试):

page = post admin_featured_path
expect(page).to route_to(:controller => 'admin/featured', :action => 'create')

答案 1 :(得分:0)

{:post => admin_featured_path}.should route_to(:controller => 'admin/featured', :action => 'create')

{:post => "admin/featured"}.should route_to(:controller => "admin/featured", :action => 'create')