From ac823c1b252ad73d5368775d10d2c1b530b6c326 Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 22 Aug 2023 09:00:44 +0200
Subject: [PATCH 01/10] feat(routing): add departements to
routable_type_de_champ
---
app/models/procedure_revision.rb | 2 +-
spec/models/procedure_revision_spec.rb | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb
index a38706b9351..716334e57c0 100644
--- a/app/models/procedure_revision.rb
+++ b/app/models/procedure_revision.rb
@@ -224,7 +224,7 @@ def coordinate_and_tdc(stable_id)
end
def routable_types_de_champ
- types_de_champ_public.filter { |tdc| [:drop_down_list].include?(tdc.type_champ.to_sym) }
+ types_de_champ_public.filter { |tdc| [:drop_down_list, :departements].include?(tdc.type_champ.to_sym) }
end
private
diff --git a/spec/models/procedure_revision_spec.rb b/spec/models/procedure_revision_spec.rb
index b115ad62fc2..b6011ca24a1 100644
--- a/spec/models/procedure_revision_spec.rb
+++ b/spec/models/procedure_revision_spec.rb
@@ -941,4 +941,16 @@ def second_champ = procedure.draft_revision.types_de_champ_public.second
expect(type_de_champ.revisions.count).to eq(1)
}
end
+
+ describe '#routable_types_de_champ' do
+ let(:procedure) do
+ create(:procedure).tap do |p|
+ p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l1')
+ p.draft_revision.add_type_de_champ(type_champ: :drop_down_list, libelle: 'l2')
+ p.draft_revision.add_type_de_champ(type_champ: :departements, libelle: 'l3')
+ end
+ end
+
+ it { expect(draft.routable_types_de_champ.pluck(:libelle)).to eq(['l2', 'l3']) }
+ end
end
From 4be93527815c6209ad759eba204e10c62ae5bd8b Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 22 Aug 2023 10:37:22 +0200
Subject: [PATCH 02/10] feat(routing): add departements options to value tag
---
.../procedure/one_groupe_management_component.rb | 16 +++++++++++++---
app/models/groupe_instructeur.rb | 8 +++++++-
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/app/components/procedure/one_groupe_management_component.rb b/app/components/procedure/one_groupe_management_component.rb
index 80ab87cd19c..570617540c5 100644
--- a/app/components/procedure/one_groupe_management_component.rb
+++ b/app/components/procedure/one_groupe_management_component.rb
@@ -58,8 +58,18 @@ def values_for_select(targeted_champ)
def available_values_for_select(targeted_champ)
return [] if targeted_champ.is_a?(Logic::Empty)
- targeted_champ
- .options(@revision.types_de_champ_public)
- .map { |(label, value)| [label, constant(value).to_json] }
+
+ case @revision.types_de_champ_public.find_by(stable_id: targeted_champ.stable_id).type_champ
+ when TypeDeChamp.type_champs.fetch(:departements)
+ departements_for_select
+ when TypeDeChamp.type_champs.fetch(:drop_down_list)
+ targeted_champ
+ .options(@revision.types_de_champ_public)
+ .map { |(label, value)| [label, constant(value).to_json] }
+ end
+ end
+
+ def departements_for_select
+ APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", constant("#{_1[:code]} – #{_1[:name]}").to_json] }
end
end
diff --git a/app/models/groupe_instructeur.rb b/app/models/groupe_instructeur.rb
index cad3b263858..52d3f1135c6 100644
--- a/app/models/groupe_instructeur.rb
+++ b/app/models/groupe_instructeur.rb
@@ -105,7 +105,13 @@ def other_groupe_instructeurs
def routing_rule_matches_tdc?
routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id)
- options = routing_tdc.options_with_drop_down_other
+
+ options = case routing_tdc.type_champ
+ when TypeDeChamp.type_champs.fetch(:departements)
+ APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
+ when TypeDeChamp.type_champs.fetch(:drop_down_list)
+ routing_tdc.options_with_drop_down_other
+ end
routing_rule.right.value.in?(options)
end
From 2827db5263c565e23956f0b9f8e33078f4415c4e Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 22 Aug 2023 10:47:14 +0200
Subject: [PATCH 03/10] feat(routing): can create simple routing from
departements tdc
---
.../administrateurs/groupe_instructeurs_controller.rb | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb
index 33491a1be02..6675b7e1f1c 100644
--- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb
+++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb
@@ -40,7 +40,12 @@ def create_simple_routing
tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }
- tdc_options = tdc.drop_down_options.reject(&:empty?)
+ tdc_options = case tdc.type_champ
+ when TypeDeChamp.type_champs.fetch(:departements)
+ APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
+ when TypeDeChamp.type_champs.fetch(:drop_down_list)
+ tdc.drop_down_options.reject(&:empty?)
+ end
tdc_options.each do |option_label|
routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
From 7e3fc68c5351f1786ec05a7bb70a10d904bce06e Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 22 Aug 2023 14:06:58 +0200
Subject: [PATCH 04/10] feat(routing): make routing engine work with
departement champ
---
app/models/logic/champ_value.rb | 2 +
spec/models/routing_engine_spec.rb | 88 +++++++++++++++++++-----------
2 files changed, 57 insertions(+), 33 deletions(-)
diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb
index dee68529f07..d0ade372d95 100644
--- a/app/models/logic/champ_value.rb
+++ b/app/models/logic/champ_value.rb
@@ -44,6 +44,8 @@ def compute(champs)
targeted_champ.selected
when "Champs::MultipleDropDownListChamp"
targeted_champ.selected_options
+ when "Champs::DepartementChamp"
+ targeted_champ.to_s
end
end
diff --git a/spec/models/routing_engine_spec.rb b/spec/models/routing_engine_spec.rb
index ef70eb5890e..f123132dfea 100644
--- a/spec/models/routing_engine_spec.rb
+++ b/spec/models/routing_engine_spec.rb
@@ -2,16 +2,6 @@
include Logic
describe '.compute' do
- let(:procedure) do
- create(:procedure,
- types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }]).tap do |p|
- p.groupe_instructeurs.create(label: 'a second group')
- p.groupe_instructeurs.create(label: 'a third group')
- end
- end
-
- let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
-
let(:dossier) { create(:dossier, procedure:) }
let(:defaut_groupe) { procedure.defaut_groupe_instructeur }
let(:gi_2) { procedure.groupe_instructeurs.find_by(label: 'a second group') }
@@ -21,43 +11,75 @@
dossier.groupe_instructeur
end
- context 'without any rules' do
- it { is_expected.to eq(defaut_groupe) }
- end
+ context 'with a drop down list type de champ' do
+ let(:procedure) do
+ create(:procedure,
+ types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }]).tap do |p|
+ p.groupe_instructeurs.create(label: 'a second group')
+ p.groupe_instructeurs.create(label: 'a third group')
+ end
+ end
+
+ let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
- context 'without any matching rules' do
- before do
- procedure.groupe_instructeurs.each do |gi|
- gi.update(routing_rule: constant(false))
+ context 'without any rules' do
+ it { is_expected.to eq(defaut_groupe) }
+ end
+
+ context 'without any matching rules' do
+ before do
+ procedure.groupe_instructeurs.each do |gi|
+ gi.update(routing_rule: constant(false))
+ end
end
+
+ it { is_expected.to eq(defaut_groupe) }
end
- it { is_expected.to eq(defaut_groupe) }
- end
+ context 'with rules not configured yet' do
+ before do
+ procedure.groupe_instructeurs.each do |gi|
+ gi.update(routing_rule: ds_eq(empty, empty))
+ end
+ end
+
+ it { is_expected.to eq(defaut_groupe) }
+ end
- context 'with rules not configured yet' do
- before do
- procedure.groupe_instructeurs.each do |gi|
- gi.update(routing_rule: ds_eq(empty, empty))
+ context 'with a matching rule' do
+ before do
+ gi_2.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
+ dossier.champs.first.update(value: 'Lyon')
end
+
+ it { is_expected.to eq(gi_2) }
end
- it { is_expected.to eq(defaut_groupe) }
+ context 'with a closed gi with a matching rule' do
+ before { gi_2.update(routing_rule: constant(true), closed: true) }
+
+ it { is_expected.to eq(defaut_groupe) }
+ end
end
- context 'with a matching rule' do
- before do
- gi_2.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
- dossier.champs.first.update(value: 'Lyon')
+ context 'with a departements type de champ' do
+ let(:procedure) do
+ create(:procedure, types_de_champ_public: [{ type: :departements }]).tap do |p|
+ p.groupe_instructeurs.create(label: 'a second group')
+ p.groupe_instructeurs.create(label: 'a third group')
+ end
end
- it { is_expected.to eq(gi_2) }
- end
+ let(:departements_tdc) { procedure.draft_revision.types_de_champ.first }
- context 'with a closed gi with a matching rule' do
- before { gi_2.update(routing_rule: constant(true), closed: true) }
+ context 'with a matching rule' do
+ before do
+ gi_2.update(routing_rule: ds_eq(champ_value(departements_tdc.stable_id), constant('43 – Haute-Loire')))
+ dossier.champs.first.update(value: 'Haute-Loire')
+ end
- it { is_expected.to eq(defaut_groupe) }
+ it { is_expected.to eq(gi_2) }
+ end
end
end
end
From 8d0fffe44f4176af9fdf5e70d39fb91bcb81cbd5 Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 22 Aug 2023 17:13:09 +0200
Subject: [PATCH 05/10] refactor(type de champ): extract codes_and_names method
---
.../administrateurs/groupe_instructeurs_controller.rb | 2 +-
app/models/groupe_instructeur.rb | 2 +-
app/models/type_de_champ.rb | 6 ++++++
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb
index 6675b7e1f1c..d8416180bb7 100644
--- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb
+++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb
@@ -42,7 +42,7 @@ def create_simple_routing
tdc_options = case tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
- APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
+ tdc.codes_and_names
when TypeDeChamp.type_champs.fetch(:drop_down_list)
tdc.drop_down_options.reject(&:empty?)
end
diff --git a/app/models/groupe_instructeur.rb b/app/models/groupe_instructeur.rb
index 52d3f1135c6..a411fad693a 100644
--- a/app/models/groupe_instructeur.rb
+++ b/app/models/groupe_instructeur.rb
@@ -108,7 +108,7 @@ def routing_rule_matches_tdc?
options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
- APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
+ routing_tdc.codes_and_names
when TypeDeChamp.type_champs.fetch(:drop_down_list)
routing_tdc.options_with_drop_down_other
end
diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb
index 1d7be7f0778..d3a2ad2e487 100644
--- a/app/models/type_de_champ.rb
+++ b/app/models/type_de_champ.rb
@@ -477,6 +477,12 @@ def options_for_select
end
end
+ def codes_and_names
+ if departement?
+ APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
+ end
+ end
+
# historicaly we added a blank ("") option by default to avoid wrong selection
# see self.parse_drop_down_list_value
# then rails decided to add this blank ("") option when the select is required
From 7355eb18cc257082b84248f73bad0b605a28b5fc Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 22 Aug 2023 18:33:57 +0200
Subject: [PATCH 06/10] style(routing): disable button with info at groups
creation
---
.../groupe_instructeurs/simple_routing.html.haml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/administrateurs/groupe_instructeurs/simple_routing.html.haml b/app/views/administrateurs/groupe_instructeurs/simple_routing.html.haml
index 16dfb386720..ae657c20366 100644
--- a/app/views/administrateurs/groupe_instructeurs/simple_routing.html.haml
+++ b/app/views/administrateurs/groupe_instructeurs/simple_routing.html.haml
@@ -24,4 +24,4 @@
%li
= link_to 'Retour', options_admin_procedure_groupe_instructeurs_path(@procedure, state: :choix), class: 'fr-btn fr-btn--secondary'
%li
- %button.fr-btn{ disabled: true, data: { 'radio-enabled-submit-target': 'submit' } } Créer les groupes
+ %button.fr-btn{ disabled: true, data: { disable_with: 'Création des groupes…', 'radio-enabled-submit-target': 'submit' } } Créer les groupes
From 3f969ca6c5fb6e8cffca4f34f9df92a97467298b Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 22 Aug 2023 18:35:21 +0200
Subject: [PATCH 07/10] clean(typo): use right suspension points
---
.../instructeurs_options_component.html.haml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml b/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml
index 0835f6a1e46..1fbfd047dfc 100644
--- a/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml
+++ b/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml
@@ -27,7 +27,7 @@
class: 'fr-btn',
method: :delete,
title: t('.delete_title', defaut_label: @procedure.defaut_groupe_instructeur.label),
- data: ( @procedure.publiee? ? { disable_with: "Suppression...", confirm: t('.delete_confirmation', defaut_label: @procedure.defaut_groupe_instructeur.label) } : nil)
+ data: ( @procedure.publiee? ? { disable_with: "Suppression…", confirm: t('.delete_confirmation', defaut_label: @procedure.defaut_groupe_instructeur.label) } : nil)
- elsif @state == 'choix'
= form_for :choice,
From 4e6788919f7595a33634592199c748dae67686da Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Wed, 23 Aug 2023 10:37:37 +0200
Subject: [PATCH 08/10] wording(routing): update routing configuration notice
---
.../instructeurs_options_component.fr.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/components/procedure/instructeurs_options_component/instructeurs_options_component.fr.yml b/app/components/procedure/instructeurs_options_component/instructeurs_options_component.fr.yml
index 50ceef36810..1d98b2d9d0c 100644
--- a/app/components/procedure/instructeurs_options_component/instructeurs_options_component.fr.yml
+++ b/app/components/procedure/instructeurs_options_component/instructeurs_options_component.fr.yml
@@ -4,7 +4,7 @@ fr:
Le routage permet d’acheminer les dossiers vers différents groupes d’instructeurs.
routing_configuration_notice_2_html: |
Pour le configurer, votre formulaire doit comporter
- au moins un champ « choix simple ».
+ au moins un champ de type « choix simple » ou « départements ».
Ajoutez ce champ dans la page « Configuration des champs ».
delete_title: Aucun dossier ne sera supprimé. Les groupes d'instructeurs vont être supprimés. Seuls les instructeurs du groupe « %{defaut_label} » resteront affectés à la démarche.
delete_confirmation: |
From ca25788f079314c952fe0173dced28e18d89a151 Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 29 Aug 2023 11:35:39 +0200
Subject: [PATCH 09/10] feat(routing): use only department codes in routing
rules
---
.../one_groupe_management_component.rb | 2 +-
.../groupe_instructeurs_controller.rb | 29 ++++++++++++-------
app/models/groupe_instructeur.rb | 2 +-
app/models/logic/champ_value.rb | 2 +-
app/models/type_de_champ.rb | 6 ----
spec/models/routing_engine_spec.rb | 2 +-
6 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/app/components/procedure/one_groupe_management_component.rb b/app/components/procedure/one_groupe_management_component.rb
index 570617540c5..f1b8aa0e1a3 100644
--- a/app/components/procedure/one_groupe_management_component.rb
+++ b/app/components/procedure/one_groupe_management_component.rb
@@ -70,6 +70,6 @@ def available_values_for_select(targeted_champ)
end
def departements_for_select
- APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", constant("#{_1[:code]} – #{_1[:name]}").to_json] }
+ APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", constant(_1[:code]).to_json] }
end
end
diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb
index d8416180bb7..d042f74c43b 100644
--- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb
+++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb
@@ -40,19 +40,26 @@ def create_simple_routing
tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }
- tdc_options = case tdc.type_champ
+ case tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
- tdc.codes_and_names
- when TypeDeChamp.type_champs.fetch(:drop_down_list)
- tdc.drop_down_options.reject(&:empty?)
- end
+ tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
+ tdc_options.each do |code_and_name, code|
+ routing_rule = ds_eq(champ_value(stable_id), constant(code))
+ @procedure
+ .groupe_instructeurs
+ .find_or_create_by(label: code_and_name)
+ .update(instructeurs: [current_administrateur.instructeur], routing_rule:)
+ end
- tdc_options.each do |option_label|
- routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
- @procedure
- .groupe_instructeurs
- .find_or_create_by(label: option_label)
- .update(instructeurs: [current_administrateur.instructeur], routing_rule:)
+ when TypeDeChamp.type_champs.fetch(:drop_down_list)
+ tdc_options = tdc.drop_down_options.reject(&:empty?)
+ tdc_options.each do |option_label|
+ routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
+ @procedure
+ .groupe_instructeurs
+ .find_or_create_by(label: option_label)
+ .update(instructeurs: [current_administrateur.instructeur], routing_rule:)
+ end
end
if tdc.drop_down_other?
diff --git a/app/models/groupe_instructeur.rb b/app/models/groupe_instructeur.rb
index a411fad693a..69dc0ea2e67 100644
--- a/app/models/groupe_instructeur.rb
+++ b/app/models/groupe_instructeur.rb
@@ -108,7 +108,7 @@ def routing_rule_matches_tdc?
options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
- routing_tdc.codes_and_names
+ APIGeoService.departements.map { _1[:code] }
when TypeDeChamp.type_champs.fetch(:drop_down_list)
routing_tdc.options_with_drop_down_other
end
diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb
index d0ade372d95..4a1c9dcc2da 100644
--- a/app/models/logic/champ_value.rb
+++ b/app/models/logic/champ_value.rb
@@ -45,7 +45,7 @@ def compute(champs)
when "Champs::MultipleDropDownListChamp"
targeted_champ.selected_options
when "Champs::DepartementChamp"
- targeted_champ.to_s
+ targeted_champ.code
end
end
diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb
index d3a2ad2e487..1d7be7f0778 100644
--- a/app/models/type_de_champ.rb
+++ b/app/models/type_de_champ.rb
@@ -477,12 +477,6 @@ def options_for_select
end
end
- def codes_and_names
- if departement?
- APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
- end
- end
-
# historicaly we added a blank ("") option by default to avoid wrong selection
# see self.parse_drop_down_list_value
# then rails decided to add this blank ("") option when the select is required
diff --git a/spec/models/routing_engine_spec.rb b/spec/models/routing_engine_spec.rb
index f123132dfea..3095da91f4f 100644
--- a/spec/models/routing_engine_spec.rb
+++ b/spec/models/routing_engine_spec.rb
@@ -74,7 +74,7 @@
context 'with a matching rule' do
before do
- gi_2.update(routing_rule: ds_eq(champ_value(departements_tdc.stable_id), constant('43 – Haute-Loire')))
+ gi_2.update(routing_rule: ds_eq(champ_value(departements_tdc.stable_id), constant('43')))
dossier.champs.first.update(value: 'Haute-Loire')
end
From b1c28e1818d35fedba97aecd150b4ec963778a34 Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem
Date: Tue, 29 Aug 2023 15:34:39 +0200
Subject: [PATCH 10/10] test(routing): test simple routing with departements
type de champ
---
.../groupe_instructeurs_controller_spec.rb | 52 +++++++++++++------
1 file changed, 37 insertions(+), 15 deletions(-)
diff --git a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb
index fdaeb450a6c..40c731ae4d7 100644
--- a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb
+++ b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb
@@ -719,25 +719,47 @@ def remove_instructeur(instructeur)
end
describe '#create_simple_routing' do
- let!(:procedure3) do
- create(:procedure,
- types_de_champ_public: [
- { type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] },
- { type: :text, libelle: 'Un champ texte' }
- ],
- administrateurs: [admin])
+ context 'with a drop_down_list type de champ' do
+ let!(:procedure3) do
+ create(:procedure,
+ types_de_champ_public: [
+ { type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] },
+ { type: :text, libelle: 'Un champ texte' }
+ ],
+ administrateurs: [admin])
+ end
+
+ let!(:drop_down_tdc) { procedure3.draft_revision.types_de_champ.first }
+
+ before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: drop_down_tdc.stable_id } } }
+
+ it do
+ expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure3))
+ expect(flash.notice).to eq 'Les groupes instructeurs ont été ajoutés'
+ expect(procedure3.groupe_instructeurs.pluck(:label)).to match_array(['Paris', 'Lyon', 'Marseille'])
+ expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
+ expect(procedure3.routing_enabled).to be_truthy
+ end
end
- let!(:drop_down_tdc) { procedure3.draft_revision.types_de_champ.first }
+ context 'with a departements type de champ' do
+ let!(:procedure3) do
+ create(:procedure,
+ types_de_champ_public: [{ type: :departements }],
+ administrateurs: [admin])
+ end
+
+ let!(:departements_tdc) { procedure3.draft_revision.types_de_champ.first }
- before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: drop_down_tdc.stable_id } } }
+ before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: departements_tdc.stable_id } } }
- it do
- expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure3))
- expect(flash.notice).to eq 'Les groupes instructeurs ont été ajoutés'
- expect(procedure3.groupe_instructeurs.pluck(:label)).to match_array(['Paris', 'Lyon', 'Marseille'])
- expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
- expect(procedure3.routing_enabled).to be_truthy
+ it do
+ expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure3))
+ expect(flash.notice).to eq 'Les groupes instructeurs ont été ajoutés'
+ expect(procedure3.groupe_instructeurs.pluck(:label)).to include("01 – Ain")
+ expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(departements_tdc.stable_id), constant('01')))
+ expect(procedure3.routing_enabled).to be_truthy
+ end
end
end