Merge pull request #9279 from colinux/fix-email-default-template
Correctif: utilise le template d'email de notification par défaut quand la démarche n'a pas personnalisé le sien
This commit is contained in:
commit
6fa7ed1c1f
3 changed files with 28 additions and 15 deletions
|
@ -34,12 +34,12 @@ module MailTemplateConcern
|
||||||
before_save :update_rich_body
|
before_save :update_rich_body
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
class_methods do
|
||||||
def default_for_procedure(procedure)
|
def default_for_procedure(procedure)
|
||||||
template_name = default_template_name_for_procedure(procedure)
|
template_name = default_template_name_for_procedure(procedure)
|
||||||
rich_body = ActionController::Base.render template: template_name
|
rich_body = ActionController::Base.render template: template_name
|
||||||
trix_rich_body = rich_body.gsub(/(?<!^|[.-])(?<!<\/strong>)\n/, ' ')
|
trix_rich_body = rich_body.gsub(/(?<!^|[.-])(?<!<\/strong>)\n/, ' ')
|
||||||
new(subject: const_get(:DEFAULT_SUBJECT), rich_body: trix_rich_body, procedure: procedure)
|
new(subject: const_get(:DEFAULT_SUBJECT), body: trix_rich_body, rich_body: trix_rich_body, procedure: procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_template_name_for_procedure(procedure)
|
def default_template_name_for_procedure(procedure)
|
||||||
|
|
|
@ -1,24 +1,37 @@
|
||||||
RSpec.describe NotificationMailer, type: :mailer do
|
RSpec.describe NotificationMailer, type: :mailer do
|
||||||
let(:administrateur) { create(:administrateur) }
|
let(:administrateur) { create(:administrateur) }
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:procedure) { create(:simple_procedure) }
|
let(:procedure) { create(:simple_procedure, :with_service) }
|
||||||
|
|
||||||
describe 'send_en_construction_notification' do
|
describe 'send_en_construction_notification' do
|
||||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, user: user, procedure: procedure) }
|
||||||
let(:email_template) { create(:initiated_mail, subject: 'Email subject', body: 'Your dossier was received. Thanks.') }
|
|
||||||
|
|
||||||
|
subject(:mail) { described_class.send_en_construction_notification(dossier) }
|
||||||
|
|
||||||
|
let(:body) { (mail.html_part || mail).body }
|
||||||
|
|
||||||
|
context "without custom template" do
|
||||||
|
it 'renders default template' do
|
||||||
|
expect(mail.subject).to eq("Votre dossier nº #{dossier.id} a bien été déposé (#{procedure.libelle})")
|
||||||
|
expect(body).to include("Votre dossier nº #{dossier.id}")
|
||||||
|
expect(body).to include(procedure.service.nom)
|
||||||
|
expect(mail.attachments.first.filename).to eq("attestation-de-depot.pdf")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a custom template" do
|
||||||
|
let(:email_template) { create(:initiated_mail, subject: 'Email subject', body: 'Your dossier was received. Thanks.') }
|
||||||
before do
|
before do
|
||||||
dossier.procedure.initiated_mail = email_template
|
dossier.procedure.initiated_mail = email_template
|
||||||
end
|
end
|
||||||
|
|
||||||
subject(:mail) { described_class.send_en_construction_notification(dossier) }
|
|
||||||
|
|
||||||
it 'renders the template' do
|
it 'renders the template' do
|
||||||
expect(mail.subject).to eq('Email subject')
|
expect(mail.subject).to eq('Email subject')
|
||||||
expect((mail.html_part || mail).body).to include('Your dossier was received')
|
expect(body).to include('Your dossier was received')
|
||||||
expect(mail.attachments.first.filename).to eq("attestation-de-depot.pdf")
|
expect(mail.attachments.first.filename).to eq("attestation-de-depot.pdf")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'send_en_instruction_notification' do
|
describe 'send_en_instruction_notification' do
|
||||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||||
|
|
|
@ -1019,7 +1019,7 @@ describe Procedure do
|
||||||
|
|
||||||
procedure.reset_draft_revision!
|
procedure.reset_draft_revision!
|
||||||
|
|
||||||
expect { published_tdc.reload }.not_to raise_error(ActiveRecord::RecordNotFound)
|
expect { published_tdc.reload }.not_to raise_error
|
||||||
expect { draft_tdc.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
expect { draft_tdc.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue