From c578c88f48e1ff997e6826c947dbbdd913607fe6 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 12 Dec 2024 09:46:59 +0100 Subject: [PATCH] always show user choice even if no more in enum in columns --- app/models/columns/champ_column.rb | 11 +++-------- spec/models/columns/champ_column_spec.rb | 8 -------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/app/models/columns/champ_column.rb b/app/models/columns/champ_column.rb index b4c3977b9..4e5813562 100644 --- a/app/models/columns/champ_column.rb +++ b/app/models/columns/champ_column.rb @@ -70,7 +70,7 @@ class Columns::ChampColumn < Column when :date parse_datetime(value)&.to_date when :enum - parse_enum(value) + value when :enums parse_enums(value) else @@ -91,9 +91,9 @@ class Columns::ChampColumn < Column when ['integer_number', 'text'], ['decimal_number', 'text'] # number to text value when ['drop_down_list', 'multiple_drop_down_list'] # single list can become multi - [parse_enum(value)].compact_blank + [value] when ['drop_down_list', 'text'] # single list can become text - parse_enum(value) + value when ['multiple_drop_down_list', 'drop_down_list'] # multi list can become single parse_enums(value)&.first when ['multiple_drop_down_list', 'text'] # multi list can become text @@ -116,11 +116,6 @@ class Columns::ChampColumn < Column end end - def parse_enum(value) - return value if options_for_select.blank? - value if options_for_select.to_set(&:second).member?(value) - end - def parse_enums(value) values = JSON.parse(value) return values if options_for_select.blank? diff --git a/spec/models/columns/champ_column_spec.rb b/spec/models/columns/champ_column_spec.rb index af5cec1fa..e16302de8 100644 --- a/spec/models/columns/champ_column_spec.rb +++ b/spec/models/columns/champ_column_spec.rb @@ -121,14 +121,6 @@ describe Columns::ChampColumn do expect(column('multiple_drop_down_list').value(champ)).to eq(['val1']) expect(column('text').value(champ)).to eq('val1') end - - context 'value not in options' do - let(:value) { 'toto' } - - it do - expect(column('simple_drop_down_list').value(champ)).to eq(nil) - end - end end context 'from a multiple_drop_down_list' do