I'm trying to test the routing of a namespaced Rails controller action, and something isn't set up correctly.
I've already looked at the following issues, none of them even seemed to answer the questions at hand, much less give me an answer to my issue:
- https://github.com/rspec/rspec-rails/issues/169
- https://github.com/rspec/rspec-rails/issues/575
- Rspec namespaced route specs failing even though route exists
It's not so much that I'm passing incorrect parameters to the action, it's that the route doesn't match at all when in the context of this test. What am I missing here?
config/routes.rb (using versionist gem):
...
api_version(module: 'api/v1', path: {value: 'v1'}) do
namespace :nphase do
resource :device_service, controller: 'device_service', only: :none, format: :json do
collection do
post :get_device_information
end
end
end
end
...
app/controllers/api/v1/device_service_controller.rb:
module Api
module V1
class DeviceServiceController < ApplicationController
respond_to :json
def get_device_information
respond_with json: {"success" => true}
end
end
end
end
output of rake routes |grep nphase
:
get_device_information_v1_nphase_device_service POST /v1/nphase/device_service/get_device_information(.:format) api/v1/nphase/device_service#get_device_information {:format=>:json}
spec/routing/api/v1/device_service_routing_spec.rb:
require 'spec_helper'
describe 'routes for DeviceService' do
it 'routes correctly' do
expect(post('/v1/nphase/device_service/get_device_information')).to route_to(
controller: 'api/v1/device_service',
action: 'get_device_information'
)
end
end
Test failure:
Failure/Error: expect(post('/v1/nphase/device_service/get_device_information')).to route_to(
No route matches "/v1/nphase/device_service/get_device_information"
GET
yet you're performing aPOST
. I see you attempt to create aPOST
inroutes.rb
, can't figure out why that doesn't work. – JesperPOST
. Which version of Rails and versionist are you using? – JesperGET
andPOST
to see if that was the issue. On my system, it is aPOST
request across the board. I get the aforementioned failure when the request is actually set up correctly. – Brad Rice