From 6a85094e1a95f43822750ca30635097e74fcdecd Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 22 Dec 2017 11:31:38 +0100 Subject: [PATCH 1/3] [#1110] Make processed_at date available for attestation generation --- app/controllers/backoffice/dossiers_controller.rb | 2 +- app/controllers/new_gestionnaire/dossiers_controller.rb | 2 +- spec/controllers/backoffice/dossiers_controller_spec.rb | 6 +++++- .../new_gestionnaire/dossiers_controller_spec.rb | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 205904f59..ad0f073be 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -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 diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index af2cead4c..1e45fe4ef 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -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 diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 2194a915f..d817aebca 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -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 diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index d53102803..2bb35d7a4 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -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 From ee109b24e30e763d2fe39b2ff588f73eb1a7f3d2 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 2 Jan 2018 17:29:11 +0100 Subject: [PATCH 2/3] =?UTF-8?q?[#1110]=20Port=20date=20de=20d=C3=A9cision?= =?UTF-8?q?=20tag=20from=20mail=20templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/tags_substitution_concern.rb | 14 ++++++++++++-- .../concern/tags_substitution_concern_spec.rb | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index 6beb0efb2..ef000a99f 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -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 diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 031f261cc..01cbcb3d5 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -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 From ad0462f7ff9c22cf1c05b4a2e4f8c04df8c842a5 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 4 Jan 2018 10:54:50 +0100 Subject: [PATCH 3/3] =?UTF-8?q?[#1110]=20Port=20libell=C3=A9=20proc=C3=A9d?= =?UTF-8?q?ure=20tag=20from=20mail=20templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/tags_substitution_concern.rb | 1 + spec/models/concern/tags_substitution_concern_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index ef000a99f..d0da15797 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -25,6 +25,7 @@ module TagsSubstitutionConcern { 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: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } }, { libelle: 'numéro du dossier', description: '', target: :id }] end diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 01cbcb3d5..51e512734 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -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) @@ -172,6 +173,12 @@ describe TagsSubstitutionConcern, type: :model do 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') }