demarches-normaliennes/spec/models/champs/commune_champ_spec.rb

44 lines
1.6 KiB
Ruby
Raw Normal View History

2021-08-18 14:08:38 +02:00
describe Champs::CommuneChamp do
2023-03-21 14:47:31 +01:00
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
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' }
describe 'value', vcr: { cassette_name: 'api_geo_communes' } do
let(:champ) { create(:champ_communes, code_postal: code_postal) }
2021-08-18 14:08:38 +02:00
2023-03-21 14:47:31 +01:00
it 'with code_postal' do
champ.update(value: code_insee)
expect(champ.name).to eq('Châteldon (63290)')
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).to eq(['Châteldon (63290)', '63102', '63 Puy-de-Dôme'])
expect(champ.communes.size).to eq(8)
end
2023-03-21 14:47:31 +01:00
context 'when code_postal is nil', vcr: { cassette_name: 'api_geo_communes' } do
let(:champ) { create(:champ_communes, external_id: code_insee, code_departement:) }
2023-03-21 14:47:31 +01:00
it 'with value' do
champ.update_column(:value, 'Châteldon (63290)')
expect(champ.name).to eq('Châteldon (63290)')
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 be_nil
expect(champ.code_postal_with_fallback).to eq(code_postal)
expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '63 Puy-de-Dôme'])
expect(champ.communes.size).to eq(8)
end
end
end
2021-08-18 14:08:38 +02:00
end