From 179bb5a9fee60900dabde43a7b73dfe404680858 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 25 May 2021 11:14:02 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Pierre de La Morinerie --- app/models/concerns/tags_substitution_concern.rb | 6 +++--- spec/models/concern/tags_substitution_concern_spec.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index e562cfa8c..e9ab51137 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -197,12 +197,12 @@ module TagsSubstitutionConcern end def champ_public_tags(dossier: nil) - types_de_champ = (dossier ? dossier : procedure.active_revision).types_de_champ + types_de_champ = (dossier || procedure.active_revision).types_de_champ types_de_champ_tags(types_de_champ, Dossier::SOUMIS) end def champ_private_tags(dossier: nil) - types_de_champ = (dossier ? dossier : procedure.active_revision).types_de_champ_private + types_de_champ = (dossier || procedure.active_revision).types_de_champ_private types_de_champ_tags(types_de_champ, Dossier::INSTRUCTION_COMMENCEE) end @@ -246,7 +246,7 @@ module TagsSubstitutionConcern end def replace_tag(text, tag, data) - libelle = Regexp.quote(tag[:id] ? tag[:id] : tag[:libelle]) + libelle = Regexp.quote(tag[:id].presence || tag[:libelle]) # allow any kind of space (non-breaking or other) in the tag’s libellé to match any kind of space in the template # (the '\\ |' is there because plain ASCII spaces were escaped by preceding Regexp.quote) diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 3b5404541..c9c95ea9c 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -401,18 +401,18 @@ describe TagsSubstitutionConcern, type: :model do procedure.update!(draft_revision: procedure.create_new_revision, published_revision: procedure.draft_revision) end - context "replace by old label" do + context "when using the champ's original label" do let(:template) { '--mon tag--' } - it "should replace tag" do + it "replaces the tag" do is_expected.to eq('valeur') end end - context "replace by new label" do + context "when using the champ's revised label" do let(:template) { '--ton tag--' } - it "should replace tag" do + it "replaces the tag" do is_expected.to eq('valeur') end end