From d7dd027cb8888a5ad82973f4b0f0a8b80113a650 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 5 Sep 2018 15:15:16 +0200 Subject: [PATCH 1/3] mailer: improve naming in specs --- spec/mailers/notification_mailer_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index bd8d96902..c5c2be9bd 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -18,7 +18,7 @@ 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`. # @@ -32,13 +32,13 @@ 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 eq(email_template.body_for_dossier) } 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 +46,8 @@ 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 eq(email_template.body) end it_behaves_like "create a commentaire not notified" From 2a5a8cf621109955f51830c1ac27b4c3375e2e6c Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 5 Sep 2018 15:15:37 +0200 Subject: [PATCH 2/3] mailer: fix typo in spec --- spec/mailers/notification_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index c5c2be9bd..323946853 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -22,7 +22,7 @@ RSpec.describe NotificationMailer, type: :mailer 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) From b2f2e75f431ae7f17fe2ec5ebe99cc9596ce393e Mon Sep 17 00:00:00 2001 From: lucien mollard Date: Wed, 5 Sep 2018 13:25:47 +0000 Subject: [PATCH 3/3] mailer: add layout for notifications emails --- app/mailers/notification_mailer.rb | 8 +++++++- app/views/layouts/mailers/notification.html.haml | 9 +++++++++ app/views/notification_mailer/closed_mail.html.haml | 6 ------ .../closed_mail_with_attestation.html.haml | 6 ------ app/views/notification_mailer/initiated_mail.html.haml | 6 ------ app/views/notification_mailer/received_mail.html.haml | 6 ------ app/views/notification_mailer/refused_mail.html.haml | 6 ------ .../without_continuation_mail.html.haml | 6 ------ spec/mailers/notification_mailer_spec.rb | 7 +++++-- 9 files changed, 21 insertions(+), 39 deletions(-) create mode 100644 app/views/layouts/mailers/notification.html.haml 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 323946853..c134835ad 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -33,7 +33,9 @@ RSpec.describe NotificationMailer, type: :mailer do end it { expect(mail.subject).to eq(email_template.subject_for_dossier) } - it { expect(mail.body).to eq(email_template.body_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 @@ -47,7 +49,8 @@ RSpec.describe NotificationMailer, type: :mailer do it do expect(mail.subject).to eq(email_template.subject) - expect(mail.body).to eq(email_template.body) + expect(mail.body).to include(email_template.body) + expect(mail.body).to have_selector('.footer') end it_behaves_like "create a commentaire not notified"