Skip to content

Commit

Permalink
Make Devise.mappings work with lazy loaded routes.
Browse files Browse the repository at this point in the history
Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments.
However, Devise's mappings are built during the routes loading phase.
To ensure it works correctly, we need to load the routes first before accessing @@mappings.
  • Loading branch information
nashby committed Nov 24, 2024
1 parent 0f514f1 commit 3c05982
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,14 @@ module Test
# PRIVATE CONFIGURATION

# Store scopes mappings.
mattr_reader :mappings
@@mappings = {}
def self.mappings
# Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments.
# However, Devise's mappings are built during the routes loading phase.
# To ensure it works correctly, we need to load the routes first before accessing @@mappings.
Rails.application.try(:reload_routes_unless_loaded)
@@mappings
end

# OmniAuth configurations.
mattr_reader :omniauth_configs
Expand Down

0 comments on commit 3c05982

Please sign in to comment.