amelioration(devise_mailer): oriente les mails de devise vers un fournisseur quand cela est configuré

This commit is contained in:
Martin 2023-01-11 09:44:39 +01:00 committed by LeSim
parent 2f43ffc940
commit d535735155
2 changed files with 25 additions and 0 deletions

View file

@ -5,6 +5,7 @@ class DeviseUserMailer < Devise::Mailer
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url` include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
include MailerMonitoringConcern include MailerMonitoringConcern
layout 'mailers/layout' layout 'mailers/layout'
before_action :add_delivery_method, if: :forced_delivery?
def template_paths def template_paths
['devise_mailer'] ['devise_mailer']
@ -16,4 +17,12 @@ class DeviseUserMailer < Devise::Mailer
@prefill_token = opts[:prefill_token] @prefill_token = opts[:prefill_token]
super super
end end
def add_delivery_method
headers[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER] = SafeMailer.forced_delivery_method
end
def forced_delivery?
SafeMailer&.forced_delivery_method.present?
end
end end

View file

@ -0,0 +1,16 @@
RSpec.describe DeviseUserMailer, type: :mailer do
let(:user) { create(:user) }
let(:token) { SecureRandom.hex }
describe '.confirmation_instructions' do
context 'without SafeMailer configured' do
subject { described_class.confirmation_instructions(user, token, opts = {}) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
end
context 'with SafeMailer configured' do
let(:forced_delivery_method) { :kikoo }
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
subject { described_class.confirmation_instructions(user, token, opts = {}) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
end
end
end