From 6ed7ae4b53c5866253949d4d08fb34e91b92ea43 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 6 Apr 2018 19:22:42 +0200 Subject: [PATCH] [Fix #1809] Handle non-champ tags in attestation --- app/models/attestation_template.rb | 4 +++- spec/models/dossier_spec.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index 1e4fd3de0..f1e90fb4c 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -27,7 +27,9 @@ class AttestationTemplate < ApplicationRecord used_tags.map do |used_tag| corresponding_champ = all_champs_with_libelle_index[used_tag] - corresponding_champ.value.blank? ? corresponding_champ : nil + if corresponding_champ && corresponding_champ.value.blank? + corresponding_champ + end end.compact end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 878a38fea..68a9b50c7 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -661,7 +661,7 @@ describe Dossier do # - with tag in body and tag in title # - with tag correponsing to a champ and an annotation privée # - with a dash in the champ libelle / tag - let(:title) { "voici --specified champ-in-title-- un --unspecified champ-in-title-- beau --specified annotation privée-in-title-- titre --unspecified annotation privée-in-title-- non" } + let(:title) { "voici --specified champ-in-title-- un --unspecified champ-in-title-- beau --specified annotation privée-in-title-- titre --unspecified annotation privée-in-title-- non --numéro du dossier--" } let(:body) { "voici --specified champ-in-body-- un --unspecified champ-in-body-- beau --specified annotation privée-in-body-- body --unspecified annotation privée-in-body-- non ?" } let(:attestation_template) { create(:attestation_template, title: title, body: body, activated: activated) }