Merge pull request #3746 from betagouv/fix-last-week-overview-mailer

Technique : corrige une exception dans les récapitulatifs hebdomadaires
This commit is contained in:
Pierre de La Morinerie 2019-04-04 17:39:55 +02:00 committed by GitHub
commit 04775582fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -21,11 +21,13 @@ class GestionnaireMailer < ApplicationMailer
def last_week_overview(gestionnaire)
email = gestionnaire.email
@overview = gestionnaire.last_week_overview
headers['X-mailjet-campaign'] = 'last_week_overview'
@subject = 'Votre activité hebdomadaire'
@overview = gestionnaire.last_week_overview
mail(to: email, subject: @subject)
if @overview.present?
headers['X-mailjet-campaign'] = 'last_week_overview'
mail(to: email, subject: @subject)
end
end
def send_dossier(sender, dossier, recipient)

View file

@ -35,5 +35,15 @@ RSpec.describe GestionnaireMailer, type: :mailer do
subject { described_class.last_week_overview(gestionnaire) }
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 'doesnt send the email' do
expect(subject.message).to be_kind_of(ActionMailer::Base::NullMail)
expect(subject.body).to be_blank
end
end
end
end