From 0562e2728f67715279d4aaca1d47a9d5e4a532ec Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 6 Nov 2019 11:20:28 +0100 Subject: [PATCH] Fix type_de_champ validation error --- .../linked_drop_down_list_type_de_champ.rb | 2 +- spec/models/type_de_champ_shared_example.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb index 71f0784b1..24410c6f6 100644 --- a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb @@ -53,7 +53,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas def check_presence_of_primary_options if !PRIMARY_PATTERN.match?(drop_down_list.options.second) - errors.add(libelle, "doit commencer par une entrée de menu primaire de la forme --texte--") + errors.add(libelle.presence || "La liste", "doit commencer par une entrée de menu primaire de la forme --texte--") end end diff --git a/spec/models/type_de_champ_shared_example.rb b/spec/models/type_de_champ_shared_example.rb index d0b6e4ecf..a710b4ef0 100644 --- a/spec/models/type_de_champ_shared_example.rb +++ b/spec/models/type_de_champ_shared_example.rb @@ -148,4 +148,22 @@ shared_examples 'type_de_champ_spec' do expect(cloned_procedure.types_de_champ.first.types_de_champ).not_to be_empty end end + + describe "linked_drop_down_list" do + let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list) } + + it 'should validate without label' do + type_de_champ.drop_down_list_value = 'toto' + expect(type_de_champ.validate).to be_falsey + messages = type_de_champ.errors.full_messages + expect(messages.size).to eq(1) + expect(messages.first.starts_with?("#{type_de_champ.libelle} doit commencer par")).to be_truthy + + type_de_champ.libelle = '' + expect(type_de_champ.validate).to be_falsey + messages = type_de_champ.errors.full_messages + expect(messages.size).to eq(2) + expect(messages.last.starts_with?("La liste doit commencer par")).to be_truthy + end + end end