Apply suggestions from code review

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>
This commit is contained in:
Paul Chavard 2021-05-25 11:14:02 +02:00
parent acb277e650
commit 179bb5a9fe
2 changed files with 7 additions and 7 deletions

View file

@ -197,12 +197,12 @@ module TagsSubstitutionConcern
end end
def champ_public_tags(dossier: nil) 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) types_de_champ_tags(types_de_champ, Dossier::SOUMIS)
end end
def champ_private_tags(dossier: nil) 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) types_de_champ_tags(types_de_champ, Dossier::INSTRUCTION_COMMENCEE)
end end
@ -246,7 +246,7 @@ module TagsSubstitutionConcern
end end
def replace_tag(text, tag, data) 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 tags libellé to match any kind of space in the template # allow any kind of space (non-breaking or other) in the tags libellé to match any kind of space in the template
# (the '\\ |' is there because plain ASCII spaces were escaped by preceding Regexp.quote) # (the '\\ |' is there because plain ASCII spaces were escaped by preceding Regexp.quote)

View file

@ -401,18 +401,18 @@ describe TagsSubstitutionConcern, type: :model do
procedure.update!(draft_revision: procedure.create_new_revision, published_revision: procedure.draft_revision) procedure.update!(draft_revision: procedure.create_new_revision, published_revision: procedure.draft_revision)
end end
context "replace by old label" do context "when using the champ's original label" do
let(:template) { '--mon tag--' } let(:template) { '--mon tag--' }
it "should replace tag" do it "replaces the tag" do
is_expected.to eq('valeur') is_expected.to eq('valeur')
end end
end end
context "replace by new label" do context "when using the champ's revised label" do
let(:template) { '--ton tag--' } let(:template) { '--ton tag--' }
it "should replace tag" do it "replaces the tag" do
is_expected.to eq('valeur') is_expected.to eq('valeur')
end end
end end