2019
Solved the same error on my controller specification. I tried to make and verify decisions, but they also did not work, either did not lead to a method error, or saved a route matching error.
Direct determination of the route, as in the decision made, also did not satisfy the errors.
After a long search and some keyboard tests, the tests pass.
What is worth noting
- controller for polymorphic resource
- routes are nested in
resources :location, only[:index, :show] do... end - these are API routes, so only JSON
Decision
let(:location) do create(:location) end shared_examples("a user who can't manage locations") do describe 'GET #index' do it 'denies access' do get :index, params:{location_id: location.locationable.id, format: :json} expect(response).to have_http_status :unauthorized end end end
Thus, in the end, it was a combination of both solutions, but I had to put them in a parameter hash, otherwise it threw out the name / absence of the method or route error.
Conclusion
- association links must be in the params hash
- even if the controller responds to: json, it will not generate errors, there are no route errors
- you must include a data hash in the request, otherwise route matching errors will not be displayed
Hope this helps,
Hurrah!
source share