How to check if a route doesn't exist in Rails 4.x

If I have a route not , how can I check that it returns 404?

Here is the relevant part of the routes. rb

resources :reservations, only: [:index,:create,:destroy]

      

You can create, delete, and write off reservations, but not change them.

Then the following is done:

patch :update, id: @reservation, reservation: { somefield: "data" }
assert_response :missing

      

This should get through since the absence of a route should return 404. Instead, I get an UrlGenerationError:

ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"reservations", :id=>"980190962", :reservation=>{:somefield=>"data"}}

      

I understand; call patch

from test fails to generate url. So how can I check that such a URL call will generate a 404?

+3


source to share


1 answer


You could really argue that a bug like this was thrown, would that be enough for you?



assert_raise ActionController::UrlGenerationError do
  patch :update, id: @reservation, reservation: { somefield: "data" }
end

      

+4


source







All Articles