add champ validation
This commit is contained in:
parent
c76d1043fa
commit
40d0cfcdc4
5 changed files with 76 additions and 6 deletions
|
@ -33,4 +33,64 @@ describe Champs::CnafChamp, type: :model do
|
|||
it { expect(JSON.parse(champ.external_id)).to eq({ "code_postal" => "12345", "numero_allocataire" => "1234567" }) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validate' do
|
||||
let(:numero_allocataire) { '1234567' }
|
||||
let(:code_postal) { '12345' }
|
||||
let(:champ) { described_class.new(dossier: create(:dossier), type_de_champ: create(:type_de_champ_cnaf)) }
|
||||
|
||||
subject { champ.valid? }
|
||||
|
||||
before do
|
||||
champ.numero_allocataire = numero_allocataire
|
||||
champ.code_postal = code_postal
|
||||
end
|
||||
|
||||
context 'when numero_allocataire and code_postal are valids' do
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when numero_allocataire and code_postal are nil' do
|
||||
let(:numero_allocataire) { nil }
|
||||
let(:code_postal) { nil }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when only code_postal is nil' do
|
||||
let(:code_postal) { nil }
|
||||
|
||||
it do
|
||||
is_expected.to be false
|
||||
expect(champ.errors.full_messages).to eq(["Code postal doit posséder 5 caractères"])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when only numero_allocataire is nil' do
|
||||
let(:numero_allocataire) { nil }
|
||||
|
||||
it do
|
||||
is_expected.to be false
|
||||
expect(champ.errors.full_messages).to eq(["Numero allocataire doit être composé au maximum de 7 chiffres"])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when numero_allocataire is invalid' do
|
||||
let(:numero_allocataire) { '123456a' }
|
||||
|
||||
it do
|
||||
is_expected.to be false
|
||||
expect(champ.errors.full_messages).to eq(["Numero allocataire doit être composé au maximum de 7 chiffres"])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when code_postal is invalid' do
|
||||
let(:code_postal) { '123456' }
|
||||
|
||||
it do
|
||||
is_expected.to be false
|
||||
expect(champ.errors.full_messages).to eq(["Code postal doit posséder 5 caractères"])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue