remove_disabled_options

This commit is contained in:
simon lehericey 2024-09-13 14:22:07 +02:00
parent 38ced210a9
commit f046f31dcc
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
3 changed files with 5 additions and 26 deletions

View file

@ -572,12 +572,8 @@ class TypeDeChamp < ApplicationRecord
drop_down_options.presence || []
end
def drop_down_list_disabled_options
drop_down_list_options.filter { |v| (v =~ /^--.*--$/).present? }
end
def drop_down_list_enabled_non_empty_options(other: false)
list_options = (drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?)
list_options = drop_down_list_options.reject(&:empty?)
if other && drop_down_other?
list_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]

View file

@ -79,12 +79,9 @@ FactoryBot.define do
factory :type_de_champ_drop_down_list do
libelle { 'Choix unique' }
type_champ { TypeDeChamp.type_champs.fetch(:drop_down_list) }
drop_down_list_value { "val1\r\nval2\r\n--separateur--\r\nval3" }
drop_down_list_value { "val1\r\nval2\r\nval3" }
trait :long do
drop_down_list_value { "alpha\r\nbravo\r\n--separateur--\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" }
end
trait :without_selectable_values do
drop_down_list_value { "\r\n--separateur--\r\n--separateur 2--\r\n \r\n" }
drop_down_list_value { "alpha\r\nbravo\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" }
end
trait :with_other do
drop_down_other { true }
@ -92,9 +89,9 @@ FactoryBot.define do
end
factory :type_de_champ_multiple_drop_down_list do
type_champ { TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) }
drop_down_list_value { "val1\r\nval2\r\n--separateur--\r\nval3" }
drop_down_list_value { "val1\r\nval2\r\nval3" }
trait :long do
drop_down_list_value { "alpha\r\nbravo\r\n--separateur--\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" }
drop_down_list_value { "alpha\r\nbravo\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" }
end
end
factory :type_de_champ_linked_drop_down_list do

View file

@ -218,20 +218,6 @@ describe TypeDeChamp do
end
end
describe 'disabled_options' do
let(:value) do
<<~EOS
tip
--top--
--troupt--
ouaich
EOS
end
let(:type_de_champ) { create(:type_de_champ_drop_down_list, drop_down_list_value: value) }
it { expect(type_de_champ.drop_down_list_disabled_options).to match(['--top--', '--troupt--']) }
end
describe '#public_only' do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }