feat(mail): devise mailer respect user preferred host for any mail
This commit is contained in:
parent
d14fe83261
commit
3512e071d3
2 changed files with 31 additions and 0 deletions
|
@ -10,11 +10,22 @@ class DeviseUserMailer < Devise::Mailer
|
||||||
include PriorityDeliveryConcern
|
include PriorityDeliveryConcern
|
||||||
|
|
||||||
layout 'mailers/layout'
|
layout 'mailers/layout'
|
||||||
|
default from: "#{APPLICATION_NAME} <#{CONTACT_EMAIL}>"
|
||||||
|
|
||||||
def template_paths
|
def template_paths
|
||||||
['devise_mailer']
|
['devise_mailer']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Note: this devise hook (like any callback) is called *after* the action,
|
||||||
|
# because we use mailers with Mailer.action_name() syntax
|
||||||
|
# instead of parameterized Mailer.with().action_name.
|
||||||
|
# So any action using Current must manually call `configure_defaults_for_user`
|
||||||
|
def initialize_from_record(record)
|
||||||
|
configure_defaults_for_user(record)
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def confirmation_instructions(record, token, opts = {})
|
def confirmation_instructions(record, token, opts = {})
|
||||||
configure_defaults_for_user(record)
|
configure_defaults_for_user(record)
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,26 @@ RSpec.describe DeviseUserMailer, type: :mailer do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "reset password instructions" do
|
||||||
|
subject { described_class.reset_password_instructions(user, token) }
|
||||||
|
|
||||||
|
context "legacy domain" do
|
||||||
|
it "respect preferred domain" do
|
||||||
|
expect(header_value("From", subject.message)).to include(CONTACT_EMAIL)
|
||||||
|
expect(subject.message.to_s).to include("#{ENV.fetch("APP_HOST_LEGACY")}/users/password")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "new domain" do
|
||||||
|
let(:user) { create(:user, preferred_domain: :demarches_gouv_fr) }
|
||||||
|
|
||||||
|
it "respect preferred domain" do
|
||||||
|
expect(header_value("From", subject.message)).to include("@demarches.gouv.fr")
|
||||||
|
expect(subject.message.to_s).to include("#{ENV.fetch("APP_HOST")}/users/password")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def header_value(name, message)
|
def header_value(name, message)
|
||||||
|
|
Loading…
Reference in a new issue