vendredi 31 juillet 2015

RSpec - Error when testing nested index route

I have my photo actions nested under restaurant actions as so:

resources :restaurants do
    resources :photos
end

However when I run my test:

describe PhotosController do
  it { should route(:get, "/restaurants/:restaurant_id/photos").to(action: :index) }
end

I get the error:

1) PhotosController should route GET /restaurants/:restaurant_id/photos to/from {:action=>"index", :controller=>"photos"}
     Failure/Error: it { should route(:get, "/restaurants/:restaurant_id/photos").to(action: :index) }
       The recognized options <{"controller"=>"photos", "action"=>"index", "restaurant_id"=>":restaurant_id"}> did not match <{"action"=>"index", "controller"=>"photos"}>, difference:.
       --- expected
       +++ actual
       @@ -1 +1 @@
       -{"action"=>"index", "controller"=>"photos"}
       +{"controller"=>"photos", "action"=>"index", "restaurant_id"=>":restaurant_id"}
     # ./spec/controllers/photos_controller_spec.rb:4:in `block (2 levels) in <top (required)>'

I checked my route paths via rake routes and got the following:

restaurant_photos  GET /restaurants/:restaurant_id/photos(.:format)  photos#index

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire