fix(mail): use default template when no custom template was found
This commit is contained in:
parent
e90093cc69
commit
1da1e67067
2 changed files with 26 additions and 13 deletions
|
@ -34,12 +34,12 @@ module MailTemplateConcern
|
|||
before_save :update_rich_body
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
class_methods do
|
||||
def default_for_procedure(procedure)
|
||||
template_name = default_template_name_for_procedure(procedure)
|
||||
rich_body = ActionController::Base.render template: template_name
|
||||
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
|
||||
|
||||
def default_template_name_for_procedure(procedure)
|
||||
|
|
|
@ -1,24 +1,37 @@
|
|||
RSpec.describe NotificationMailer, type: :mailer do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:simple_procedure) }
|
||||
let(:procedure) { create(:simple_procedure, :with_service) }
|
||||
|
||||
describe 'send_en_construction_notification' do
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:email_template) { create(:initiated_mail, subject: 'Email subject', body: 'Your dossier was received. Thanks.') }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, user: user, procedure: procedure) }
|
||||
|
||||
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
|
||||
dossier.procedure.initiated_mail = email_template
|
||||
end
|
||||
|
||||
subject(:mail) { described_class.send_en_construction_notification(dossier) }
|
||||
|
||||
it 'renders the template' do
|
||||
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")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'send_en_instruction_notification' do
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
|
|
Loading…
Reference in a new issue