From 9d92e43d8d8fde3e6d691a270b75878f33941f88 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 18 Feb 2019 16:18:09 +0100 Subject: [PATCH] [fix #3315] Migrate service organisme --- app/models/service.rb | 7 +++---- config/locales/models/service/fr.yml | 15 +++++++-------- .../2019_02_18_migrate_service_organisme.rake | 17 +++++++++++++++++ .../services_controller_spec.rb | 10 +++++----- spec/factories/service.rb | 2 +- spec/models/service_spec.rb | 2 +- 6 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 lib/tasks/2019_02_18_migrate_service_organisme.rake diff --git a/app/models/service.rb b/app/models/service.rb index 5305c2989..4f8cab66c 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -7,11 +7,10 @@ class Service < ApplicationRecord enum type_organisme: { administration_centrale: 'administration_centrale', association: 'association', - commune: 'commune', - departement: 'departement', + collectivite_territoriale: 'collectivite_territoriale', etablissement_enseignement: 'etablissement_enseignement', - prefecture: 'prefecture', - region: 'region', + operateur_d_etat: "operateur_d_etat", + service_deconcentre_de_l_etat: 'service_deconcentre_de_l_etat', autre: 'autre' } diff --git a/config/locales/models/service/fr.yml b/config/locales/models/service/fr.yml index 4a573ecc4..68e032c8d 100644 --- a/config/locales/models/service/fr.yml +++ b/config/locales/models/service/fr.yml @@ -1,10 +1,9 @@ fr: type_organisme: - administration_centrale: 'administration centrale' - association: 'association' - commune: 'commune' - departement: 'département' - etablissement_enseignement: 'établissement d’enseignement' - prefecture: 'préfecture' - region: 'région' - autre: 'autre' + administration_centrale: 'Administration centrale' + association: 'Association' + collectivite_territoriale: 'Collectivité territoriale' + etablissement_enseignement: 'Établissement d’enseignement' + operateur_d_etat: "Opérateur d'État" + service_deconcentre_de_l_etat: "Service déconcentré de l'État" + autre: 'Autre' diff --git a/lib/tasks/2019_02_18_migrate_service_organisme.rake b/lib/tasks/2019_02_18_migrate_service_organisme.rake new file mode 100644 index 000000000..369a85a5f --- /dev/null +++ b/lib/tasks/2019_02_18_migrate_service_organisme.rake @@ -0,0 +1,17 @@ +namespace :after_party do + desc 'Deployment task: migrate service organisme' + task migrate_service_organisme: :environment do + table = { + 'commune': 'collectivite_territoriale', + 'departement': 'collectivite_territoriale', + 'region': 'collectivite_territoriale', + 'prefecture': 'service_deconcentre_de_l_etat' + } + + table.each do |(old_name, new_name)| + Service.where(type_organisme: old_name).update_all(type_organisme: new_name) + end + + AfterParty::TaskRecord.create version: '20190201121252' + end +end diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index 081603342..e020d9751 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -15,7 +15,7 @@ describe NewAdministrateur::ServicesController, type: :controller do nom: 'super service', organisme: 'organisme', siret: '01234567891234', - type_organisme: 'region', + type_organisme: 'association', email: 'email@toto.com', telephone: '1234', horaires: 'horaires', @@ -30,7 +30,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(Service.last.nom).to eq('super service') } it { expect(Service.last.organisme).to eq('organisme') } it { expect(Service.last.siret).to eq('01234567891234') } - it { expect(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:region)) } + it { expect(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:association)) } it { expect(Service.last.email).to eq('email@toto.com') } it { expect(Service.last.telephone).to eq('1234') } it { expect(Service.last.horaires).to eq('horaires') } @@ -49,7 +49,7 @@ describe NewAdministrateur::ServicesController, type: :controller do describe '#update' do let!(:service) { create(:service, administrateur: admin) } - let(:service_params) { { nom: 'nom', type_organisme: Service.type_organismes.fetch(:region) } } + let(:service_params) { { nom: 'nom', type_organisme: Service.type_organismes.fetch(:association) } } before do sign_in admin @@ -65,12 +65,12 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(flash.alert).to be_nil } it { expect(flash.notice).to eq('nom modifié') } it { expect(Service.last.nom).to eq('nom') } - it { expect(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:region)) } + it { expect(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:association)) } it { expect(response).to redirect_to(services_path(procedure_id: procedure.id)) } end context 'when updating a service with invalid data' do - let(:service_params) { { nom: '', type_organisme: Service.type_organismes.fetch(:region) } } + let(:service_params) { { nom: '', type_organisme: Service.type_organismes.fetch(:association) } } it { expect(flash.alert).not_to be_nil } it { expect(response).to render_template(:edit) } diff --git a/spec/factories/service.rb b/spec/factories/service.rb index 710721e7c..889a80240 100644 --- a/spec/factories/service.rb +++ b/spec/factories/service.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :service do nom { 'service' } organisme { 'organisme' } - type_organisme { Service.type_organismes.fetch(:commune) } + type_organisme { Service.type_organismes.fetch(:association) } administrateur { create(:administrateur) } email { 'email@toto.com' } telephone { '1234' } diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 2a24cc89f..e34f56dac 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -5,7 +5,7 @@ describe Service, type: :model do { nom: 'service des jardins', organisme: 'mairie des iles', - type_organisme: Service.type_organismes.fetch(:commune), + type_organisme: Service.type_organismes.fetch(:association), email: 'super@email.com', telephone: '1212202', horaires: 'du lundi au vendredi',