demarches-normaliennes/spec/mailers/gestionnaire_mailer_spec.rb
Pierre de La Morinerie 8ca683c515 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
2019-04-04 17:32:12 +02:00

49 lines
1.6 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

RSpec.describe GestionnaireMailer, type: :mailer do
describe '#send_dossier' do
let(:sender) { create(:gestionnaire) }
let(:recipient) { create(:gestionnaire) }
let(:dossier) { create(:dossier) }
subject { described_class.send_dossier(sender, dossier, recipient) }
it { expect(subject.body).to include('Bonjour') }
end
describe '#last_week_overview' do
let(:gestionnaire) { create(:gestionnaire) }
let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
let(:dossier) { create(:dossier) }
let(:last_week_overview) do
procedure_overview = double('po',
procedure: procedure,
created_dossiers_count: 0,
dossiers_en_construction_count: 1,
old_dossiers_en_construction: [dossier],
dossiers_en_construction_description: 'desc',
dossiers_en_instruction_count: 1,
old_dossiers_en_instruction: [dossier],
dossiers_en_instruction_description: 'desc')
{
start_date: Time.zone.now,
procedure_overviews: [procedure_overview]
}
end
before { allow(gestionnaire).to receive(:last_week_overview).and_return(last_week_overview) }
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