rails rspec controller test ActionController::RoutingError
My routes looks like this
resources :stores, :except => [:destroy] do
resources :toys, :member => {:destroy => :delete}
end
my objects controller spec look like this
req开发者_如何学编程uire 'spec_helper'
describe ToysController do
describe "GET index" do
it "assigns all toys as @toys" do
toy11 = Factory(:toy, :is_shiny => true)
toy12 = Factory(:toy,:is_shiny => false)
get :index
assigns(:toys).should eq([toy12,toy11 ])
end
end
end
end
I got the following error
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"toys"}
Since the toys resource is nested under stores resources its not able to get toys_path route so i think so the spec is failing.
How do i pass the spec?
Thanks
The error is due to not sending store_id to tyos index. Had i sent
:store_id => @store.id in get :index
it would have passed.
精彩评论