2016-08-08 12:52:30 +02:00
|
|
|
shared_examples 'champ_spec' do
|
2017-03-29 13:37:07 +02:00
|
|
|
describe 'mandatory_and_blank?' do
|
2018-02-13 17:00:19 +01:00
|
|
|
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
|
2018-02-09 17:38:30 +01:00
|
|
|
let(:champ) { type_de_champ.champ.build(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_and_blank?).to be(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not blank' do
|
|
|
|
let(:value) { 'yop' }
|
|
|
|
it { expect(champ.mandatory_and_blank?).to be(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not mandatory' do
|
|
|
|
let(:mandatory) { false }
|
|
|
|
it { expect(champ.mandatory_and_blank?).to be(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not mandatory or blank' do
|
|
|
|
let(:value) { 'u' }
|
|
|
|
let(:mandatory) { false }
|
|
|
|
it { expect(champ.mandatory_and_blank?).to be(false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
describe '.departement', vcr: { cassette_name: 'call_geo_api_departements' } do
|
2018-06-15 14:36:48 +02:00
|
|
|
subject { Champs::DepartementChamp.departements }
|
2016-10-19 11:33:21 +02:00
|
|
|
|
|
|
|
it { expect(subject).to include '99 - Étranger' }
|
|
|
|
end
|
2017-06-09 12:04:16 +02:00
|
|
|
|
|
|
|
context "when type_champ=date" do
|
2018-02-14 15:12:57 +01:00
|
|
|
let(:type_de_champ) { create(:type_de_champ_date) }
|
2018-02-09 17:38:30 +01:00
|
|
|
let(:champ) { type_de_champ.champ.create }
|
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
|