Hi,
I’m looking for a way to solve an error I get each times I run my functional tests. I have a Rails Engine gem (isolated), I have a JSON action with a route declared. But each times I use the method get in a test I get an ActionController::UrlGenerationError exception.
Here an example of code with the problem:
# config/routes.rb
MyEngine::Engine.routes.draw do
resources :cats, only: [:show], format: 'json'
end
# test/dummy/config/routes.rb
Rails.application.routes.draw do
mount MyEngine::Engine => '/my_engine'
end
# app/controllers/my_engine/cats_controller.rb
module MyEngine
class CatsController < ApplicationController
def show
render json: { hello: 'world' }
end
end
end
# test/controllers/my_engine/cats_controller_test.rb
module MyEngine
class CatsControllerTest < ActionController::TestCase
test 'should get success' do
get :show, id: 42
assert_response :success
end
end
end
Here is an example of test return:
1) Error:
MyEngine:: CatsControllerTest#test_should_get_success:
ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"my_engine/cats", :id=>"42"}
Anyone have an idea to solve this problem?
Thanks.