From aa1cf6788bdc7583eee9fbe83b262ef5f80652de Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 10 Sep 2019 11:05:04 +0200 Subject: [PATCH] mailers: turn revert_to_instruction into a notification email --- app/mailers/dossier_mailer.rb | 9 +++++++-- .../notify_revert_to_instruction.html.haml | 8 +++++++- spec/mailers/dossier_mailer_spec.rb | 12 ++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index ce00ce63f..56ee3d288 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -60,8 +60,13 @@ class DossierMailer < ApplicationMailer def notify_revert_to_instruction(dossier) @dossier = dossier - @subject = "Votre dossier nº #{@dossier.id} est en train d'être réexaminé" + @service = dossier.procedure.service + @logo_url = attach_logo(dossier.procedure) - mail(to: dossier.user.email, subject: @subject) + subject = "Votre dossier nº #{@dossier.id} est en train d'être réexaminé" + + mail(from: NO_REPLY_EMAIL, to: dossier.user.email, subject: subject) do |format| + format.html { render layout: 'mailers/notifications_layout' } + end end end diff --git a/app/views/dossier_mailer/notify_revert_to_instruction.html.haml b/app/views/dossier_mailer/notify_revert_to_instruction.html.haml index 06518948e..f5b8caa5e 100644 --- a/app/views/dossier_mailer/notify_revert_to_instruction.html.haml +++ b/app/views/dossier_mailer/notify_revert_to_instruction.html.haml @@ -1,3 +1,6 @@ +- content_for :procedure_logo do + = render 'layouts/mailers/logo', url: @logo_url + %p Bonjour, @@ -13,4 +16,7 @@ email: = mail_to @dossier.procedure.service.email, @dossier.procedure.service.email -= render partial: "layouts/mailers/signature" += render 'layouts/mailers/signature' + +- content_for :footer do + = render 'layouts/mailers/service_footer', service: @service, dossier: @dossier diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index d965ad9c7..54fc52f91 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -67,4 +67,16 @@ RSpec.describe DossierMailer, type: :mailer do it { expect(subject.body).to include("n'a pas pu être supprimé") } it { expect(subject.body).to include(dossier.procedure.libelle) } end + + describe '.notify_revert_to_instruction' do + let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) } + + subject { described_class.notify_revert_to_instruction(dossier) } + + it { expect(subject.subject).to include('réexaminé') } + it { expect(subject.body).to include(dossier.procedure.libelle) } + it { expect(subject.body).to include(dossier_url(dossier)) } + + it_behaves_like 'a dossier notification' + end end