rename drop_down_list_value -> drop_down_option_from_text

This commit is contained in:
simon lehericey 2024-09-19 17:23:26 +02:00
parent 5fc0eb11f5
commit c638ac0261
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
6 changed files with 16 additions and 16 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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