[fix #3315] Migrate service organisme

This commit is contained in:
simon lehericey 2019-02-18 16:18:09 +01:00
parent 0bb4abb3b3
commit 9d92e43d8d
6 changed files with 34 additions and 19 deletions

View file

@ -7,11 +7,10 @@ class Service < ApplicationRecord
enum type_organisme: { enum type_organisme: {
administration_centrale: 'administration_centrale', administration_centrale: 'administration_centrale',
association: 'association', association: 'association',
commune: 'commune', collectivite_territoriale: 'collectivite_territoriale',
departement: 'departement',
etablissement_enseignement: 'etablissement_enseignement', etablissement_enseignement: 'etablissement_enseignement',
prefecture: 'prefecture', operateur_d_etat: "operateur_d_etat",
region: 'region', service_deconcentre_de_l_etat: 'service_deconcentre_de_l_etat',
autre: 'autre' autre: 'autre'
} }

View file

@ -1,10 +1,9 @@
fr: fr:
type_organisme: type_organisme:
administration_centrale: 'administration centrale' administration_centrale: 'Administration centrale'
association: 'association' association: 'Association'
commune: 'commune' collectivite_territoriale: 'Collectivité territoriale'
departement: 'département' etablissement_enseignement: 'Établissement denseignement'
etablissement_enseignement: 'établissement denseignement' operateur_d_etat: "Opérateur d'État"
prefecture: 'préfecture' service_deconcentre_de_l_etat: "Service déconcentré de l'État"
region: 'région' autre: 'Autre'
autre: 'autre'

View file

@ -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

View file

@ -15,7 +15,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
nom: 'super service', nom: 'super service',
organisme: 'organisme', organisme: 'organisme',
siret: '01234567891234', siret: '01234567891234',
type_organisme: 'region', type_organisme: 'association',
email: 'email@toto.com', email: 'email@toto.com',
telephone: '1234', telephone: '1234',
horaires: 'horaires', 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.nom).to eq('super service') }
it { expect(Service.last.organisme).to eq('organisme') } it { expect(Service.last.organisme).to eq('organisme') }
it { expect(Service.last.siret).to eq('01234567891234') } 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.email).to eq('email@toto.com') }
it { expect(Service.last.telephone).to eq('1234') } it { expect(Service.last.telephone).to eq('1234') }
it { expect(Service.last.horaires).to eq('horaires') } it { expect(Service.last.horaires).to eq('horaires') }
@ -49,7 +49,7 @@ describe NewAdministrateur::ServicesController, type: :controller do
describe '#update' do describe '#update' do
let!(:service) { create(:service, administrateur: admin) } 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 before do
sign_in admin sign_in admin
@ -65,12 +65,12 @@ describe NewAdministrateur::ServicesController, type: :controller do
it { expect(flash.alert).to be_nil } it { expect(flash.alert).to be_nil }
it { expect(flash.notice).to eq('nom modifié') } it { expect(flash.notice).to eq('nom modifié') }
it { expect(Service.last.nom).to eq('nom') } 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)) } it { expect(response).to redirect_to(services_path(procedure_id: procedure.id)) }
end end
context 'when updating a service with invalid data' do 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(flash.alert).not_to be_nil }
it { expect(response).to render_template(:edit) } it { expect(response).to render_template(:edit) }

View file

@ -2,7 +2,7 @@ FactoryBot.define do
factory :service do factory :service do
nom { 'service' } nom { 'service' }
organisme { 'organisme' } organisme { 'organisme' }
type_organisme { Service.type_organismes.fetch(:commune) } type_organisme { Service.type_organismes.fetch(:association) }
administrateur { create(:administrateur) } administrateur { create(:administrateur) }
email { 'email@toto.com' } email { 'email@toto.com' }
telephone { '1234' } telephone { '1234' }

View file

@ -5,7 +5,7 @@ describe Service, type: :model do
{ {
nom: 'service des jardins', nom: 'service des jardins',
organisme: 'mairie des iles', organisme: 'mairie des iles',
type_organisme: Service.type_organismes.fetch(:commune), type_organisme: Service.type_organismes.fetch(:association),
email: 'super@email.com', email: 'super@email.com',
telephone: '1212202', telephone: '1212202',
horaires: 'du lundi au vendredi', horaires: 'du lundi au vendredi',