Skip to content

Commit af112a2

Browse files
committed
Fix Zeitwerk autoloading when ActionMailer is not present.
When ActionMailer is not defined we have empty app/mailers/devise/mailer.rb file and Zeitwerk doesn't like that and errors with ``` expected file app/mailers/devise/mailer.rb to define constant Devise::Mailer ``` The fix is to tell Zeitwerk to ignore that file if ActionMailer constant if not defined. I tried to write a spec for it but since specs are run in the same process it's hard to have two Rails applications where one of them has ActionMailer define and the seconds one doesn't.
1 parent 90a3fa8 commit af112a2

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
* Add Rails 8 support.
2020
- Routes are lazy-loaded by default in test and development environments now so Devise loads them before `Devise.mappings` call.
2121
22+
* bug fixes
23+
* Make `Devise` work without `ActionMailer` when `Zeitwerk` autoloader is used.
24+
2225
Please check [4-stable](https://github.com/heartcombo/devise/blob/4-stable/CHANGELOG.md)
2326
for previous changes.

lib/devise/rails.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,11 @@ class Engine < ::Rails::Engine
4747
)
4848
end
4949
end
50+
51+
initializer "devise.configure_zeitwerk" do
52+
if Rails.autoloaders.zeitwerk_enabled? && !defined?(ActionMailer)
53+
Rails.autoloaders.main.ignore("#{root}/app/mailers/devise/mailer.rb")
54+
end
55+
end
5056
end
5157
end

0 commit comments

Comments
 (0)