Merge pull request #5997 from tchak/fix-mandatory-multiple-drop-down

Usager : un champ "Liste déroulante à choix multiple" est correctement détecté comme vide si aucun élément n'a été ajouté (#5997)
This commit is contained in:
Pierre de La Morinerie 2021-03-18 18:09:46 +01:00 committed by GitHub
commit d42156b494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -94,6 +94,8 @@ class Champ < ApplicationRecord
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

View file

@ -15,6 +15,12 @@ shared_examples 'champ_spec' do
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(:value) { '[]' }
it { expect(champ.mandatory_and_blank?).to be(true) }
end
context 'when not blank' do
let(:value) { 'yop' }
it { expect(champ.mandatory_and_blank?).to be(false) }