assert_route以良好的路线失败

时间:2012-03-12 06:17:23

标签: ruby-on-rails ruby-on-rails-3 functional-testing rails-routing

我正在编写一个功能测试,但它失败并出现以下错误:

1) Failure:
test: routing should route GET /categories/1/inventory_items/2/edit to/from {:action=>"edit", :controller=>"inventory_items", :category_id=>"1", :id=>"2"}. (InventoryItemsControllerTest)
    []:
No route matches "/categories/1/inventory_items/2/edit"

有路线:

resources :categories, :constraints => lambda { |request| Category.exists?(request.params['category_id']) } do
  resources :inventory_items
end

和我的佣金路线:

      category_inventory_items GET    /categories/:category_id/inventory_items(.:format)          inventory_items#index
                               POST   /categories/:category_id/inventory_items(.:format)          inventory_items#create
   new_category_inventory_item GET    /categories/:category_id/inventory_items/new(.:format)      inventory_items#new
  edit_category_inventory_item GET    /categories/:category_id/inventory_items/:id/edit(.:format) inventory_items#edit
       category_inventory_item GET    /categories/:category_id/inventory_items/:id(.:format)      inventory_items#show
                               PUT    /categories/:category_id/inventory_items/:id(.:format)      inventory_items#update
                               DELETE /categories/:category_id/inventory_items/:id(.:format)      inventory_items#destroy

我尝试创建一个Category的{​​{1}}对象,但它仍然失败。我在路线中执行了:idputs哈希是params!我正在使用像这样的应用匹配器:

{}

当我在匹配器中执行should route(:get, "/categories/1/inventory_items/2").to(:action => "show", :controller => "inventory_items", :category_id => 1, :id => 2) 时,puts已正确填充:

params

感谢任何帮助,谢谢!

0 个答案:

没有答案