Merge pull request #1174 from sgmap/fix_1110-port_mail_tags_to_attestation

Fix 1110 - 2. port mail tags to attestation
This commit is contained in:
gregoirenovel 2018-01-05 12:08:40 +01:00 committed by GitHub
commit d80eb7a02b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 6 deletions

View file

@ -123,8 +123,8 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
notice = "Dossier considéré comme sans suite."
template = dossier.procedure.without_continuation_mail_template
when "close"
dossier.attestation = dossier.build_attestation
dossier.accepte!
dossier.attestation = dossier.build_attestation
notice = "Dossier traité avec succès."
template = dossier.procedure.closed_mail_template
end

View file

@ -89,8 +89,8 @@ module NewGestionnaire
notice = "Dossier considéré comme sans suite."
template = procedure.without_continuation_mail_template
when "accepter"
dossier.attestation = dossier.build_attestation
dossier.accepte!
dossier.attestation = dossier.build_attestation
notice = "Dossier traité avec succès."
template = procedure.closed_mail_template
end

View file

@ -19,7 +19,13 @@ module TagsSubstitutionConcern
end
def dossier_tags
[{ libelle: 'motivation', description: '', target: :motivation },
[{ libelle: 'motivation',
description: 'Motivation facultative associée à la décision finale dacceptation, refus ou classement sans suite',
target: :motivation },
{ libelle: 'date de décision',
description: 'Date de la décision dacceptation, refus, ou classement sans suite',
lambda: -> (d) { d.processed_at.present? ? d.processed_at.localtime.strftime('%d/%m/%Y') : '' } },
{ libelle: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } },
{ libelle: 'numéro du dossier', description: '', target: :id }]
end
@ -70,7 +76,12 @@ module TagsSubstitutionConcern
def replace_tags_with_values_from_data(text, tags, data)
if data.present?
tags.inject(text) do |acc, tag|
replace_tag(acc, tag, data.send(tag[:target]))
if tag.key?(:target)
value = data.send(tag[:target])
else
value = tag[:lambda].(data)
end
replace_tag(acc, tag, value)
end
else
text

View file

@ -358,11 +358,15 @@ describe Backoffice::DossiersController, type: :controller do
subject { post :process_dossier, params: { process_action: "close", dossier_id: dossier_id, dossier: { motivation: "Yallah" }}}
before do
Timecop.freeze(DateTime.now)
expect_any_instance_of(AttestationTemplate)
.to receive(:attestation_for)
.with(have_attributes(motivation: "Yallah"))
.with(have_attributes(motivation: "Yallah", processed_at: DateTime.now))
end
after { Timecop.return }
it { subject }
end
end

View file

@ -237,11 +237,15 @@ describe NewGestionnaire::DossiersController, type: :controller do
end
before do
Timecop.freeze(DateTime.now)
expect_any_instance_of(AttestationTemplate)
.to receive(:attestation_for)
.with(have_attributes(motivation: "Yallah"))
.with(have_attributes(motivation: "Yallah", processed_at: DateTime.now))
end
after { Timecop.return }
it { subject }
end
end

View file

@ -5,6 +5,7 @@ describe TagsSubstitutionConcern, type: :model do
let(:procedure) do
create(:procedure,
libelle: 'Une magnifique procédure',
types_de_champ: types_de_champ,
types_de_champ_private: types_de_champ_private,
for_individual: for_individual)
@ -164,6 +165,20 @@ describe TagsSubstitutionConcern, type: :model do
end
end
context "when the template has a date de décision tag" do
let(:template) { '--date de décision--' }
before { dossier.accepte! }
it { is_expected.to eq(DateTime.now.localtime.strftime('%d/%m/%Y')) }
end
context "when the template has a libellé procédure tag" do
let(:template) { 'body --libellé procédure--' }
it { is_expected.to eq('body Une magnifique procédure') }
end
context "match breaking and non breaking spaces" do
before { dossier.champs.first.update_attributes(value: 'valeur') }
@ -194,4 +209,10 @@ describe TagsSubstitutionConcern, type: :model do
end
end
end
describe 'tags' do
subject { template_concern.tags }
it { is_expected.to include(include({ libelle: 'date de décision' })) }
end
end