[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: {
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'
}

View file

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

View file

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

View file

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