fix wrong encoding of special character in email notification subject

This commit is contained in:
Lisa Durand 2023-03-31 16:58:41 +02:00
parent 04b17e8299
commit e1260a3df8
2 changed files with 18 additions and 1 deletions

View file

@ -26,7 +26,7 @@ class NotificationMailer < ApplicationMailer
attachments[@attachment[:filename]] = @attachment[:content] if @attachment.present? attachments[@attachment[:filename]] = @attachment[:content] if @attachment.present?
I18n.with_locale(@dossier.user_locale) do I18n.with_locale(@dossier.user_locale) do
mail(subject: @subject, to: @email, template_name: 'send_notification') mail(subject: Nokogiri::HTML.parse(@subject).text, to: @email, template_name: 'send_notification')
end end
end end

View file

@ -124,4 +124,21 @@ RSpec.describe NotificationMailer, type: :mailer do
it { expect(mail.subject.length).to be <= 100 } it { expect(mail.subject.length).to be <= 100 }
end end
end end
describe 'subject with apostrophe' do
let(:procedure) { create(:simple_procedure, libelle: "Mon titre avec l'apostrophe") }
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_service, user: user, procedure: procedure) }
let(:email_template) { create(:closed_mail, subject:, body: 'Your dossier was accepted. Thanks.') }
before do
dossier.procedure.closed_mail = email_template
end
subject(:mail) { described_class.send_accepte_notification(dossier) }
context "subject has a special character" do
let(:subject) { '--libellé démarche--' }
it { expect(mail.subject).to eq("Mon titre avec l'apostrophe") }
end
end
end end