我得到了一个非常基本的控制器测试
require 'spec_helper'
describe Admin::OrdersController do
describe "GET #order_detail" do
before :each do
new_admin = FactoryGirl.create(:admin)
sign_in new_admin
@storefront = FactoryGirl.create(:storefront)
@order = FactoryGirl.create(:order)
end
it "assigns the requested order to @order" do
get :order_detail, { :storefront_id => @storefront.id, :order_id => @order.id }
assigns(:order).should eq(@order)
end
it "renders the :show template" do
get :order_detail, {:storefront_id => @storefront.id, :order_id => @order.id}
response.should render_template :order_detail
end
end
end
这让我得到以下两个操作的错误:
ActionController::RoutingError:
No route matches {:storefront_id=>"14", :order_id=>"1", :controller=>"admin/orders", :action=>"order_detail"}
From routes.rb:
resources :storefronts do
resources :orders do
member do
get :order_detail
end
end
end
我想get :order_detail, { :storefront_id => @storefront.id, :order_id => @order.id }
应该是生成路由的正确方式,但不幸的是它不是。
您可以看到Rails在应用程序根目录中使用rake routes
或bundle exec rake routes
生成的路由。我在一个全新的rails应用程序中做了相同的资源设置,rake路由输出如下(仅用于订单详细路由):
order_detail_storefront_order GET /storefronts/:storefront_id/orders/:id/order_detail(.:format) orders#order_detail
可以看到,rails期望:id
而不是:order_id
。尝试将:order_id
更改为:id
作为规格中的参数键。