From c60c58ff8bc37d67530a806b1cd1ac741eac00e5 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 6 Apr 2018 16:21:48 +0200 Subject: [PATCH] Fix issues spotted by @fredZen in #1802 --- app/models/attestation_template.rb | 3 +++ app/models/dossier.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index aeb980d79..1e4fd3de0 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -50,6 +50,9 @@ class AttestationTemplate < ApplicationRecord def used_tags delimiters_regex = /--(?((?!--).)*)--/ + # We can't use flat_map as scan will return 3 levels of array, + # using flat_map would give us 2, whereas flatten will + # give us 1, which is what we want [title, body] .map { |str| str.scan(delimiters_regex) } .flatten diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 89f564cce..2ba5fddc7 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -286,7 +286,7 @@ class Dossier < ApplicationRecord def unspecified_attestation_champs attestation_template = procedure.attestation_template - if attestation_template.present? && attestation_template.activated? + if attestation_template&.activated? attestation_template.unspecified_champs_for_dossier(self) else [] @@ -294,7 +294,7 @@ class Dossier < ApplicationRecord end def build_attestation - if procedure.attestation_template.present? && procedure.attestation_template.activated? + if procedure.attestation_template&.activated? procedure.attestation_template.attestation_for(self) end end