diff --git a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml index c79d3f7b5..4b2fd7062 100644 --- a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml +++ b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml @@ -71,12 +71,12 @@ - if type_de_champ.drop_down_list? .flex.column.justify-start.width-33 .cell - = form.label :drop_down_list_value, "Options de la liste", for: dom_id(type_de_champ, :drop_down_list_value) - = form.text_area :drop_down_list_value, + = form.label :drop_down_options_from_text, "Options de la liste", for: dom_id(type_de_champ, :drop_down_options_from_text) + = form.text_area :drop_down_options_from_text, value: type_de_champ.drop_down_options.join("\r\n"), class: 'fr-input small-margin small width-100', rows: 7, - id: dom_id(type_de_champ, :drop_down_list_value) + id: dom_id(type_de_champ, :drop_down_options_from_text) - if type_de_champ.simple_drop_down_list? .cell = form.label :drop_down_other, for: dom_id(type_de_champ, :drop_down_other) do diff --git a/app/controllers/administrateurs/types_de_champ_controller.rb b/app/controllers/administrateurs/types_de_champ_controller.rb index 8af2b8546..0fee638ec 100644 --- a/app/controllers/administrateurs/types_de_champ_controller.rb +++ b/app/controllers/administrateurs/types_de_champ_controller.rb @@ -153,7 +153,7 @@ module Administrateurs :libelle, :description, :mandatory, - :drop_down_list_value, + :drop_down_options_from_text, :drop_down_other, :drop_down_secondary_libelle, :drop_down_secondary_description, diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index d65bb609d..cb393890d 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -480,6 +480,10 @@ class TypeDeChamp < ApplicationRecord Array.wrap(super) end + def drop_down_options_from_text=(text) + self.drop_down_options = text.to_s.lines.map(&:strip).reject(&:empty?) + end + def drop_down_options_with_other if drop_down_other? drop_down_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]] @@ -488,10 +492,6 @@ class TypeDeChamp < ApplicationRecord end end - def drop_down_list_value=(value) - self.drop_down_options = value.to_s.lines.map(&:strip).reject(&:empty?) - end - def header_section_level_value if header_section_level.presence header_section_level.to_i diff --git a/lib/tasks/deployment/20200618121241_drop_down_list_options_to_json.rake b/lib/tasks/deployment/20200618121241_drop_down_list_options_to_json.rake index 7a264aa12..df4c67b55 100644 --- a/lib/tasks/deployment/20200618121241_drop_down_list_options_to_json.rake +++ b/lib/tasks/deployment/20200618121241_drop_down_list_options_to_json.rake @@ -15,7 +15,7 @@ namespace :after_party do progress = ProgressReport.new(types_de_champ.count) types_de_champ.find_each do |type_de_champ| - type_de_champ.drop_down_list_value = type_de_champ.drop_down_list_value + type_de_champ.drop_down_options_from_text = type_de_champ.drop_down_list_value if type_de_champ.save type_de_champ.drop_down_list.destroy diff --git a/spec/models/type_de_champ_spec.rb b/spec/models/type_de_champ_spec.rb index f676cb119..94e5ad974 100644 --- a/spec/models/type_de_champ_spec.rb +++ b/spec/models/type_de_champ_spec.rb @@ -196,13 +196,13 @@ describe TypeDeChamp do let(:type_de_champ) { create(:type_de_champ_drop_down_list) } it "splits input" do - type_de_champ.drop_down_list_value = nil + type_de_champ.drop_down_options_from_text = nil expect(type_de_champ.drop_down_options).to eq([]) - type_de_champ.drop_down_list_value = "\n\r" + type_de_champ.drop_down_options_from_text = "\n\r" expect(type_de_champ.drop_down_options).to eq([]) - type_de_champ.drop_down_list_value = " 1 / 2 \r\n 3" + type_de_champ.drop_down_options_from_text = " 1 / 2 \r\n 3" expect(type_de_champ.drop_down_options).to eq(['1 / 2', '3']) end end diff --git a/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb b/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb index 3a825b41e..a4d60e3f4 100644 --- a/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb +++ b/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb @@ -10,23 +10,23 @@ RSpec.describe TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp do end describe '#example_value' do - let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_list_value: drop_down_list_value, procedure: procedure) } + let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_options_from_text: drop_down_options_from_text, procedure: procedure) } subject(:example_value) { described_class.new(type_de_champ, procedure.active_revision).example_value } context 'when the multiple drop down list has no option' do - let(:drop_down_list_value) { "" } + let(:drop_down_options_from_text) { "" } it { expect(example_value).to eq(nil) } end context 'when the multiple drop down list only has one option' do - let(:drop_down_list_value) { "value" } + let(:drop_down_options_from_text) { "value" } it { expect(example_value).to eq("value") } end context 'when the multiple drop down list has two options or more' do - let(:drop_down_list_value) { "value1\r\nvalue2\r\nvalue3" } + let(:drop_down_options_from_text) { "value1\r\nvalue2\r\nvalue3" } it { expect(example_value).to eq(["value1", "value2"]) } end