From 5f63ade97a423ab51007091996f1552d4a80e526 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 12 Dec 2024 09:50:38 +0100 Subject: [PATCH] same for enums in columns --- app/models/columns/champ_column.rb | 13 +++---------- spec/models/columns/champ_column_spec.rb | 8 -------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/app/models/columns/champ_column.rb b/app/models/columns/champ_column.rb index 4e5813562..c333af916 100644 --- a/app/models/columns/champ_column.rb +++ b/app/models/columns/champ_column.rb @@ -95,9 +95,9 @@ class Columns::ChampColumn < Column when ['drop_down_list', 'text'] # single list can become text value when ['multiple_drop_down_list', 'drop_down_list'] # multi list can become single - parse_enums(value)&.first + parse_enums(value).first when ['multiple_drop_down_list', 'text'] # multi list can become text - parse_enums(value)&.join(', ') + parse_enums(value).join(', ') when ['date', 'datetime'] # date <=> datetime parse_datetime(value)&.to_datetime when ['datetime', 'date'] # may lose some data, but who cares ? @@ -116,14 +116,7 @@ class Columns::ChampColumn < Column end end - def parse_enums(value) - values = JSON.parse(value) - return values if options_for_select.blank? - options = options_for_select.to_set(&:second) - values.filter { options.member?(_1) } - rescue JSON::ParserError - nil - end + def parse_enums(value) = JSON.parse(value) rescue nil def parse_datetime(value) = Time.zone.parse(value) rescue nil end diff --git a/spec/models/columns/champ_column_spec.rb b/spec/models/columns/champ_column_spec.rb index e16302de8..5254dd96a 100644 --- a/spec/models/columns/champ_column_spec.rb +++ b/spec/models/columns/champ_column_spec.rb @@ -131,14 +131,6 @@ describe Columns::ChampColumn do expect(column('simple_drop_down_list').value(champ)).to eq('val1') expect(column('text').value(champ)).to eq('val1, val2') end - - context 'value not in options' do - let(:value) { '["toto","val2"]' } - - it do - expect(column('multiple_drop_down_list').value(champ)).to eq(['val2']) - end - end end end end