do not ask for avis if the dossier is absent
This commit is contained in:
parent
2730fac40d
commit
fde433a7cf
2 changed files with 15 additions and 5 deletions
|
@ -5,10 +5,12 @@ class AvisMailer < ApplicationMailer
|
||||||
layout 'mailers/layout'
|
layout 'mailers/layout'
|
||||||
|
|
||||||
def avis_invitation(avis)
|
def avis_invitation(avis)
|
||||||
@avis = avis
|
if avis.dossier.present?
|
||||||
email = @avis.expert&.email
|
@avis = avis
|
||||||
subject = "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})"
|
email = @avis.expert&.email
|
||||||
|
subject = "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})"
|
||||||
|
|
||||||
mail(to: email, subject: subject)
|
mail(to: email, subject: subject)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe AvisMailer, type: :mailer do
|
||||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
|
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
|
||||||
let(:avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') }
|
let(:avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') }
|
||||||
|
|
||||||
subject { described_class.avis_invitation(avis) }
|
subject { described_class.avis_invitation(avis.reload) }
|
||||||
|
|
||||||
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
|
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
|
||||||
it { expect(subject.body).to have_text("Vous avez été invité par\r\n#{avis.claimant.email}\r\nà donner votre avis sur le dossier nº #{avis.dossier.id} de la démarche :\r\n#{avis.dossier.procedure.libelle}") }
|
it { expect(subject.body).to have_text("Vous avez été invité par\r\n#{avis.claimant.email}\r\nà donner votre avis sur le dossier nº #{avis.dossier.id} de la démarche :\r\n#{avis.dossier.procedure.libelle}") }
|
||||||
|
@ -16,5 +16,13 @@ RSpec.describe AvisMailer, type: :mailer do
|
||||||
context 'when the recipient is not already registered' do
|
context 'when the recipient is not already registered' do
|
||||||
it { expect(subject.body).to include(sign_up_expert_avis_url(avis.dossier.procedure.id, avis.id, avis.expert.email)) }
|
it { expect(subject.body).to include(sign_up_expert_avis_url(avis.dossier.procedure.id, avis.id, avis.expert.email)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the dossier has been deleted before the avis was sent' do
|
||||||
|
before { dossier.update(hidden_at: Time.zone.now) }
|
||||||
|
|
||||||
|
it 'doesn’t send the email' do
|
||||||
|
expect(subject.body).to be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue