From 367f508e2edcb4800c71317c9725194525084dc6 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 6 Sep 2021 17:31:39 +0200 Subject: [PATCH] linked_drop_down_list: empty primary => empty secondary --- app/models/champs/linked_drop_down_list_champ.rb | 6 +++++- spec/models/champs/linked_drop_down_list_champ_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 355f44442..157f4af89 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -41,7 +41,11 @@ class Champs::LinkedDropDownListChamp < Champ end def primary_value=(value) - pack_value(value, secondary_value) + if value.blank? + pack_value("", "") + else + pack_value(value, secondary_value) + end end def secondary_value=(value) diff --git a/spec/models/champs/linked_drop_down_list_champ_spec.rb b/spec/models/champs/linked_drop_down_list_champ_spec.rb index 9d0977716..bf53cc1b4 100644 --- a/spec/models/champs/linked_drop_down_list_champ_spec.rb +++ b/spec/models/champs/linked_drop_down_list_champ_spec.rb @@ -14,6 +14,14 @@ describe Champs::LinkedDropDownListChamp do it { expect(champ.value).to eq('["tata","tutu"]') } end + describe '#primary_value=' do + let!(:champ) { described_class.new(primary_value: 'tata', secondary_value: 'tutu') } + + before { champ.primary_value = '' } + + it { expect(champ.value).to eq('["",""]') } + end + describe '#to_s' do let(:champ) { described_class.new(primary_value: primary_value, secondary_value: secondary_value) } let(:primary_value) { nil }