Always reload routes in UrlHelpers #2210
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
We are upgrading to Rails 8 and the generated RBIs for
GeneratedUrlHelpersModule
andGeneratedPathHelpersModule
did not include any of our configured routes. The previous version of theUrlHelpers
compiler links to rails/rails#52012, so I think the change was made to anticipate lazy loaded routes, but it does not seem to work in practice.Implementation
Rails.application.reload_routes!
produced the result I was looking for and I found that this also worked in Rails 7.Tests
The old code did not break tests when CURRENT_RAILS_VERSION was set to 7.1 or 8.0.0, so some guidance on how to write a test for this would be appreciated. I am surprised that these tests weren't breaking.