diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 74b79940b..0f4cd3ea9 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -48,7 +48,13 @@ class NotificationMailer < ApplicationMailer create_commentaire_for_notification(dossier, subject, body) - mail(subject: subject, to: email) { |format| format.html { body } } + @dossier = dossier + + mail(subject: subject, to: email) do |format| + # rubocop:disable Rails/OutputSafety + format.html { render(html: body.html_safe, layout: 'mailers/notification') } + # rubocop:enable Rails/OutputSafety + end end def create_commentaire_for_notification(dossier, subject, body) diff --git a/app/views/layouts/mailers/notification.html.haml b/app/views/layouts/mailers/notification.html.haml new file mode 100644 index 000000000..343b88da2 --- /dev/null +++ b/app/views/layouts/mailers/notification.html.haml @@ -0,0 +1,9 @@ += yield + +%p --- + +%p.footer + %strong + Merci de ne pas répondre à cet email. Pour vous adresser à votre administration, passez directement par votre + = succeed '.' do + = link_to 'messagerie', users_dossier_recapitulatif_url(@dossier), target: '_blank' diff --git a/app/views/notification_mailer/closed_mail.html.haml b/app/views/notification_mailer/closed_mail.html.haml index 9f4d08fc3..33d4866d2 100644 --- a/app/views/notification_mailer/closed_mail.html.haml +++ b/app/views/notification_mailer/closed_mail.html.haml @@ -12,9 +12,3 @@ %p L'équipe demarches-simplifiees.fr - -%p - — - -%p - Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/notification_mailer/closed_mail_with_attestation.html.haml b/app/views/notification_mailer/closed_mail_with_attestation.html.haml index e1851d5db..7d5d34495 100644 --- a/app/views/notification_mailer/closed_mail_with_attestation.html.haml +++ b/app/views/notification_mailer/closed_mail_with_attestation.html.haml @@ -15,9 +15,3 @@ %p L'équipe demarches-simplifiees.fr - -%p - — - -%p - Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/notification_mailer/initiated_mail.html.haml b/app/views/notification_mailer/initiated_mail.html.haml index 3d80a35bd..f8fda2710 100644 --- a/app/views/notification_mailer/initiated_mail.html.haml +++ b/app/views/notification_mailer/initiated_mail.html.haml @@ -12,9 +12,3 @@ %p L'équipe demarches-simplifiees.fr - -%p - — - -%p - Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/notification_mailer/received_mail.html.haml b/app/views/notification_mailer/received_mail.html.haml index b6c43df50..d85b4d3ba 100644 --- a/app/views/notification_mailer/received_mail.html.haml +++ b/app/views/notification_mailer/received_mail.html.haml @@ -9,9 +9,3 @@ %p L'équipe demarches-simplifiees.fr - -%p - — - -%p - Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/notification_mailer/refused_mail.html.haml b/app/views/notification_mailer/refused_mail.html.haml index e7503723e..9d7f90cd2 100644 --- a/app/views/notification_mailer/refused_mail.html.haml +++ b/app/views/notification_mailer/refused_mail.html.haml @@ -15,9 +15,3 @@ %p L'équipe demarches-simplifiees.fr - -%p - — - -%p - Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/notification_mailer/without_continuation_mail.html.haml b/app/views/notification_mailer/without_continuation_mail.html.haml index 4240a4e2a..ea57a3e90 100644 --- a/app/views/notification_mailer/without_continuation_mail.html.haml +++ b/app/views/notification_mailer/without_continuation_mail.html.haml @@ -15,9 +15,3 @@ %p L'équipe demarches-simplifiees.fr - -%p - — - -%p - Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index bd8d96902..c134835ad 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -18,11 +18,11 @@ RSpec.describe NotificationMailer, type: :mailer do describe '.send_notification' do let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') } - subject do + subject(:mail) do klass = Class.new(described_class) do # We’re testing the (private) method `NotificationMailer#send_notification`. # - # The standard trick to test a private method would be to `send(:send_notification`, but doesn’t work here, + # The standard trick to test a private method would be to `send(:send_notification)`, but doesn’t work here, # because ActionMailer does some magic to expose public instace methods as class methods. # So, we use inheritance instead to make the private method public for testing purposes. def send_notification(dossier, template) @@ -32,13 +32,15 @@ RSpec.describe NotificationMailer, type: :mailer do klass.send_notification(dossier, email_template) end - it { expect(subject.subject).to eq(email_template.subject_for_dossier) } - it { expect(subject.body).to eq(email_template.body_for_dossier) } + it { expect(mail.subject).to eq(email_template.subject_for_dossier) } + it { expect(mail.body).to include(email_template.body_for_dossier) } + it { expect(mail.body).to have_selector('.footer') } + it_behaves_like "create a commentaire not notified" end describe '.send_dossier_received' do - subject { described_class.send_dossier_received(dossier) } + subject(:mail) { described_class.send_dossier_received(dossier) } let(:email_template) { create(:received_mail) } before do @@ -46,8 +48,9 @@ RSpec.describe NotificationMailer, type: :mailer do end it do - expect(subject.subject).to eq(email_template.subject) - expect(subject.body).to eq(email_template.body) + expect(mail.subject).to eq(email_template.subject) + expect(mail.body).to include(email_template.body) + expect(mail.body).to have_selector('.footer') end it_behaves_like "create a commentaire not notified"