ruby on rails - How to test controllers with nested routes using Rspec? -
ruby on rails - How to test controllers with nested routes using Rspec? -
i have 2 controllers created using scaffold generator of rails. wanted them nested in folder called "demo" , ran
rails g scaffold demo/flows rails g scaffold demo/nodes then decided nest nodes within flows, , changed routes file so:
namespace :demo resources :flows resources :nodes end end but alter resulted on rspec tests nodes breaking actioncontroller::routing errors.
15) demo::nodescontroller delete destroy redirects demo_nodes list failure/error: delete :destroy, :id => "1" actioncontroller::routingerror: no route matches {:id=>"1", :controller=>"demo/nodes", :action=>"destroy"} the problem rspec looking @ wrong route. it's supposed "demo/flows/1/nodes". needs mock model flow, not sure how provide that. here sample code generated rspec file:
def mock_node(stubs={}) @mock_node ||= mock_model(demo::node, stubs).as_null_object end describe "get index" "assigns demo_nodes @demo_nodes" demo::node.stub(:all) { [mock_node] } :index assigns(:demo_nodes).should eq([mock_node]) end end can help me understand how need provide flow model?
you have 2 different questions going on here, may want split them since sec question has nil title of post. recommend using factorygirl creating mock models https://github.com/thoughtbot/factory_girl
your route error coming fact nested routes require id's after each 1 of them this:
/demo/flows/:flow_id/nodes/:id when delete on object, need pass in flow id or else won't know route talking about.
delete :destroy, :id => "1", :flow_id => "1" in future, easiest way check expects run rake routes , compare output route params passing in.
demo_flow_node /demo/flows/:flow_id/nodes/:id(.:format) {:action=>"destroy", :controller=>"demo/flows"} ruby-on-rails routing rspec
Comments
Post a Comment