diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index 2c7a82266..cb2464c93 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -11,13 +11,6 @@ module TagsSubstitutionConcern target: :motivation, available_for_states: Dossier::TERMINE }, - { - libelle: 'groupe instructeur', - description: 'Le groupe instructeur en charge du dossier', - lambda: -> (d) { d.groupe_instructeur.label }, - available?: -> (d) { d.procedure.routee? }, - available_for_states: Dossier::SOUMIS - }, { libelle: 'date de dépôt', description: 'Date du passage en construction du dossier par l’usager', @@ -137,6 +130,15 @@ module TagsSubstitutionConcern } ] + ROUTAGE_TAGS = [ + { + libelle: 'groupe instructeur', + description: 'Le groupe instructeur en charge du dossier', + lambda: -> (d) { d.groupe_instructeur.label }, + available_for_states: Dossier::SOUMIS + } + ] + def tags if procedure.for_individual? identity_tags = INDIVIDUAL_TAGS @@ -144,7 +146,12 @@ module TagsSubstitutionConcern identity_tags = ENTREPRISE_TAGS end - filter_tags(identity_tags + dossier_tags + champ_public_tags + champ_private_tags) + routage_tags = [] + if procedure.routee? + routage_tags = ROUTAGE_TAGS + end + + filter_tags(identity_tags + dossier_tags + champ_public_tags + champ_private_tags + routage_tags) end private @@ -214,6 +221,7 @@ module TagsSubstitutionConcern [champ_public_tags, dossier.champs], [champ_private_tags, dossier.champs_private], [dossier_tags, dossier], + [ROUTAGE_TAGS, dossier], [INDIVIDUAL_TAGS, dossier.individual], [ENTREPRISE_TAGS, dossier.etablissement&.entreprise] ] @@ -226,19 +234,7 @@ module TagsSubstitutionConcern def replace_tags_with_values_from_data(text, tags, data) if data.present? tags.reduce(text) do |acc, tag| - # A tag is available by default. - # If it has an :available? lambda, then we check its result to determine if the tag is available - if tag.key?(:available?) - tag_available = instance_exec(data, &tag[:available?]) - else - tag_available = true - end - - if tag_available - replace_tag(acc, tag, data) - else - text - end + replace_tag(acc, tag, data) end else text diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index cb3c9b352..9488976fd 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -83,13 +83,13 @@ describe TagsSubstitutionConcern, type: :model do dossier.reload end - it { expect(procedure.groupe_instructeurs.size).to eq(2) } it { expect(procedure.routee?).to eq(true) } it { is_expected.to eq(label) } end context 'and the dossier has no groupe instructeur' do - it { is_expected.to eq(template) } + it { expect(procedure.routee?).to eq(false) } + it { is_expected.to eq('défaut') } end end