[#1110] Port date de décision tag from mail templates
This commit is contained in:
parent
6a85094e1a
commit
ee109b24e3
2 changed files with 26 additions and 2 deletions
|
@ -19,7 +19,12 @@ module TagsSubstitutionConcern
|
|||
end
|
||||
|
||||
def dossier_tags
|
||||
[{ libelle: 'motivation', description: '', target: :motivation },
|
||||
[{ libelle: 'motivation',
|
||||
description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite',
|
||||
target: :motivation },
|
||||
{ libelle: 'date de décision',
|
||||
description: 'Date de la décision d’acceptation, refus, ou classement sans suite',
|
||||
lambda: -> (d) { d.processed_at.present? ? d.processed_at.localtime.strftime('%d/%m/%Y') : '' } },
|
||||
{ libelle: 'numéro du dossier', description: '', target: :id }]
|
||||
end
|
||||
|
||||
|
@ -70,7 +75,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
|
||||
|
|
|
@ -164,6 +164,14 @@ 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 "match breaking and non breaking spaces" do
|
||||
before { dossier.champs.first.update_attributes(value: 'valeur') }
|
||||
|
||||
|
@ -194,4 +202,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
|
||||
|
|
Loading…
Reference in a new issue