2013-12-19 29 views
1

一個創建路線我有這個天賦: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)>' 

回答

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

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

{:後=> 「管理/功能」}工作,這不是{:post => admin_featured_pa​​th} ... – Boti

+0

第二個是正確的答案 – Boti

1

這應該工作(未經測試):

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

它不工作... – Boti