2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-08-18 14:08:38 +02:00
|
|
|
|
describe Champs::CommuneChamp do
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :communes, stable_id: 99 }]) }
|
|
|
|
|
let(:dossier) { create(:dossier, procedure:) }
|
|
|
|
|
|
2021-08-18 14:08:38 +02:00
|
|
|
|
let(:code_insee) { '63102' }
|
2023-03-21 14:47:31 +01:00
|
|
|
|
let(:code_postal) { '63290' }
|
|
|
|
|
let(:code_departement) { '63' }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:champ) do
|
|
|
|
|
described_class.new(stable_id: 99, dossier:).tap do |champ|
|
|
|
|
|
champ.code_postal = code_postal
|
|
|
|
|
champ.external_id = code_insee
|
|
|
|
|
champ.run_callbacks(:save)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-03-21 14:47:31 +01:00
|
|
|
|
|
2023-04-13 13:10:23 +02:00
|
|
|
|
describe 'value' do
|
2024-05-06 21:44:41 +02:00
|
|
|
|
it 'find commune' do
|
2023-04-05 18:02:42 +02:00
|
|
|
|
expect(champ.to_s).to eq('Châteldon (63290)')
|
|
|
|
|
expect(champ.name).to eq('Châteldon')
|
2023-03-21 14:47:31 +01:00
|
|
|
|
expect(champ.external_id).to eq(code_insee)
|
|
|
|
|
expect(champ.code).to eq(code_insee)
|
|
|
|
|
expect(champ.code_departement).to eq(code_departement)
|
|
|
|
|
expect(champ.code_postal).to eq(code_postal)
|
2024-04-02 17:05:44 +02:00
|
|
|
|
expect(champ.for_export(:value)).to eq 'Châteldon (63290)'
|
|
|
|
|
expect(champ.for_export(:code)).to eq '63102'
|
|
|
|
|
expect(champ.for_export(:departement)).to eq '63 – Puy-de-Dôme'
|
2023-03-21 14:47:31 +01:00
|
|
|
|
end
|
2023-04-20 10:16:48 +02:00
|
|
|
|
|
2024-09-05 17:12:13 +02:00
|
|
|
|
context 'with tricky bug (should not happen, but it happens)' do
|
|
|
|
|
let(:champ) do
|
|
|
|
|
described_class.new(stable_id: 99, dossier:).tap do |champ|
|
|
|
|
|
champ.external_id = ''
|
|
|
|
|
champ.value = 'Gagny'
|
|
|
|
|
champ.run_callbacks(:save)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'fails' do
|
|
|
|
|
expect(champ).to receive(:instrument_external_id_error)
|
|
|
|
|
expect(champ.validate(:champs_public_value)).to be_falsey
|
|
|
|
|
expect(champ.errors).to include('external_id')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-06 21:44:41 +02:00
|
|
|
|
context 'with code' do
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:champ) do
|
|
|
|
|
described_class.new(stable_id: 99, dossier:).tap do |champ|
|
|
|
|
|
champ.code = '63102-63290'
|
|
|
|
|
champ.run_callbacks(:save)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-04-20 10:16:48 +02:00
|
|
|
|
|
2024-05-06 21:44:41 +02:00
|
|
|
|
it 'find commune' do
|
|
|
|
|
expect(champ.to_s).to eq('Châteldon (63290)')
|
|
|
|
|
expect(champ.name).to eq('Châteldon')
|
|
|
|
|
expect(champ.external_id).to eq(code_insee)
|
|
|
|
|
expect(champ.code).to eq(code_insee)
|
|
|
|
|
expect(champ.code_departement).to eq(code_departement)
|
|
|
|
|
expect(champ.code_postal).to eq(code_postal)
|
|
|
|
|
expect(champ.for_export(:value)).to eq 'Châteldon (63290)'
|
|
|
|
|
expect(champ.for_export(:code)).to eq '63102'
|
|
|
|
|
expect(champ.for_export(:departement)).to eq '63 – Puy-de-Dôme'
|
|
|
|
|
end
|
2023-04-20 10:16:48 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-08-18 14:08:38 +02:00
|
|
|
|
end
|