one less indirection

This commit is contained in:
simon lehericey 2024-09-13 17:22:08 +02:00
parent f046f31dcc
commit 2f64fe5e4c
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
16 changed files with 35 additions and 35 deletions

View file

@ -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

View file

@ -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

View file

@ -7,7 +7,7 @@ module Types::Champs::Descriptor
field :options, [String], "List des options dun 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

View file

@ -7,7 +7,7 @@ module Types::Champs::Descriptor
field :options, [String], "List des options dun 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

View file

@ -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,

View file

@ -17,7 +17,7 @@ class Champs::DropDownListChamp < Champ
end
def options?
drop_down_list_options?
drop_down_options?
end
def html_label?

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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]]

View file

@ -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 <code style='white-space: pre-wrap;'>--texte--</code>")
end
end

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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é')

View file

@ -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