From 2214fc6b86688d80f38e2bcb807597ef604f754e Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 09:48:33 +0200 Subject: [PATCH 1/5] [#1421] Extract contents of both drop down lists --- .../champs/linked_drop_down_list_champ.rb | 1 + .../linked_drop_down_list_type_de_champ.rb | 29 ++++++++++++++ ...inked_drop_down_list_type_de_champ_spec.rb | 40 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 20fb7455a..3d1832fc5 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -1,2 +1,3 @@ class Champs::LinkedDropDownListChamp < Champ + delegate :master_options, :slave_options, to: :type_de_champ end 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 e54cbef7f..1d8b369d2 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 @@ -1,2 +1,31 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypeDeChamp + MASTER_PATTERN = /^--(.*)--$/ + + def master_options + master_options = unpack_options.map(&:first) + if master_options.present? + master_options.unshift('') + end + master_options + end + + def slave_options + slave_options = unpack_options.to_h + if slave_options.present? + slave_options[''] = [] + end + slave_options + end + + private + + def unpack_options + _, *options = drop_down_list.options + chunked = options.slice_before(MASTER_PATTERN) + chunked.map do |chunk| + master, *slave = chunk + slave.unshift('') + [MASTER_PATTERN.match(master)[1], slave] + end + end end diff --git a/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb new file mode 100644 index 000000000..7bbe5a3e5 --- /dev/null +++ b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe TypesDeChamp::LinkedDropDownListTypeDeChamp do + describe '#unpack_options' do + let(:drop_down_list) { build(:drop_down_list, value: menu_options) } + let(:type_de_champ) { described_class.new(drop_down_list: drop_down_list) } + + context 'with no options' do + let(:menu_options) { '' } + it { expect(type_de_champ.slave_options).to eq({}) } + it { expect(type_de_champ.master_options).to eq([]) } + end + + context 'with two master options' do + let(:menu_options) do + <<~END_OPTIONS + --Master 1-- + slave 1.1 + slave 1.2 + --Master 2-- + slave 2.1 + slave 2.2 + slave 2.3 + END_OPTIONS + end + + it do + expect(type_de_champ.slave_options).to eq( + { + '' => [], + 'Master 1' => [ '', 'slave 1.1', 'slave 1.2'], + 'Master 2' => [ '', 'slave 2.1', 'slave 2.2', 'slave 2.3'] + } + ) + end + + it { expect(type_de_champ.master_options).to eq([ '', 'Master 1', 'Master 2' ]) } + end + end +end From 7b1e8c2110e049a6845c2a72925e53f74425c4d7 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 09:50:34 +0200 Subject: [PATCH 2/5] [#1421] Extract values for both drop down lists --- .../champs/linked_drop_down_list_champ.rb | 29 +++++++++++++++++++ .../linked_drop_down_list_champ_spec.rb | 18 ++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 spec/models/champs/linked_drop_down_list_champ_spec.rb diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 3d1832fc5..6bd1f4f9f 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -1,3 +1,32 @@ class Champs::LinkedDropDownListChamp < Champ + attr_reader :master_value, :slave_value delegate :master_options, :slave_options, to: :type_de_champ + + after_initialize :unpack_value + + def unpack_value + if value.present? + master, slave = JSON.parse(value) + else + master = slave = '' + end + @master_value ||= master + @slave_value ||= slave + end + + def master_value=(value) + @master_value = value + pack_value + end + + def slave_value=(value) + @slave_value = value + pack_value + end + + private + + def pack_value + self.value = JSON.generate([ master_value, slave_value ]) + end end diff --git a/spec/models/champs/linked_drop_down_list_champ_spec.rb b/spec/models/champs/linked_drop_down_list_champ_spec.rb new file mode 100644 index 000000000..0b9586203 --- /dev/null +++ b/spec/models/champs/linked_drop_down_list_champ_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Champs::LinkedDropDownListChamp do + describe '#unpack_value' do + let(:champ) { described_class.new(value: '["tata", "tutu"]') } + + it { expect(champ.master_value).to eq('tata') } + it { expect(champ.slave_value).to eq('tutu') } + end + + describe '#pack_value' do + let(:champ) { described_class.new(master_value: 'tata', slave_value: 'tutu') } + + before { champ.save } + + it { expect(champ.value).to eq('["tata","tutu"]') } + end +end From 2f206af0d6c1612f603796b33e1c99864fe90ed3 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 15:23:24 +0200 Subject: [PATCH 3/5] [#1421] Make label clickable for drop-down lists --- app/models/champ.rb | 4 ++++ app/models/champs/linked_drop_down_list_champ.rb | 4 ++++ .../shared/dossiers/editable_champs/_champ_label.html.haml | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index f396e988c..67601b599 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -35,6 +35,10 @@ class Champ < ApplicationRecord end end + def main_value_name + :value + end + private def string_value diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 6bd1f4f9f..aff0259f0 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -24,6 +24,10 @@ class Champs::LinkedDropDownListChamp < Champ pack_value end + def main_value_name + :master_value + end + private def pack_value diff --git a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml index 8c1070299..6ba997ae9 100644 --- a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml +++ b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml @@ -1,4 +1,4 @@ -= form.label :value do += form.label champ.main_value_name do #{champ.libelle} - if champ.mandatory? %span.mandatory * From dad3bc092b0b636cf9471cd7ebff90b39d45d917 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 21 Jun 2018 16:17:59 +0200 Subject: [PATCH 4/5] [#1421] linked dropdwon user view --- .../champs/linked_drop_down_list.js | 30 ++++++++ .../new_user/dossiers_controller.rb | 2 +- .../_linked_drop_down_list.html.haml | 10 +++ .../features/new_user/linked_dropdown_spec.rb | 76 +++++++++++++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/new_design/champs/linked_drop_down_list.js create mode 100644 app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml create mode 100644 spec/features/new_user/linked_dropdown_spec.rb diff --git a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js new file mode 100644 index 000000000..70a3628ca --- /dev/null +++ b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js @@ -0,0 +1,30 @@ +document.addEventListener('turbolinks:load', function() { + var masters, i, master, slave, slaveOptions; + + masters = document.querySelectorAll('select[data-slave-options]'); + for (i = 0; i < masters.length; i++) { + master = masters[i]; + slave = document.querySelector('select[data-slave-id="' + master.dataset.masterId + '"]'); + slaveOptions = JSON.parse(master.dataset.slaveOptions); + + master.addEventListener('change', function(e) { + var option, options, element; + + while ((option = slave.firstChild)) { + slave.removeChild(option); + } + + options = slaveOptions[e.target.value]; + + for (i = 0; i < options.length; i++) { + option = options[i]; + element = document.createElement("option"); + element.textContent = option; + element.value = option; + slave.appendChild(element); + } + + slave.selectedIndex = 0; + }); + } +}); diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 905f78ebe..c90d82075 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -145,7 +145,7 @@ module NewUser def champs_params params.permit(dossier: { champs_attributes: [ - :id, :value, :piece_justificative_file, value: [], + :id, :value, :master_value, :slave_value, :piece_justificative_file, value: [], etablissement_attributes: Champs::SiretChamp::ETABLISSEMENT_ATTRIBUTES ] }) diff --git a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml new file mode 100644 index 000000000..330465aeb --- /dev/null +++ b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml @@ -0,0 +1,10 @@ +- if champ.drop_down_list && champ.drop_down_list.options.any? + - champ_id = champ.object_id + = form.select :master_value, + champ.master_options, + { required: champ.mandatory? }, + { data: { "slave-options" => champ.slave_options, "master-id" => champ_id } } + = form.select :slave_value, + champ.slave_options[champ.master_value], + { required: champ.mandatory? }, + { data: { "slave-id" => champ_id } } diff --git a/spec/features/new_user/linked_dropdown_spec.rb b/spec/features/new_user/linked_dropdown_spec.rb new file mode 100644 index 000000000..9a32d2423 --- /dev/null +++ b/spec/features/new_user/linked_dropdown_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +feature 'linked dropdown lists' do + let(:password) { 'secret_password' } + let!(:user) { create(:user, password: password) } + + let(:list_items) do + <<~END_OF_LIST + --Master 1-- + Slave 1.1 + Slave 1.2 + --Master 2-- + Slave 2.1 + Slave 2.2 + Slave 2.3 + END_OF_LIST + end + let(:drop_down_list) { create(:drop_down_list, value: list_items) } + let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list, libelle: 'linked dropdown', drop_down_list: drop_down_list) } + + let!(:procedure) do + p = create(:procedure, :published, :for_individual) + p.types_de_champ << type_de_champ + p + end + + let(:user_dossier) { user.dossiers.first } + + scenario 'change master value, slave options are updated', js: true do + log_in(user.email, password, procedure) + + fill_individual + + # Select a master value + select('Master 2', from: master_id_for('linked dropdown')) + + # Slave menu reflects chosen master value + expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 2.1', 'Slave 2.2', 'Slave 2.3']) + + # Select another master value + select('Master 1', from: master_id_for('linked dropdown')) + + # Slave menu gets updated + expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 1.1', 'Slave 1.2']) + end + + private + + def log_in(email, password, procedure) + visit "/commencer/#{procedure.procedure_path.path}" + expect(page).to have_current_path(new_user_session_path) + + fill_in 'user_email', with: email + fill_in 'user_password', with: password + click_on 'Se connecter' + expect(page).to have_current_path(identite_dossier_path(user_dossier)) + end + + def fill_individual + fill_in('individual_prenom', with: 'prenom') + fill_in('individual_nom', with: 'nom') + check 'dossier_autorisation_donnees' + click_on 'Continuer' + expect(page).to have_current_path(modifier_dossier_path(user_dossier)) + end + + def master_id_for(libelle) + find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for] + end + + def slave_id_for(libelle) + master_id = master_id_for(libelle) + link = find("\##{master_id}")['data-master-id'] + find("[data-slave-id=\"#{link}\"]")['id'] + end +end From 0cebf60c46e7fdbf0c71ac76ea9ac1cadaa53dc4 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 27 Jun 2018 14:31:34 +0200 Subject: [PATCH 5/5] [#1421] replace master/slave by primary/secondary --- .../champs/linked_drop_down_list.js | 24 +++++------ .../new_user/dossiers_controller.rb | 2 +- .../champs/linked_drop_down_list_champ.rb | 24 +++++------ .../linked_drop_down_list_type_de_champ.rb | 30 ++++++------- .../_linked_drop_down_list.html.haml | 12 +++--- .../features/new_user/linked_dropdown_spec.rb | 42 +++++++++---------- .../linked_drop_down_list_champ_spec.rb | 6 +-- ...inked_drop_down_list_type_de_champ_spec.rb | 28 ++++++------- 8 files changed, 84 insertions(+), 84 deletions(-) diff --git a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js index 70a3628ca..d82bf438f 100644 --- a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js +++ b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js @@ -1,30 +1,30 @@ document.addEventListener('turbolinks:load', function() { - var masters, i, master, slave, slaveOptions; + var primaries, i, primary, secondary, secondaryOptions; - masters = document.querySelectorAll('select[data-slave-options]'); - for (i = 0; i < masters.length; i++) { - master = masters[i]; - slave = document.querySelector('select[data-slave-id="' + master.dataset.masterId + '"]'); - slaveOptions = JSON.parse(master.dataset.slaveOptions); + primaries = document.querySelectorAll('select[data-secondary-options]'); + for (i = 0; i < primaries.length; i++) { + primary = primaries[i]; + secondary = document.querySelector('select[data-secondary-id="' + primary.dataset.primaryId + '"]'); + secondaryOptions = JSON.parse(primary.dataset.secondaryOptions); - master.addEventListener('change', function(e) { + primary.addEventListener('change', function(e) { var option, options, element; - while ((option = slave.firstChild)) { - slave.removeChild(option); + while ((option = secondary.firstChild)) { + secondary.removeChild(option); } - options = slaveOptions[e.target.value]; + options = secondaryOptions[e.target.value]; for (i = 0; i < options.length; i++) { option = options[i]; element = document.createElement("option"); element.textContent = option; element.value = option; - slave.appendChild(element); + secondary.appendChild(element); } - slave.selectedIndex = 0; + secondary.selectedIndex = 0; }); } }); diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index c90d82075..361eb3765 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -145,7 +145,7 @@ module NewUser def champs_params params.permit(dossier: { champs_attributes: [ - :id, :value, :master_value, :slave_value, :piece_justificative_file, value: [], + :id, :value, :primary_value, :secondary_value, :piece_justificative_file, value: [], etablissement_attributes: Champs::SiretChamp::ETABLISSEMENT_ATTRIBUTES ] }) diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index aff0259f0..ef02e78f4 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -1,36 +1,36 @@ class Champs::LinkedDropDownListChamp < Champ - attr_reader :master_value, :slave_value - delegate :master_options, :slave_options, to: :type_de_champ + attr_reader :primary_value, :secondary_value + delegate :primary_options, :secondary_options, to: :type_de_champ after_initialize :unpack_value def unpack_value if value.present? - master, slave = JSON.parse(value) + primary, secondary = JSON.parse(value) else - master = slave = '' + primary = secondary = '' end - @master_value ||= master - @slave_value ||= slave + @primary_value ||= primary + @secondary_value ||= secondary end - def master_value=(value) - @master_value = value + def primary_value=(value) + @primary_value = value pack_value end - def slave_value=(value) - @slave_value = value + def secondary_value=(value) + @secondary_value = value pack_value end def main_value_name - :master_value + :primary_value end private def pack_value - self.value = JSON.generate([ master_value, slave_value ]) + self.value = JSON.generate([ primary_value, secondary_value ]) end end 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 1d8b369d2..6e602a97f 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 @@ -1,31 +1,31 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypeDeChamp - MASTER_PATTERN = /^--(.*)--$/ + PRIMARY_PATTERN = /^--(.*)--$/ - def master_options - master_options = unpack_options.map(&:first) - if master_options.present? - master_options.unshift('') + def primary_options + primary_options = unpack_options.map(&:first) + if primary_options.present? + primary_options.unshift('') end - master_options + primary_options end - def slave_options - slave_options = unpack_options.to_h - if slave_options.present? - slave_options[''] = [] + def secondary_options + secondary_options = unpack_options.to_h + if secondary_options.present? + secondary_options[''] = [] end - slave_options + secondary_options end private def unpack_options _, *options = drop_down_list.options - chunked = options.slice_before(MASTER_PATTERN) + chunked = options.slice_before(PRIMARY_PATTERN) chunked.map do |chunk| - master, *slave = chunk - slave.unshift('') - [MASTER_PATTERN.match(master)[1], slave] + primary, *secondary = chunk + secondary.unshift('') + [PRIMARY_PATTERN.match(primary)[1], secondary] end end end diff --git a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml index 330465aeb..03afe6832 100644 --- a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml +++ b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml @@ -1,10 +1,10 @@ - if champ.drop_down_list && champ.drop_down_list.options.any? - champ_id = champ.object_id - = form.select :master_value, - champ.master_options, + = form.select :primary_value, + champ.primary_options, { required: champ.mandatory? }, - { data: { "slave-options" => champ.slave_options, "master-id" => champ_id } } - = form.select :slave_value, - champ.slave_options[champ.master_value], + { data: { "secondary-options" => champ.secondary_options, "primary-id" => champ_id } } + = form.select :secondary_value, + champ.secondary_options[champ.primary_value], { required: champ.mandatory? }, - { data: { "slave-id" => champ_id } } + { data: { "secondary-id" => champ_id } } diff --git a/spec/features/new_user/linked_dropdown_spec.rb b/spec/features/new_user/linked_dropdown_spec.rb index 9a32d2423..01758f0bc 100644 --- a/spec/features/new_user/linked_dropdown_spec.rb +++ b/spec/features/new_user/linked_dropdown_spec.rb @@ -6,13 +6,13 @@ feature 'linked dropdown lists' do let(:list_items) do <<~END_OF_LIST - --Master 1-- - Slave 1.1 - Slave 1.2 - --Master 2-- - Slave 2.1 - Slave 2.2 - Slave 2.3 + --Primary 1-- + Secondary 1.1 + Secondary 1.2 + --Primary 2-- + Secondary 2.1 + Secondary 2.2 + Secondary 2.3 END_OF_LIST end let(:drop_down_list) { create(:drop_down_list, value: list_items) } @@ -26,22 +26,22 @@ feature 'linked dropdown lists' do let(:user_dossier) { user.dossiers.first } - scenario 'change master value, slave options are updated', js: true do + scenario 'change primary value, secondary options are updated', js: true do log_in(user.email, password, procedure) fill_individual - # Select a master value - select('Master 2', from: master_id_for('linked dropdown')) + # Select a primary value + select('Primary 2', from: primary_id_for('linked dropdown')) - # Slave menu reflects chosen master value - expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 2.1', 'Slave 2.2', 'Slave 2.3']) + # Secondary menu reflects chosen primary value + expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 2.1', 'Secondary 2.2', 'Secondary 2.3']) - # Select another master value - select('Master 1', from: master_id_for('linked dropdown')) + # Select another primary value + select('Primary 1', from: primary_id_for('linked dropdown')) - # Slave menu gets updated - expect(page).to have_select(slave_id_for('linked dropdown'), options: ['', 'Slave 1.1', 'Slave 1.2']) + # Secondary menu gets updated + expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 1.1', 'Secondary 1.2']) end private @@ -64,13 +64,13 @@ feature 'linked dropdown lists' do expect(page).to have_current_path(modifier_dossier_path(user_dossier)) end - def master_id_for(libelle) + def primary_id_for(libelle) find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for] end - def slave_id_for(libelle) - master_id = master_id_for(libelle) - link = find("\##{master_id}")['data-master-id'] - find("[data-slave-id=\"#{link}\"]")['id'] + def secondary_id_for(libelle) + primary_id = primary_id_for(libelle) + link = find("\##{primary_id}")['data-primary-id'] + find("[data-secondary-id=\"#{link}\"]")['id'] end end diff --git a/spec/models/champs/linked_drop_down_list_champ_spec.rb b/spec/models/champs/linked_drop_down_list_champ_spec.rb index 0b9586203..95327e5cb 100644 --- a/spec/models/champs/linked_drop_down_list_champ_spec.rb +++ b/spec/models/champs/linked_drop_down_list_champ_spec.rb @@ -4,12 +4,12 @@ describe Champs::LinkedDropDownListChamp do describe '#unpack_value' do let(:champ) { described_class.new(value: '["tata", "tutu"]') } - it { expect(champ.master_value).to eq('tata') } - it { expect(champ.slave_value).to eq('tutu') } + it { expect(champ.primary_value).to eq('tata') } + it { expect(champ.secondary_value).to eq('tutu') } end describe '#pack_value' do - let(:champ) { described_class.new(master_value: 'tata', slave_value: 'tutu') } + let(:champ) { described_class.new(primary_value: 'tata', secondary_value: 'tutu') } before { champ.save } diff --git a/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb index 7bbe5a3e5..ab0fcf203 100644 --- a/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb +++ b/spec/models/types_de_champ/linked_drop_down_list_type_de_champ_spec.rb @@ -7,34 +7,34 @@ describe TypesDeChamp::LinkedDropDownListTypeDeChamp do context 'with no options' do let(:menu_options) { '' } - it { expect(type_de_champ.slave_options).to eq({}) } - it { expect(type_de_champ.master_options).to eq([]) } + it { expect(type_de_champ.secondary_options).to eq({}) } + it { expect(type_de_champ.primary_options).to eq([]) } end - context 'with two master options' do + context 'with two primary options' do let(:menu_options) do <<~END_OPTIONS - --Master 1-- - slave 1.1 - slave 1.2 - --Master 2-- - slave 2.1 - slave 2.2 - slave 2.3 + --Primary 1-- + secondary 1.1 + secondary 1.2 + --Primary 2-- + secondary 2.1 + secondary 2.2 + secondary 2.3 END_OPTIONS end it do - expect(type_de_champ.slave_options).to eq( + expect(type_de_champ.secondary_options).to eq( { '' => [], - 'Master 1' => [ '', 'slave 1.1', 'slave 1.2'], - 'Master 2' => [ '', 'slave 2.1', 'slave 2.2', 'slave 2.3'] + 'Primary 1' => [ '', 'secondary 1.1', 'secondary 1.2'], + 'Primary 2' => [ '', 'secondary 2.1', 'secondary 2.2', 'secondary 2.3'] } ) end - it { expect(type_de_champ.master_options).to eq([ '', 'Master 1', 'Master 2' ]) } + it { expect(type_de_champ.primary_options).to eq([ '', 'Primary 1', 'Primary 2' ]) } end end end