2016-08-08 12:52:30 +02:00
|
|
|
shared_examples 'champ_spec' do
|
2022-06-27 11:55:56 +02:00
|
|
|
describe 'mandatory_blank_and_visible?' do
|
2018-02-13 17:00:19 +01:00
|
|
|
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
|
2020-07-20 17:18:44 +02:00
|
|
|
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
|
2022-06-27 11:55:56 +02:00
|
|
|
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
2017-03-29 13:37:07 +02:00
|
|
|
end
|
|
|
|
|
2018-10-22 14:17:30 +02:00
|
|
|
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 }
|
2022-06-27 11:55:56 +02:00
|
|
|
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
2018-10-22 14:17:30 +02:00
|
|
|
end
|
2021-03-18 14:44:14 +01:00
|
|
|
|
|
|
|
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) }
|
2021-03-18 14:44:14 +01:00
|
|
|
let(:value) { '[]' }
|
2022-06-27 11:55:56 +02:00
|
|
|
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
2021-03-18 14:44:14 +01:00
|
|
|
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) }
|
|
|
|
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ) }
|
|
|
|
|
|
|
|
it { expect(champ.blank?).to be(false) }
|
|
|
|
end
|
2018-10-22 14:17:30 +02:00
|
|
|
|
2017-03-29 13:37:07 +02:00
|
|
|
context 'when not blank' do
|
|
|
|
let(:value) { 'yop' }
|
2022-06-27 11:55:56 +02:00
|
|
|
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
2017-03-29 13:37:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not mandatory' do
|
|
|
|
let(:mandatory) { false }
|
2022-06-27 11:55:56 +02:00
|
|
|
it { expect(champ.mandatory_blank_and_visible?).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 }
|
2022-06-27 11:55:56 +02:00
|
|
|
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
2017-03-29 13:37:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-09 12:04:16 +02:00
|
|
|
context "when type_champ=date" do
|
2020-07-20 17:18:44 +02:00
|
|
|
let(:champ) { build(:champ_date) }
|
2017-06-09 12:04:16 +02:00
|
|
|
|
|
|
|
it "should convert %d/%m/%Y format to ISO" do
|
|
|
|
champ.value = "31/12/2017"
|
|
|
|
champ.save
|
|
|
|
champ.reload
|
|
|
|
expect(champ.value).to eq("2017-12-31")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert to nil if date parse failed" do
|
|
|
|
champ.value = "bla"
|
|
|
|
champ.save
|
|
|
|
champ.reload
|
|
|
|
expect(champ.value).to be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert empty string to nil" do
|
|
|
|
champ.value = ""
|
|
|
|
champ.save
|
|
|
|
champ.reload
|
|
|
|
expect(champ.value).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|