Ruby on Rails Monday, March 31, 2014

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.

-----
Geoffrey Roguelon

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/06e665fd-7a76-4d98-9d91-171e4dc6bf6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment