Reputation: 14581
If I have a route not defined, how do I test that it returns a 404?
Here is the relevant part of routes.rb
resources :reservations, only: [:index,:create,:destroy]
You can create, destroy and list reservations, but not change them.
The test then is:
patch :update, id: @reservation, reservation: { somefield: "data" }
assert_response :missing
This should pass, since the lack of a route should return a 404. Instead, I get a UrlGenerationError:
ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"reservations", :id=>"980190962", :reservation=>{:somefield=>"data"}}
I get it; the patch
call from the test cannot generate a URL. So how do I test that such a URL call would generate a 404?
Upvotes: 3
Views: 879
Reputation: 1060
You actually could assert an error like this has been thrown, would it be sufficient for you?
assert_raise ActionController::UrlGenerationError do
patch :update, id: @reservation, reservation: { somefield: "data" }
end
Upvotes: 4