From 7217b2decaaf2091280ea51beacc1f61d4de756d Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 17 Nov 2024 12:10:30 +0100 Subject: [PATCH] Fix Zeitwerk autoloading when ActionMailer is not present. --- lib/devise/rails.rb | 6 ++++++ test/zeitwerk_loader_test.rb | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/zeitwerk_loader_test.rb diff --git a/lib/devise/rails.rb b/lib/devise/rails.rb index dad9e86dc..b5738853f 100644 --- a/lib/devise/rails.rb +++ b/lib/devise/rails.rb @@ -47,5 +47,11 @@ class Engine < ::Rails::Engine ) end end + + initializer "devise.configure_zeitwerk" do + if Rails.autoloaders.zeitwerk_enabled? && !defined?(ActionMailer) + Rails.autoloaders.main.ignore("#{root}/app/mailers/devise/mailer.rb") + end + end end end diff --git a/test/zeitwerk_loader_test.rb b/test/zeitwerk_loader_test.rb new file mode 100644 index 000000000..a21cf63a4 --- /dev/null +++ b/test/zeitwerk_loader_test.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +ENV["RAILS_ENV"] = 'test' + +require 'rails' +require 'rails/test_help' + +require 'devise' + +class RailsTest < ActiveSupport::TestCase + test 'boot without ActionMailer' do + class MinimalApp < Rails::Application + config.root = __dir__ + config.eager_load = false + config.active_support.to_time_preserves_timezone = :zone + end + + Devise.setup do |config| + config.parent_controller = 'ActionController::Base' + end + + MinimalApp.initialize! + MinimalApp.eager_load! + end +end