[#1421] Handle mandatory fields

This commit is contained in:
Frederic Merizen 2018-06-28 08:42:04 +00:00
parent e794515c8e
commit b326cb9c3e
2 changed files with 40 additions and 0 deletions

View file

@ -32,6 +32,10 @@ class Champs::LinkedDropDownListChamp < Champ
[primary_value, secondary_value].compact.join(' / ')
end
def mandatory_and_blank?
mandatory? && (primary_value.blank? || secondary_value.blank?)
end
private
def value_for_export

View file

@ -62,4 +62,40 @@ describe Champs::LinkedDropDownListChamp do
it { is_expected.to eq('primary;secondary') }
end
end
describe '#mandatory_and_blank' do
let(:drop_down_list) { build(:drop_down_list, value: "--Primary--\nSecondary") }
subject { described_class.new(type_de_champ: type_de_champ) }
context 'when the champ is not mandatory' do
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list: drop_down_list) }
it 'blank is fine' do
is_expected.not_to be_mandatory_and_blank
end
end
context 'when the champ is mandatory' do
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: true, drop_down_list: drop_down_list) }
context 'when there is no value' do
it { is_expected.to be_mandatory_and_blank }
end
context 'when there is a primary value' do
before { subject.primary_value = 'Primary' }
context 'when there is no secondary value' do
it { is_expected.to be_mandatory_and_blank }
end
context 'when there is a secondary value' do
before { subject.secondary_value = 'Primary' }
it { is_expected.not_to be_mandatory_and_blank }
end
end
end
end
end