-
Notifications
You must be signed in to change notification settings - Fork 143
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
Unlocalized route path does not work in non-feature specs #140
Comments
I think it depends on
I would say that Relevant code: https://github.com/enriclluelles/route_translator/blob/master/lib/route_translator/extensions/route_set.rb#L13 elsif RouteTranslator.config.generate_unlocalized_routes
add_route app, conditions, requirements, defaults, as, anchor
end Leaving this open for further discussion |
Thank you - this works, but then I am missing some untranslated named route helpers in my rspec tests - strangely, only in tests. In devel mode the routes exist and work. Example:
With generate_unlocalized_routes = true, |
Sorry but I cannot confirm RouteTranslator.config do |config|
config.force_locale = true
end
Could you please provide a failing test case or application? |
Will do. It only fails in my rspec tests when I use the helpers, not in the console or in the app. Very strange. |
I'm also using rspec tests and I got the issue. require 'spec_helper'
describe 'Route translator' do
it "shows localized and unlocalized routes" do
visit press_releases_path
visit press_releases_en_path
visit press_releases_it_path
end
end Results:
describe 'Route translator', type: :feature do
it "shows localized and unlocalized routes" do
visit press_releases_path
visit press_releases_en_path
visit press_releases_it_path
end
end Results:
Please try with |
@jensb is it possible to use url helpers outside feature specs? This question is not related to route_translator |
In my controller specs, I But the routing issue gets even stranger - in development mode |
any solution for this yet? |
|
I know last post was several years ago, but in case anyone runs into this again, it seems to be that the issue arrises due to not mixing in the dynamically defined unlocalized route helpers into the base classes of the testing suite, which happens here. To get these methods to work on specs that do not inherit from
I've currently modified this to be:
Hope this helps, if needed. |
@monteverdetico thanks for the heads-up Could you please provide a use case when you need to use |
@tagliala no problem. In our current use case it is for testing modules that are generally mixed into a view / controller context; or, testing models that need url helper methods available to them (used in background jobs). So it's not to use It's possible we could treat some of the url helpers as a black box and stub them; or test the helper modules in the context of a request, but that refactor currently wasn't in the scope of work given our constraints. Reference to the above in code: monteverdetico@1542b1e I had a simple spec written, but felt it was slightly hacky as I had to create the modules, classes as a namespace in the test to ensure that the methods were being mixed in. Test looked very similar to the tests for the Hope this clarifies the use case a bit, but let me know if you have any other questions. |
What can be the reason if I have route helpers that - when called with a specific locale set - always return the default translation, not the translated route? E.g.
Settings:
Using Rails 4.2. Please advise where I should start to debug, I'd like to help track this and will provide a patch if I find a bug. Thank you!
The text was updated successfully, but these errors were encountered: