diff --git a/lib/devise.rb b/lib/devise.rb index 3d9dc7886..5b7417ed6 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -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