From 1897b2775cfb45ae49a02ef25055ae1cae62b8e1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:58:46 +0100 Subject: [PATCH] Remove old migration task --- ...20181030155307_migrate_carto_to_carte.rake | 80 ------------------- .../2018_10_30_migrate_carto_to_carte_spec.rb | 39 --------- 2 files changed, 119 deletions(-) delete mode 100644 lib/tasks/deployment/20181030155307_migrate_carto_to_carte.rake delete mode 100644 spec/lib/tasks/2018_10_30_migrate_carto_to_carte_spec.rb diff --git a/lib/tasks/deployment/20181030155307_migrate_carto_to_carte.rake b/lib/tasks/deployment/20181030155307_migrate_carto_to_carte.rake deleted file mode 100644 index 1b8a43a8f..000000000 --- a/lib/tasks/deployment/20181030155307_migrate_carto_to_carte.rake +++ /dev/null @@ -1,80 +0,0 @@ -namespace :after_party do - desc 'Deployment task: migrate_carto_to_carte' - task migrate_carto_to_carte: :environment do - def add_champ_carte_if_needed(procedure) - champ_carte = procedure.types_de_champ_ordered.to_a.find do |type_de_champ| - type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:carte) - end - - if champ_carte - puts "Procedure##{procedure.id} already migrated to use champ carte" - else - add_champ_carte(procedure) - end - end - - def add_champ_carte(procedure) - qp = !!procedure.module_api_carto.quartiers_prioritaires - ca = !!procedure.module_api_carto.cadastre - - puts "Creating champ carte on Procedure##{procedure.id} with qp:#{qp} and ca:#{ca}..." - - procedure.types_de_champ.update_all('order_place = order_place + 1') - type_de_champ = procedure.types_de_champ.create( - order_place: 0, - libelle: 'Cartographie', - type_champ: TypeDeChamp.type_champs.fetch(:carte), - quartiers_prioritaires: qp, - cadastres: ca, - mandatory: true - ) - - procedure.dossiers.each do |dossier| - champ = type_de_champ.champ.create(dossier: dossier, value: dossier.json_latlngs) - - if ca && !dossier.cadastres.empty? - puts "Creating Cadastres on Dossier##{dossier.id}..." - dossier.cadastres.each do |cadastre| - champ.geo_areas.create( - source: GeoArea.sources.fetch(:cadastre), - geometry: cadastre.geometry, - surface_intersection: cadastre.surface_intersection, - surface_parcelle: cadastre.surface_parcelle, - numero: cadastre.numero, - feuille: cadastre.feuille, - section: cadastre.section, - code_dep: cadastre.code_dep, - nom_com: cadastre.nom_com, - code_com: cadastre.code_com, - code_arr: cadastre.code_arr - ) - end - end - - if qp && !dossier.quartier_prioritaires.empty? - puts "Creating Quartiers Prioritaires on Dossier##{dossier.id}..." - dossier.quartier_prioritaires.each do |qp| - champ.geo_areas.create( - source: GeoArea.sources.fetch(:quartier_prioritaire), - geometry: qp.geometry, - code: qp.code, - nom: qp.nom, - commune: qp.commune - ) - end - end - end - - procedure.module_api_carto.update(migrated: true) - end - - Procedure.includes(:types_de_champ, dossiers: [:cadastres, :quartier_prioritaires]) - .joins(:module_api_carto) - .where(module_api_cartos: { use_api_carto: true, migrated: nil }) - .find_each do |procedure| - add_champ_carte_if_needed(procedure) - end - - AfterParty::TaskRecord.create version: '20181030155307' - end -end diff --git a/spec/lib/tasks/2018_10_30_migrate_carto_to_carte_spec.rb b/spec/lib/tasks/2018_10_30_migrate_carto_to_carte_spec.rb deleted file mode 100644 index 8b7702eb5..000000000 --- a/spec/lib/tasks/2018_10_30_migrate_carto_to_carte_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'spec_helper' - -describe '2018_10_30_migrate_carto_to_carte' do - let(:rake_task) { Rake::Task['after_party:migrate_carto_to_carte'] } - let(:procedure) { create(:procedure, :published, :with_api_carto) } - let(:dossier) { create(:dossier, :with_two_quartier_prioritaires, :with_two_cadastres) } - - def run_task - procedure.module_api_carto.quartiers_prioritaires = true - procedure.module_api_carto.cadastre = true - procedure.module_api_carto.save - procedure.dossiers << dossier - - rake_task.invoke - procedure.reload - dossier.reload - end - - after { rake_task.reenable } - - context 'on happy path' do - before do - run_task - end - - it { - expect(procedure.module_api_carto.migrated?).to be_truthy - expect(dossier.cadastres.count).to eq(2) - expect(dossier.quartier_prioritaires.count).to eq(2) - expect(dossier.champs.first.type_champ).to eq('carte') - expect(dossier.champs.first.order_place).to eq(0) - expect(dossier.champs.first.libelle).to eq('Cartographie') - expect(dossier.champs.first.geo_areas.count).to eq(4) - expect(dossier.champs.first.mandatory?).to be_truthy - expect(dossier.champs.first.cadastres?).to be_truthy - expect(dossier.champs.first.quartiers_prioritaires?).to be_truthy - } - end -end