Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSpec: cannot call non-localized routes name #267

Closed
james-em opened this issue Aug 4, 2022 · 5 comments
Closed

RSpec: cannot call non-localized routes name #267

james-em opened this issue Aug 4, 2022 · 5 comments

Comments

@james-em
Copy link

james-em commented Aug 4, 2022

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

@tagliala
Copy link
Collaborator

tagliala commented Aug 4, 2022

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

@james-em
Copy link
Author

james-em commented Aug 4, 2022

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

@tagliala
Copy link
Collaborator

tagliala commented Aug 5, 2022

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

@tagliala
Copy link
Collaborator

tagliala commented Aug 5, 2023

Closing here because of missing feedback

@tagliala tagliala closed this as completed Aug 5, 2023
@jamesst20
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants