From 04892f6c55cbb88cf8e1fd6e39b0d9737b3d6de1 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 28 Jun 2018 08:36:18 +0000 Subject: [PATCH] [#1421] Format value for display --- .../champs/linked_drop_down_list_champ.rb | 4 +++ .../linked_drop_down_list_champ_spec.rb | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index ef02e78f4..74bc55b65 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -28,6 +28,10 @@ class Champs::LinkedDropDownListChamp < Champ :primary_value end + def for_display + [primary_value, secondary_value].compact.join(' / ') + end + private def pack_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 95327e5cb..be847e335 100644 --- a/spec/models/champs/linked_drop_down_list_champ_spec.rb +++ b/spec/models/champs/linked_drop_down_list_champ_spec.rb @@ -15,4 +15,29 @@ describe Champs::LinkedDropDownListChamp do it { expect(champ.value).to eq('["tata","tutu"]') } end + + describe '#for_display' do + let(:champ) { described_class.new(primary_value: primary_value, secondary_value: secondary_value) } + let(:primary_value) { nil } + let(:secondary_value) { nil } + + subject { champ.for_display } + + context 'with no value' do + it { is_expected.to eq('') } + end + + context 'with primary value' do + let(:primary_value) { 'primary' } + + it { is_expected.to eq('primary') } + end + + context 'with secondary value' do + let(:primary_value) { 'primary' } + let(:secondary_value) { 'secondary' } + + it { is_expected.to eq('primary / secondary') } + end + end end