amelioration(devise_mailer): oriente les mails de devise vers un fournisseur quand cela est configuré
This commit is contained in:
parent
2f43ffc940
commit
d535735155
2 changed files with 25 additions and 0 deletions
|
@ -5,6 +5,7 @@ class DeviseUserMailer < Devise::Mailer
|
|||
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
|
||||
include MailerMonitoringConcern
|
||||
layout 'mailers/layout'
|
||||
before_action :add_delivery_method, if: :forced_delivery?
|
||||
|
||||
def template_paths
|
||||
['devise_mailer']
|
||||
|
@ -16,4 +17,12 @@ class DeviseUserMailer < Devise::Mailer
|
|||
@prefill_token = opts[:prefill_token]
|
||||
super
|
||||
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
|
||||
|
|
16
spec/mailers/devise_user_mailer_spec.rb
Normal file
16
spec/mailers/devise_user_mailer_spec.rb
Normal 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
|
Loading…
Reference in a new issue