demarches-normaliennes/spec/models/champ_shared_example.rb

57 lines
2 KiB
Ruby
Raw Normal View History

shared_examples 'champ_spec' do
describe 'mandatory_blank?' do
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
let(:champ) { build(:champ, type_de_champ: type_de_champ, value: value) }
2017-03-29 13:37:07 +02:00
let(:value) { '' }
let(:mandatory) { true }
context 'when mandatory and blank' do
it { expect(champ.mandatory_blank?).to be(true) }
2017-03-29 13:37:07 +02:00
end
context 'when carte mandatory and blank' do
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
2021-07-21 10:45:59 +02:00
let(:champ) { build(:champ_carte, type_de_champ: type_de_champ, value: value) }
let(:value) { nil }
it { expect(champ.mandatory_blank?).to be(true) }
end
context 'when multiple_drop_down_list mandatory and blank' do
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
2021-07-21 10:45:59 +02:00
let(:champ) { build(:champ_multiple_drop_down_list, type_de_champ: type_de_champ, value: value) }
let(:value) { '[]' }
it { expect(champ.mandatory_blank?).to be(true) }
end
2021-07-21 10:45:59 +02:00
context 'when repetition blank' do
let(:type_de_champ) { build(:type_de_champ_repetition) }
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ, rows: 0) }
it { expect(champ.blank?).to be(true) }
end
context 'when repetition not blank' do
let(:type_de_champ) { build(:type_de_champ_repetition, :with_types_de_champ, procedure: build(:procedure)) }
2021-07-21 10:45:59 +02:00
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ) }
it { expect(champ.blank?).to be(false) }
end
2017-03-29 13:37:07 +02:00
context 'when not blank' do
let(:value) { 'yop' }
it { expect(champ.mandatory_blank?).to be(false) }
2017-03-29 13:37:07 +02:00
end
context 'when not mandatory' do
let(:mandatory) { false }
it { expect(champ.mandatory_blank?).to be(false) }
2017-03-29 13:37:07 +02:00
end
context 'when not mandatory or blank' do
let(:value) { 'u' }
let(:mandatory) { false }
it { expect(champ.mandatory_blank?).to be(false) }
2017-03-29 13:37:07 +02:00
end
end
2017-04-04 15:27:04 +02:00
end