Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec2 and Rails 3 - View Spec Routing for Nested Resources

I have a nested resource, setup like this:

 resources :chickens do
      resources :eggs
 end

The views for the EggsController are under views/eggs, but:

describe "eggs/index.html.erb" do

gives a "No route matches {:action => "create", :controller => "eggs"} error on calling render. How do I get RSpec to find the correct (nested) route for view specs?

As a side note, is there any way to specify a nested resource to the Rails 3 controller scaffold generator?

like image 757
Christopher Foy Avatar asked Oct 28 '10 14:10

Christopher Foy


1 Answers

The test looks ok to me...

By any chance do you have a form on your eggs/index.html.erb for creating new eggs that might not yet be wired up correctly? It seems it may be trying to render the index view but failing because the view is trying build a route that doesn't exist? You'd want to make sure that the form is using the correct nested resource route. Does the view render when you load it up in the browser?

like image 199
njorden Avatar answered Oct 07 '22 01:10

njorden