diff --git a/app/graphql/types/champ_descriptor_type.rb b/app/graphql/types/champ_descriptor_type.rb index 580400fd3..9e4a474a9 100644 --- a/app/graphql/types/champ_descriptor_type.rb +++ b/app/graphql/types/champ_descriptor_type.rb @@ -117,7 +117,7 @@ module Types def options if type_de_champ.drop_down_list? - type_de_champ.drop_down_list_options.reject(&:empty?) + type_de_champ.drop_down_options.reject(&:empty?) end end diff --git a/app/graphql/types/champs/descriptor/drop_down_list_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/drop_down_list_champ_descriptor_type.rb index 22f533781..189e34943 100644 --- a/app/graphql/types/champs/descriptor/drop_down_list_champ_descriptor_type.rb +++ b/app/graphql/types/champs/descriptor/drop_down_list_champ_descriptor_type.rb @@ -12,7 +12,7 @@ module Types::Champs::Descriptor end def options - object.type_de_champ.drop_down_list_options.reject(&:empty?) + object.type_de_champ.drop_down_options.reject(&:empty?) end end end diff --git a/app/graphql/types/champs/descriptor/linked_drop_down_list_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/linked_drop_down_list_champ_descriptor_type.rb index 918c2913a..93d6660af 100644 --- a/app/graphql/types/champs/descriptor/linked_drop_down_list_champ_descriptor_type.rb +++ b/app/graphql/types/champs/descriptor/linked_drop_down_list_champ_descriptor_type.rb @@ -7,7 +7,7 @@ module Types::Champs::Descriptor field :options, [String], "List des options d’un champ avec selection.", null: true def options - object.type_de_champ.drop_down_list_options.reject(&:empty?) + object.type_de_champ.drop_down_options.reject(&:empty?) end end end diff --git a/app/graphql/types/champs/descriptor/multiple_drop_down_list_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/multiple_drop_down_list_champ_descriptor_type.rb index 995972bea..d5715d495 100644 --- a/app/graphql/types/champs/descriptor/multiple_drop_down_list_champ_descriptor_type.rb +++ b/app/graphql/types/champs/descriptor/multiple_drop_down_list_champ_descriptor_type.rb @@ -7,7 +7,7 @@ module Types::Champs::Descriptor field :options, [String], "List des options d’un champ avec selection.", null: true def options - object.type_de_champ.drop_down_list_options.reject(&:empty?) + object.type_de_champ.drop_down_options.reject(&:empty?) end end end diff --git a/app/models/champ.rb b/app/models/champ.rb index c8bfbff03..7694177c9 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -29,9 +29,9 @@ class Champ < ApplicationRecord delegate :libelle, :type_champ, :description, - :drop_down_list_options, + :drop_down_options, :drop_down_other?, - :drop_down_list_options?, + :drop_down_options?, :drop_down_list_enabled_non_empty_options, :drop_down_secondary_libelle, :drop_down_secondary_description, diff --git a/app/models/champs/drop_down_list_champ.rb b/app/models/champs/drop_down_list_champ.rb index e49d18b2b..0204caa15 100644 --- a/app/models/champs/drop_down_list_champ.rb +++ b/app/models/champs/drop_down_list_champ.rb @@ -17,7 +17,7 @@ class Champs::DropDownListChamp < Champ end def options? - drop_down_list_options? + drop_down_options? end def html_label? diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 2dacb4dbb..0cf99ad02 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -4,7 +4,7 @@ class Champs::LinkedDropDownListChamp < Champ delegate :primary_options, :secondary_options, to: :type_de_champ def options? - drop_down_list_options? + drop_down_options? end def primary_value diff --git a/app/models/champs/multiple_drop_down_list_champ.rb b/app/models/champs/multiple_drop_down_list_champ.rb index ac7c8502e..93dbeafc0 100644 --- a/app/models/champs/multiple_drop_down_list_champ.rb +++ b/app/models/champs/multiple_drop_down_list_champ.rb @@ -4,7 +4,7 @@ class Champs::MultipleDropDownListChamp < Champ validate :values_are_in_options, if: -> { value.present? && validate_champ_value_or_prefill? } def options? - drop_down_list_options? + drop_down_options? end def enabled_non_empty_options diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 88c9f7dbf..80d4b7b2c 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -407,11 +407,11 @@ class ProcedureRevision < ApplicationRecord end if to_type_de_champ.drop_down_list? - if from_type_de_champ.drop_down_list_options != to_type_de_champ.drop_down_list_options + if from_type_de_champ.drop_down_options != to_type_de_champ.drop_down_options changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ, :drop_down_options, - from_type_de_champ.drop_down_list_options, - to_type_de_champ.drop_down_list_options) + from_type_de_champ.drop_down_options, + to_type_de_champ.drop_down_options) end if to_type_de_champ.linked_drop_down_list? if from_type_de_champ.drop_down_secondary_libelle != to_type_de_champ.drop_down_secondary_libelle diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 066093b4d..eda2176bb 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -475,8 +475,8 @@ class TypeDeChamp < ApplicationRecord end def drop_down_list_value - if drop_down_list_options.present? - drop_down_list_options.reject(&:empty?).join("\r\n") + if drop_down_options.present? + drop_down_options.reject(&:empty?).join("\r\n") else '' end @@ -564,16 +564,16 @@ class TypeDeChamp < ApplicationRecord end end - def drop_down_list_options? - drop_down_list_options.any? + def drop_down_options? + drop_down_options.any? end - def drop_down_list_options - drop_down_options.presence || [] + def drop_down_options + Array.wrap(super) end def drop_down_list_enabled_non_empty_options(other: false) - list_options = drop_down_list_options.reject(&:empty?) + list_options = drop_down_options.reject(&:empty?) if other && drop_down_other? list_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]] 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 125429673..0b3b3677c 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 @@ -3,7 +3,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase PRIMARY_PATTERN = /^--(.*)--$/ - delegate :drop_down_list_options, to: :@type_de_champ + delegate :drop_down_options, to: :@type_de_champ validate :check_presence_of_primary_options def libelles_for_export @@ -89,7 +89,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas end def unpack_options - _, *options = drop_down_list_options + _, *options = drop_down_options chunked = options.slice_before(PRIMARY_PATTERN) chunked.map do |chunk| primary, *secondary = chunk @@ -99,7 +99,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas end def check_presence_of_primary_options - if !PRIMARY_PATTERN.match?(drop_down_list_options.second) + if !PRIMARY_PATTERN.match?(drop_down_options.second) 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/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 1871307cc..35fbdbe18 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -219,7 +219,7 @@ describe API::V2::GraphqlController do description: tdc.description, required: tdc.mandatory?, champDescriptors: tdc.repetition? ? procedure.active_revision.children_of(tdc.reload).map { { id: _1.to_typed_id, __typename: format_type_champ(_1.type_champ) } } : nil, - options: tdc.drop_down_list? ? tdc.drop_down_list_options.reject(&:empty?) : nil + options: tdc.drop_down_list? ? tdc.drop_down_options.reject(&:empty?) : nil }.compact end, dossiers: { @@ -1445,8 +1445,8 @@ describe API::V2::GraphqlController do end describe 'drop_down_list' do - let(:drop_down_list_options) { ['bijour'] } - let(:types_de_champ_private) { [{ type: :drop_down_list, options: drop_down_list_options }] } + let(:drop_down_options) { ['bijour'] } + let(:types_de_champ_private) { [{ type: :drop_down_list, options: drop_down_options }] } let(:query) do "mutation { dossierModifierAnnotationDropDownList(input: { @@ -1466,7 +1466,7 @@ describe API::V2::GraphqlController do end context "success" do - let(:value) { drop_down_list_options.first } + let(:value) { drop_down_options.first } it 'should be a success' do expect(gql_errors).to eq(nil) @@ -1479,7 +1479,7 @@ describe API::V2::GraphqlController do end end context "failure" do - let(:value) { drop_down_list_options.first.reverse } + let(:value) { drop_down_options.first.reverse } it 'should be a success' do expect(gql_errors).to eq(nil) diff --git a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb index d887bab6a..f3f6c11b9 100644 --- a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb @@ -1243,7 +1243,7 @@ describe API::V2::GraphqlController do expect(gql_errors).to be_nil expect(gql_data[:groupeInstructeurModifier][:errors]).to be_nil expect(gql_data[:groupeInstructeurModifier][:groupeInstructeur][:id]).to eq(dossier.groupe_instructeur.to_typed_id) - expect(routing_champ.reload.drop_down_list_options).to match_array(procedure.groupe_instructeurs.active.map(&:label)) + expect(routing_champ.reload.drop_down_options).to match_array(procedure.groupe_instructeurs.active.map(&:label)) expect(procedure.groupe_instructeurs.active.map(&:routing_rule)).to match_array(procedure.groupe_instructeurs.active.map { ds_eq(champ_value(routing_champ.stable_id), constant(_1.label)) }) } end @@ -1297,7 +1297,7 @@ describe API::V2::GraphqlController do expect(gql_errors).to be_nil expect(gql_data[:groupeInstructeurCreer][:errors]).to be_nil expect(gql_data[:groupeInstructeurCreer][:groupeInstructeur][:id]).not_to be_nil - expect(routing_champ.reload.drop_down_list_options).to match_array(procedure.groupe_instructeurs.map(&:label)) + expect(routing_champ.reload.drop_down_options).to match_array(procedure.groupe_instructeurs.map(&:label)) expect(procedure.groupe_instructeurs.map(&:routing_rule)).to match_array(procedure.groupe_instructeurs.map { ds_eq(champ_value(routing_champ.stable_id), constant(_1.label)) }) } end diff --git a/spec/models/type_de_champ_spec.rb b/spec/models/type_de_champ_spec.rb index 48927bb0c..28c5365e8 100644 --- a/spec/models/type_de_champ_spec.rb +++ b/spec/models/type_de_champ_spec.rb @@ -107,7 +107,7 @@ describe TypeDeChamp do context 'when the target type_champ is not drop_down_list' do let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:text) } - it { expect(tdc.drop_down_options).to be_nil } + it { expect(tdc.drop_down_options).to be_empty } end context 'when the target type_champ is linked_drop_down_list' do @@ -192,7 +192,7 @@ describe TypeDeChamp do end end - describe '#drop_down_list_options' do + describe '#drop_down_options' do let(:value) do <<~EOS Cohésion sociale @@ -203,7 +203,7 @@ describe TypeDeChamp do 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_options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } + it { expect(type_de_champ.drop_down_options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } context 'when one value is empty' do let(:value) do @@ -214,7 +214,7 @@ describe TypeDeChamp do EOS end - it { expect(type_de_champ.drop_down_list_options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } + it { expect(type_de_champ.drop_down_options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } end end diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index c1b6b94e5..5586242a5 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -162,7 +162,7 @@ describe 'As an administrateur I can edit types de champ', js: true do fill_in 'Options de la liste', with: 'Un menu', fill_options: { clear: :backspace } check "Proposer une option « autre » avec un texte libre" - wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_list_options == ['', 'Un menu'] } + wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_options == ['', 'Un menu'] } wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_other == "1" } expect(page).to have_content('Formulaire enregistré') diff --git a/spec/views/shared/dossiers/_edit.html.haml_spec.rb b/spec/views/shared/dossiers/_edit.html.haml_spec.rb index 32a6b2393..a7452d536 100644 --- a/spec/views/shared/dossiers/_edit.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_edit.html.haml_spec.rb @@ -85,7 +85,7 @@ describe 'shared/dossiers/edit', type: :view do let(:types_de_champ_public) { [{ type: :multiple_drop_down_list, options: }] } let(:champ) { dossier.champs.first } let(:type_de_champ) { champ.type_de_champ } - let(:options) { type_de_champ.drop_down_list_options } + let(:options) { type_de_champ.drop_down_options } let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options } context 'when the list is short' do