mercredi 19 décembre 2018

Rspec 3.8, request spec, unable to set route with id

In the request spec for the show method i want to test the route cars/:id. If i write the path like the following i get a redirect to my root exception.

 describe '#show' do
  let(:car) {create :car}

it 'renders a partial' do
  get car_url(car.id)
  #get car_url, car.id
  expect(response).to render_template(:template)
end 

=> expecting <"template"> but was a redirect to <http://admin.example.com/>

When i change get car_url,car.id with get cars to test the #index method everything works fine. But i do not see myself able to add a id parameter to the route.

In the console the app object gives me:

irb(main):001:0> app.car_url(2)                                                                                                                                                     
=> "http://www.example.com/cars/2"

so the route is there. The factory is also a valid object saved to the database.

Aucun commentaire:

Enregistrer un commentaire