From 5a19cc1a0974870b55e02a14b29ba969b5e68599 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 18 Sep 2024 17:21:22 +0200 Subject: [PATCH] remove drop_down_list_value reader --- .../champ_component/champ_component.html.haml | 6 +++++- app/models/type_de_champ.rb | 8 -------- .../20240912091625_clean_drop_down_options.rake_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) 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 d28769213..c79d3f7b5 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 @@ -72,7 +72,11 @@ .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, class: 'fr-input small-margin small width-100', rows: 7, id: dom_id(type_de_champ, :drop_down_list_value) + = form.text_area :drop_down_list_value, + 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) - 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/models/type_de_champ.rb b/app/models/type_de_champ.rb index 43ac688c2..84872c92c 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -490,14 +490,6 @@ class TypeDeChamp < ApplicationRecord end end - def drop_down_list_value - if drop_down_options.present? - drop_down_options.reject(&:empty?).join("\r\n") - else - '' - end - end - def drop_down_list_value=(value) self.drop_down_options = value.to_s.lines.map(&:strip).reject(&:empty?) end diff --git a/spec/lib/tasks/deployment/20240912091625_clean_drop_down_options.rake_spec.rb b/spec/lib/tasks/deployment/20240912091625_clean_drop_down_options.rake_spec.rb index 54bea7982..c1d4b1848 100644 --- a/spec/lib/tasks/deployment/20240912091625_clean_drop_down_options.rake_spec.rb +++ b/spec/lib/tasks/deployment/20240912091625_clean_drop_down_options.rake_spec.rb @@ -27,8 +27,8 @@ describe '20240912091625_clean_drop_down_options.rake' do after { rake_task.reenable } it 'removes the hidden options' do - expect(dashed_drop_down_list.drop_down_list_value).to eq(['1', '2'].join("\r\n")) - expect(witness_drop_down_list.drop_down_list_value).to eq(['1', 'hi', '2'].join("\r\n")) - expect(multiple_drop_down_list.drop_down_list_value).to eq(['1', '2'].join("\r\n")) + expect(dashed_drop_down_list.drop_down_options).to eq(['1', '2']) + expect(witness_drop_down_list.drop_down_options).to eq(['1', 'hi', '2']) + expect(multiple_drop_down_list.drop_down_options).to eq(['1', '2']) end end