From 70f7ebdf560559e57a4ed21f295a4aa1c47e7604 Mon Sep 17 00:00:00 2001 From: Apostolos Stergiakis Date: Mon, 9 Nov 2026 09:47:26 +0200 Subject: [PATCH] Fix uninitialized constant CustomDeviseMailer when inviting a user in a cold-loaded process (#5745) Bump devise_invitable 2.0.13 -> 2.0.14. 2.0.13's :action_mailer load hook resolved Devise.mailer while CustomDeviseMailer was still being autoloaded, so the first invite in a non-eager-loaded process failed. 2.0.14 (scambra/devise_invitable#929) contains only that fix. Adds a spec that boots a fresh non-eager-loaded process, since CI eager-loads and hides the failure. Resolves #5745 --- Gemfile.lock | 2 +- spec/lib/custom_devise_mailer_load_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 spec/lib/custom_devise_mailer_load_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index c83ef6b9fd..283cddcf82 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -202,7 +202,7 @@ GEM railties (>= 7.0) responders warden (~> 1.2.3) - devise_invitable (2.0.13) + devise_invitable (2.0.14) actionmailer (>= 5.0) devise (>= 4.6) diff-lcs (1.6.2) diff --git a/spec/lib/custom_devise_mailer_load_spec.rb b/spec/lib/custom_devise_mailer_load_spec.rb new file mode 100644 index 0000000000..ad6fac4cec --- /dev/null +++ b/spec/lib/custom_devise_mailer_load_spec.rb @@ -0,0 +1,16 @@ +require "open3" + +# Autoloading CustomDeviseMailer in a fresh process used to raise +# "uninitialized constant CustomDeviseMailer" (#5745): devise_invitable 2.0.13's +# :action_mailer load hook resolved Devise.mailer while the class was still loading +# (fixed in 2.0.14, scambra/devise_invitable#929). +# CI eager-loads, which hides it, so this boots a separate non-eager-loaded process. +RSpec.describe "CustomDeviseMailer cold load" do + it "resolves Devise.mailer when autoloaded first in a fresh process" do + env = {"RAILS_ENV" => "test", "CI" => nil} + output, status = Open3.capture2e(env, "bin/rails", "runner", "puts Devise.mailer.name", chdir: Rails.root.to_s) + + expect(status).to be_success, output + expect(output.lines.map(&:strip)).to include("CustomDeviseMailer") + end +end