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
How do I test routes? #27
Comments
This might be related to my issue #26. There is some information out there for a few fixes: However, it didn't help my particular situation out that much. |
I ended up using rails' default way to translate routes (seeing I was only translating actions anyway):
So, I'm not actually using route_translator anymore. Might be useful to you too, @astjohn. |
+1 Gem seems to work in production, but in test any _path or _url calls without explicit language code cause Any known solutions so far? |
@GSI, you could try giving my fork a try on the "fix_rendered_paths" branch. |
@astjohn, thanks for the hint. I'd already tried your fork, but the same tests fail with the same error messages like with the original gem. I suppose it's working for you. Any idea how your setup might differ? |
@GSI, hm... not sure. Can you please double check that you're using the branch instead of master on my fork? Your Gemfile should look something like like the following:
Then of course bundle install and re-start your server. |
@astjohn that's exactly what I have in my Gemfile. I also tried adding the exact ref just to be sure. I note that you write "re-start your server" - to clarify: production works fine, but with |
@GSI, I'm not sure. I use rspec most of the time, but in my controller tests, assertions on redirects using _path seem to be working well. There's nothing special about our setup, and we have some pretty complicated routes. The translated and un-translated routes all seem to be working well. I'm not sure what else it can be. Sorry I'm all out of insights. |
@enriclluelles, any idea on this? |
I published a Rails 4.0.2 project that reproduces the error: When you check it out and run "rake test", you should see the same error as shown in the README. When removing the line "localized do" (and it's corresponding "end") from config/routes.rb, the "rake test" command succeeds. |
There's a bounty for solving this on oDesk now (https://www.odesk.com/jobs/~014df4f3bce62bb002). |
@GSI, With the branch I stated above, I have no issues. Here is an snipped from one of our controller tests:
That works fine and I can't think of how unit test might be different than rspec in this scenario. Sorry I can't be of much more help, but it works perfectly fine for me in all environments, including test. (In your example app, you don't have the branch specified for my repo/fix.) |
Thank you for the update @astjohn. I've checked out your branch in the test project (https://github.com/GSI/route_translator_reproduce_issue-27). The problem persists. Maybe it's Devise-related ... does your project use Devise? |
@GSI, yes. We use Devise so unfortunately, I don't think that's it. However, I would go ahead and add a test model, controller, and routes for something separate to be sure. If you have time, try adding and setting up rspec as well to see if there are any differences there (also a long shot). |
Thanks to @mohamagdy for solving this issue within the PR #45 |
PR #45 have been merged into master. All tests are green but it will help if you can test this new route_translator in your apps before we release it. |
Whenever I declare my routes adding localization
my generated controller tests all fail
This happens even if I only use english as
config.i18n.available_locales
andconfig.i18n.default_locale
. But whenever I remove the localized block, all tests pass.Is there a way I can test those routes with
get :action
?The text was updated successfully, but these errors were encountered: