Rails Engine ActionController::UrlGenerationError on functional tests

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.rbMyEngine::Engine.routes.draw do

resources :cats, only: [:show], format: 'json’end

test/dummy/config/routes.rbRails.application.routes.draw do

mount MyEngine::Engine => '/my_engine’end

app/controllers/my_engine/cats_controller.rbmodule MyEngine

class CatsController < ApplicationController
def show
render json: { hello: ‘world’ }
end
endend

test/controllers/my_engine/cats_controller_test.rbmodule MyEngine

class CatsControllerTest < ActionController::TestCase
test ‘should get success’ do
get :show, id: 42

  assert_response :success
end

endend

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.

Hi,

I experience that behaviour too. I assume something is wrong
with ActionController::TestCase, because the route is working in my
browser. The assumption is validated by the fact that my test class
inheriting from ActionDispatch::IntegrationTest instead makes routes
helper
working.

Georg

Am Montag, 31. März 2014 09:57:54 UTC+2 schrieb Geoffrey Roguelon:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs