enriclluelles/route_translator

NoMethodError: private method `_routes' called

Closed this issue · 9 comments

GSI commented

Said error is caused in test environment, when calling a _path or _url method (eg user_path) from a view helper or a view helper's test.

  • Localized variants (eg user_de_path) are equally affected.
  • The issue is present in at least route_translator 4.1, 4.2 and 4.3.
  • In production, the method works just fine and returns the expected value.
  • The issue vanishes, when removing route_translator from the project.

Could you please provide a reduced test case?

@GSI

the problem is apprantly here: https://github.com/rails/rails/blob/v4.2.6/actionpack/lib/action_dispatch/routing/route_set.rb#L280

we need another way to add helpers to ActionView::TestCase. PR are very welcome

Failing spec:

test/helpers/helper_test.rb

require File.expand_path('../../test_helper', __FILE__)

class TestController < ActionController::Base
  def test
    render text: nil
  end
end

class TestHelperTest < ActionView::TestCase
  include RouteTranslator::ConfigurationHelper
  include RouteTranslator::RoutesHelper

  def setup
    setup_config

    @routes = ActionDispatch::Routing::RouteSet.new

    config_default_locale_settings 'en'

    draw_routes do
      localized do
        get :test, to: 'test#test'
      end
    end
  end

  def teardown
    teardown_config
  end

  def test_no_private_method_call
    test_path
  end
end
GSI commented

I'm recently getting back to ruby. If I may still be of help, please let me know.

@GSI yes, this part seems too complex for me at the moment

Running into the same problem. Gem isn't loading url_helpers for controller specs.

@stuarthannig @GSI it seems not a problem anymore with route_translator 5.0.5

I know it is a completely different version of rails, but if you have updated could you please confirm?

I would leave this open but I'm going to add "v4" somewhere

I'm going to close here because it does not appear to be a problem anymore