enriclluelles/route_translator

RSpec: cannot call non-localized routes name

james-em opened this issue · 5 comments

Configuration

config.force_locale = false
config.generate_unlocalized_routes = false

Steps to reproduce*

Use a named_path without the locale in the name in RSpec

home_path # crash in rspec, works in views outside test. I can do home_path(locale: "en")
home_en_path #works

Expected behavior*

Should behave just like outside specs.

Actual behavior*

It crashes

System configuration*

Rails version: 7.0.1
Ruby version: 3.0.1
Route Translator version: 12.1.0

Hi, could you please provide more details?

I need the version of RSpec, its configuration, and the type of the spec executed. A GitHub repository with a minimum reproducible test case would be appreciated

I think this may be related to #140

Hi, could you please provide more details?

I need the version of RSpec, its configuration, and the type of the spec executed. A GitHub repository with a minimum reproducible test case would be appreciated

I think this may be related to #140

All my gems are up to date and my specs are of type: :controller

    rspec-core (3.11.0)
      rspec-support (~> 3.11.0)
    rspec-expectations (3.11.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.11.0)
    rspec-mocks (3.11.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.11.0)
    rspec-rails (5.1.2)
      actionpack (>= 5.2)
      activesupport (>= 5.2)
      railties (>= 5.2)
      rspec-core (~> 3.10)
      rspec-expectations (~> 3.10)
      rspec-mocks (~> 3.10)
      rspec-support (~> 3.10)
    rspec-support (3.11.0)

It doesn't require any specific configuration. Let me know if a test repo is still required. I will try to find one hour to build one as I can't possibly share our client's projetcs

I will try to find one hour to build one as I can't possibly share our client's projetcs

Of course. Also, it should be a minimum reproducible test case, without extra gems and with the minimum amount of code to reproduce the issue

You can fork https://github.com/diowa/ruby3-rails7-bootstrap-heroku/ and add the minimum amount of code to the route_translator branch to reproduce the issue. It is using Ruby 3.1 but I do not think it will be an issue

Closing here because of missing feedback

Hi,

sorry I never came back but in case anyone is wondering the samething here is the fix I had

# spec/support/route_translator.rb

module AutomatedLocale
  extend ActiveSupport::Concern

  included do
    def process(action, method: "GET", params: nil, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil) # rubocop:disable Metrics/ParameterLists, Layout/LineLength
      params ||= {}
      params[:locale] = I18n.locale.to_s unless params.key?(:locale)
      super
    end
  end
end

ActionController::TestCase::Behavior.include AutomatedLocale