Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,8 @@ 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
9 changes: 9 additions & 0 deletions lib/devise/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,14 @@ class Engine < ::Rails::Engine
Rails.autoloaders.main.ignore("#{root}/app/mailers/devise/mailer.rb")
end
end

# 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, so we need to ensure
# routes are eagerly loaded by reverting the route set class back to the default.
initializer "devise.make_routes_eager_load", after: :make_routes_lazy, before: :add_routing_paths do |app|
if app.config.respond_to?(:route_set_class)
app.config.route_set_class = ActionDispatch::Routing::RouteSet
end
end
end
end
Loading