correctif(ChampDepartement): gere les departement a 3 codes
This commit is contained in:
parent
48c80e9387
commit
186d4e6539
7 changed files with 22 additions and 4 deletions
|
@ -55,7 +55,7 @@ class Champs::DepartementChamp < Champs::TextChamp
|
||||||
end
|
end
|
||||||
|
|
||||||
def value=(code)
|
def value=(code)
|
||||||
if code&.size == 2
|
if [2, 3].include?(code&.size)
|
||||||
self.external_id = code
|
self.external_id = code
|
||||||
super(APIGeoService.departement_name(code))
|
super(APIGeoService.departement_name(code))
|
||||||
elsif code.blank?
|
elsif code.blank?
|
||||||
|
|
|
@ -37,6 +37,7 @@ describe API::V2::GraphqlController do
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain')
|
||||||
instructeur.assign_to_procedure(procedure)
|
instructeur.assign_to_procedure(procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
factory :champ_departements, class: 'Champs::DepartementChamp' do
|
factory :champ_departements, class: 'Champs::DepartementChamp' do
|
||||||
type_de_champ { association :type_de_champ_departements, procedure: dossier.procedure }
|
type_de_champ { association :type_de_champ_departements, procedure: dossier.procedure }
|
||||||
value { '971 - Guadeloupe' }
|
value { '01' }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :champ_communes, class: 'Champs::CommuneChamp' do
|
factory :champ_communes, class: 'Champs::CommuneChamp' do
|
||||||
|
|
|
@ -9,7 +9,10 @@ describe '20220705164551_remove_unused_champs' do
|
||||||
rake_task.invoke
|
rake_task.invoke
|
||||||
end
|
end
|
||||||
|
|
||||||
before { champ_repetition.champs.first.update(type_de_champ: create(:type_de_champ)) }
|
before do
|
||||||
|
allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain')
|
||||||
|
champ_repetition.champs.first.update(type_de_champ: create(:type_de_champ))
|
||||||
|
end
|
||||||
after { rake_task.reenable }
|
after { rake_task.reenable }
|
||||||
|
|
||||||
describe 'remove_unused_champs' do
|
describe 'remove_unused_champs' do
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe Champs::DepartementChamp, type: :model do
|
||||||
let(:champ) { described_class.new }
|
let(:champ) { described_class.new }
|
||||||
|
|
||||||
describe 'value', vcr: { cassette_name: 'api_geo_departements' } do
|
describe 'value', vcr: { cassette_name: 'api_geo_departements' } do
|
||||||
it 'with code' do
|
it 'with code having 2 chars' do
|
||||||
champ.value = '01'
|
champ.value = '01'
|
||||||
expect(champ.external_id).to eq('01')
|
expect(champ.external_id).to eq('01')
|
||||||
expect(champ.code).to eq('01')
|
expect(champ.code).to eq('01')
|
||||||
|
@ -19,6 +19,16 @@ describe Champs::DepartementChamp, type: :model do
|
||||||
expect(champ.to_s).to eq('01 – Ain')
|
expect(champ.to_s).to eq('01 – Ain')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'with code having 3 chars' do
|
||||||
|
champ.value = '971'
|
||||||
|
expect(champ.external_id).to eq('971')
|
||||||
|
expect(champ.code).to eq('971')
|
||||||
|
expect(champ.name).to eq('Guadeloupe')
|
||||||
|
expect(champ.value).to eq('Guadeloupe')
|
||||||
|
expect(champ.selected).to eq('971')
|
||||||
|
expect(champ.to_s).to eq('971 – Guadeloupe')
|
||||||
|
end
|
||||||
|
|
||||||
it 'with nil' do
|
it 'with nil' do
|
||||||
champ.write_attribute(:value, 'Ain')
|
champ.write_attribute(:value, 'Ain')
|
||||||
champ.write_attribute(:external_id, '01')
|
champ.write_attribute(:external_id, '01')
|
||||||
|
|
|
@ -1669,6 +1669,7 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#destroy" do
|
describe "#destroy" do
|
||||||
|
before { allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain') }
|
||||||
let(:procedure) { create(:procedure, :with_all_champs, :with_all_annotations) }
|
let(:procedure) { create(:procedure, :with_all_champs, :with_all_annotations) }
|
||||||
let(:transfer) { create(:dossier_transfer) }
|
let(:transfer) { create(:dossier_transfer) }
|
||||||
let(:dossier) { create(:dossier, :with_populated_champs, :with_populated_annotations, transfer: transfer, procedure: procedure) }
|
let(:dossier) { create(:dossier, :with_populated_champs, :with_populated_annotations, transfer: transfer, procedure: procedure) }
|
||||||
|
|
|
@ -3,6 +3,9 @@ require 'csv'
|
||||||
describe ProcedureExportService do
|
describe ProcedureExportService do
|
||||||
let(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs) }
|
let(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs) }
|
||||||
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers) }
|
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers) }
|
||||||
|
before do
|
||||||
|
allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain')
|
||||||
|
end
|
||||||
|
|
||||||
describe 'to_xlsx' do
|
describe 'to_xlsx' do
|
||||||
subject do
|
subject do
|
||||||
|
|
Loading…
Reference in a new issue