I’m getting a routing error in a test example that I can’t make sense of. The relevant routing code is:
resources :books, only: [:index, :new, :create, :show, :update, :destroy] do
put 'modify' => 'books#modify'
end
yielding the following output from ‘rake routes’:
book_modify PUT /books/:book_id/modify(.:format) books#modify
and the test example looks like this:
describe 'verb = MoveBook source_book_id, dest_book_id => [:ok, nil]' do
it 'returns an indication of success' do
put 'modify', xhr: true, format: :js, params: {verb: 'MoveBook', source_id: 1, dest_id: 2}
expect(response).to have_http_status :ok
expect(response.text).to be_blank
end
end
When I run this test, I get the following error:
1) BooksController GET 'modify' verb = MoveBook source_book_id, dest_book_id => [:ok, nil] returns an indication of success
Failure/Error: put 'modify', xhr: true, format: :js, params: {verb: 'MoveBook', source_id: 1, dest_id: 2}
ActionController::UrlGenerationError:
No route matches {:action=>"modify", :controller=>"books", :dest_id=>2, :format=>:js, :source_id=>1, :verb=>"MoveBook"}
# ./spec/controllers/books_controller_spec.rb:184:in `block (4 levels) in <top (required)>'
As you can see, the route is defined. So why would it be rejected?