Merge pull request #6357 from tchak/fix-false-positive-unspecified-tags-messages

Fix false positive unspecified tags messages
This commit is contained in:
Paul Chavard 2021-07-22 11:23:35 +02:00 committed by GitHub
commit 99b836da2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 26 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

@ -95,15 +95,8 @@ class Champ < ApplicationRecord
end
def blank?
case type_de_champ.type_champ
when TypeDeChamp.type_champs.fetch(:carte)
geo_areas.blank? || value == '[]'
when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
value.blank? || value == '[]'
else
value.blank?
end
end
def search_terms
[to_s]

View file

@ -109,6 +109,10 @@ class Champs::CarteChamp < Champ
nil
end
def blank?
geo_areas.blank?
end
private
def selection_utilisateur_legacy_geometry

View file

@ -62,6 +62,10 @@ class Champs::MultipleDropDownListChamp < Champ
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
end
def blank?
selected_options.blank?
end
private
def format_before_save

View file

@ -30,8 +30,8 @@ class Champs::RepetitionChamp < Champ
end
end
def mandatory_and_blank?
mandatory? && champs.empty?
def blank?
champs.empty?
end
def search_terms

View file

@ -176,7 +176,11 @@ FactoryBot.define do
factory :champ_repetition, class: 'Champs::RepetitionChamp' do
type_de_champ { association :type_de_champ_repetition, procedure: dossier.procedure }
after(:build) do |champ_repetition, _evaluator|
transient do
rows { 2 }
end
after(:build) do |champ_repetition, evaluator|
types_de_champ = champ_repetition.type_de_champ.types_de_champ
existing_type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' }
type_de_champ_text = existing_type_de_champ_text || build(
@ -195,13 +199,13 @@ FactoryBot.define do
)
champ_repetition.type_de_champ.types_de_champ << [type_de_champ_text, type_de_champ_number]
evaluator.rows.times do |row|
champ_repetition.champs << [
build(:champ_text, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_text, parent: champ_repetition),
build(:champ_number, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_number, parent: champ_repetition),
build(:champ_text, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_text, parent: champ_repetition),
build(:champ_number, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition)
build(:champ_text, dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ_text, parent: champ_repetition),
build(:champ_number, dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ_number, parent: champ_repetition)
]
end
end
trait :without_champs do
after(:build) do |champ_repetition, _evaluator|

View file

@ -11,16 +11,32 @@ shared_examples 'champ_spec' do
context 'when carte mandatory and blank' do
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
let(:value) { '[]' }
let(:champ) { build(:champ_carte, type_de_champ: type_de_champ, value: value) }
let(:value) { nil }
it { expect(champ.mandatory_and_blank?).to be(true) }
end
context 'when multiple_drop_down_list mandatory and blank' do
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
let(:champ) { build(:champ_multiple_drop_down_list, type_de_champ: type_de_champ, value: value) }
let(:value) { '[]' }
it { expect(champ.mandatory_and_blank?).to be(true) }
end
context 'when repetition blank' do
let(:type_de_champ) { build(:type_de_champ_repetition) }
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ, rows: 0) }
it { expect(champ.blank?).to be(true) }
end
context 'when repetition not blank' do
let(:type_de_champ) { build(:type_de_champ_repetition) }
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ) }
it { expect(champ.blank?).to be(false) }
end
context 'when not blank' do
let(:value) { 'yop' }
it { expect(champ.mandatory_and_blank?).to be(false) }

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) { [] }