Fix false positive blank champ warnings

This commit is contained in:
Paul Chavard 2021-07-21 10:46:44 +02:00
parent ac0f50b488
commit 388fb39eb5
2 changed files with 4 additions and 8 deletions

View file

@ -39,16 +39,12 @@ class AttestationTemplate < ApplicationRecord
end
def unspecified_champs_for_dossier(dossier)
all_champs_with_libelle_index = (dossier.champs + dossier.champs_private)
.reduce({}) do |acc, champ|
acc[champ.libelle] = champ
acc
end
all_champs_with_libelle_index = (dossier.champs + dossier.champs_private).index_by { |champ| "tdc#{champ.stable_id}" }
used_tags.filter_map do |used_tag|
corresponding_champ = all_champs_with_libelle_index[used_tag]
if corresponding_champ && corresponding_champ.value.blank?
if corresponding_champ && corresponding_champ.blank?
corresponding_champ
end
end
@ -113,7 +109,7 @@ class AttestationTemplate < ApplicationRecord
# 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]
[normalize_tags(title), normalize_tags(body)]
.map { |str| str.scan(delimiters_regex) }
.flatten
end

View file

@ -564,7 +564,7 @@ describe Dossier do
describe "#unspecified_attestation_champs" do
let(:procedure) { create(:procedure, attestation_template: attestation_template, types_de_champ: types_de_champ, types_de_champ_private: types_de_champ_private) }
let(:dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
let(:types_de_champ) { [] }
let(:types_de_champ_private) { [] }