Skip to content

Commit

Permalink
rename drop_down_list_value -> drop_down_option_from_text
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim committed Sep 20, 2024
1 parent 66f7d6c commit c67355d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def type_de_champ_update_params
:libelle,
:description,
:mandatory,
:drop_down_list_value,
:drop_down_options_from_text,
:drop_down_other,
:drop_down_secondary_libelle,
:drop_down_secondary_description,
Expand Down
8 changes: 4 additions & 4 deletions app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ def drop_down_options
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]]
Expand All @@ -482,10 +486,6 @@ def drop_down_options_with_other
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/models/type_de_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ def never_valid
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
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
Expand Down

0 comments on commit c67355d

Please sign in to comment.