[#1421] Format value for display

This commit is contained in:
Frederic Merizen 2018-06-28 08:36:18 +00:00
parent 55a685c183
commit 04892f6c55
2 changed files with 29 additions and 0 deletions

View file

@ -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

View file

@ -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