mailers: fix last_week_overview crash when the overview is missing
This is because procedures may be unpublished between the time where the job is enqueued and the time the mailer is run Fix #3745
This commit is contained in:
parent
c0a9f103b3
commit
8ca683c515
2 changed files with 15 additions and 3 deletions
|
@ -21,12 +21,14 @@ class GestionnaireMailer < ApplicationMailer
|
||||||
|
|
||||||
def last_week_overview(gestionnaire)
|
def last_week_overview(gestionnaire)
|
||||||
email = gestionnaire.email
|
email = gestionnaire.email
|
||||||
@overview = gestionnaire.last_week_overview
|
|
||||||
headers['X-mailjet-campaign'] = 'last_week_overview'
|
|
||||||
@subject = 'Votre activité hebdomadaire'
|
@subject = 'Votre activité hebdomadaire'
|
||||||
|
@overview = gestionnaire.last_week_overview
|
||||||
|
|
||||||
|
if @overview.present?
|
||||||
|
headers['X-mailjet-campaign'] = 'last_week_overview'
|
||||||
mail(to: email, subject: @subject)
|
mail(to: email, subject: @subject)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def send_dossier(sender, dossier, recipient)
|
def send_dossier(sender, dossier, recipient)
|
||||||
@sender = sender
|
@sender = sender
|
||||||
|
|
|
@ -35,5 +35,15 @@ RSpec.describe GestionnaireMailer, type: :mailer do
|
||||||
subject { described_class.last_week_overview(gestionnaire) }
|
subject { described_class.last_week_overview(gestionnaire) }
|
||||||
|
|
||||||
it { expect(subject.body).to include('Votre activité hebdomadaire') }
|
it { expect(subject.body).to include('Votre activité hebdomadaire') }
|
||||||
|
|
||||||
|
context 'when the gestionnaire has no active procedures' do
|
||||||
|
let(:procedure) { nil }
|
||||||
|
let(:last_week_overview) { nil }
|
||||||
|
|
||||||
|
it 'doesn’t send the email' do
|
||||||
|
expect(subject.message).to be_kind_of(ActionMailer::Base::NullMail)
|
||||||
|
expect(subject.body).to be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue