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

Eager load routes (fixes failing test) #499

Merged
merged 2 commits into from
Oct 31, 2024
Merged

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Oct 31, 2024

@vinistock noticed the test route location returns the location for a valid route was failing if run in isolation.

@andyw8 andyw8 added the chore Chore task label Oct 31, 2024
@andyw8 andyw8 requested a review from a team as a code owner October 31, 2024 13:48
@andyw8 andyw8 force-pushed the andyw8/fix-failing-test branch from 048bead to d227981 Compare October 31, 2024 16:05
@andyw8
Copy link
Contributor Author

andyw8 commented Oct 31, 2024

After a little digging I found that if you call ::Rails.application.routes.named_routes then it's not populated. The reason the test was passing intermittently was because ::Rails.application.routes.routes calls ::Rails.application.reload_routes_unless_loaded as a side-effect.

I've updated the implementation to call that.

I'm wondering if this should be considered a bug in Rails...

dummy(dev)> ::Rails.application.routes.named_routes
=> 
#<Rails::Engine::LazyRouteSet::NamedRouteCollection:0x000000011d515518
 @path_helpers=#<Set: {}>,
 @path_helpers_module=#<Module:0x0000000101291ce0>,
 @routes={},
 @url_helpers=#<Set: {}>,
 @url_helpers_module=#<Module:0x0000000101291d80>>
dummy(dev)> ::Rails.application.reload_routes_unless_loaded
=> true
dummy(dev)> ::Rails.application.routes.named_routes
=> 
#<Rails::Engine::LazyRouteSet::NamedRouteCollection:0x000000011d515518
 @path_helpers=
  #<Set:
   {:rails_mailers_path,
    :rails_info_properties_path,
    :rails_info_routes_path,
    :rails_info_notes_path,
    :rails_info_path,
    :archive_users_path,
    :users_path,
    :new_user_path,

@andyw8 andyw8 force-pushed the andyw8/fix-failing-test branch from d227981 to 0f7c757 Compare October 31, 2024 16:10
@andyw8
Copy link
Contributor Author

andyw8 commented Oct 31, 2024

(I'll need to verify this against Rails 7)

@andyw8
Copy link
Contributor Author

andyw8 commented Oct 31, 2024

Updated for Rails 7.2 compatibility. Related: #500

@andyw8 andyw8 merged commit 6af704a into main Oct 31, 2024
28 checks passed
@andyw8 andyw8 deleted the andyw8/fix-failing-test branch October 31, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants