From 37a7e26fc3fafc08b3183e8c868ba52f97d654b6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:46:22 +0100 Subject: [PATCH 1/8] Remove unused users/carte_controller --- app/controllers/users/carte_controller.rb | 78 ------ app/controllers/users_controller.rb | 35 --- app/services/module_api_carto_service.rb | 24 -- .../user_routes_authorization_service.rb | 8 - .../users/carte_controller_shared_example.rb | 242 ------------------ .../users/carte_controller_spec.rb | 36 --- .../users_controller_shared_example.rb | 43 ---- spec/controllers/users_controller_spec.rb | 30 --- .../user_routes_authorization_service_spec.rb | 53 ---- 9 files changed, 549 deletions(-) delete mode 100644 app/controllers/users/carte_controller.rb delete mode 100644 app/controllers/users_controller.rb delete mode 100644 app/services/user_routes_authorization_service.rb delete mode 100644 spec/controllers/users/carte_controller_shared_example.rb delete mode 100644 spec/controllers/users/carte_controller_spec.rb delete mode 100644 spec/controllers/users_controller_shared_example.rb delete mode 100644 spec/controllers/users_controller_spec.rb delete mode 100644 spec/services/user_routes_authorization_service_spec.rb diff --git a/app/controllers/users/carte_controller.rb b/app/controllers/users/carte_controller.rb deleted file mode 100644 index 9c952d513..000000000 --- a/app/controllers/users/carte_controller.rb +++ /dev/null @@ -1,78 +0,0 @@ -class Users::CarteController < UsersController - before_action only: [:show] do - authorized_routes? self.class - end - - def show - @dossier = current_user_dossier - - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for(root_path) - end - - def save - geo_json = clean_json_latlngs(params[:selection]) - dossier = current_user_dossier - - dossier.quartier_prioritaires.each(&:destroy) - dossier.cadastres.each(&:destroy) - - if geo_json.present? - ModuleApiCartoService.save_qp!(dossier, geo_json) - ModuleApiCartoService.save_cadastre!(dossier, geo_json) - end - - dossier.update!(json_latlngs: geo_json) - - redirect_to brouillon_dossier_path(dossier) - end - - def zones - @dossier = current_user_dossier - @data = {} - - geo_json = JSON.parse(params.fetch(:selection, '[]')) - - if geo_json.first == ["error", "TooManyPolygons"] - @error = true - else - if @dossier.procedure.module_api_carto.quartiers_prioritaires? - quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json) - @dossier.quartier_prioritaires.build(quartiers_prioritaires) - @data[:quartiersPrioritaires] = quartiers_prioritaires - end - - if @dossier.procedure.module_api_carto.cadastre? - cadastres = ModuleApiCartoService.generate_cadastre(geo_json) - @dossier.cadastres.build(cadastres) - @data[:cadastres] = cadastres - end - end - end - - def self.route_authorization - { - states: [Dossier.states.fetch(:brouillon), Dossier.states.fetch(:en_construction)], - api_carto: true - } - end - - private - - def clean_json_latlngs(json_latlngs) - # a polygon must contain at least 4 points - # https://tools.ietf.org/html/rfc7946#section-3.1.6 - if json_latlngs.present? - multipolygone = JSON.parse(json_latlngs) - if multipolygone.first == ["error", "TooManyPolygons"] - [].to_json - else - multipolygone.reject! { |polygone| polygone.count < 4 } - if multipolygone.present? - multipolygone.to_json - end - end - end - end -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb deleted file mode 100644 index b3ba3b69b..000000000 --- a/app/controllers/users_controller.rb +++ /dev/null @@ -1,35 +0,0 @@ -class UsersController < ApplicationController - before_action :authenticate_user! - - def index - redirect_to root_path - end - - def current_user_dossier(dossier_id = nil) - dossier_id ||= params[:dossier_id] || params[:id] - - dossier = Dossier.find(dossier_id) - - if !current_user.owns_or_invite?(dossier) - raise ActiveRecord::RecordNotFound - end - - dossier - end - - def authorized_routes?(controller) - if !UserRoutesAuthorizationService.authorized_route?(controller, current_user_dossier) - redirect_to_root_path 'Le statut de votre dossier n\'autorise pas cette URL' - end - - rescue ActiveRecord::RecordNotFound - redirect_to_root_path 'Vous n’avez pas accès à ce dossier.' - end - - private - - def redirect_to_root_path(message) - flash.alert = message - redirect_to url_for root_path - end -end diff --git a/app/services/module_api_carto_service.rb b/app/services/module_api_carto_service.rb index b372e0870..915905d8b 100644 --- a/app/services/module_api_carto_service.rb +++ b/app/services/module_api_carto_service.rb @@ -1,28 +1,4 @@ class ModuleApiCartoService - def self.save_qp!(dossier, json_latlngs) - if dossier.procedure.module_api_carto.quartiers_prioritaires? - qp_list = generate_qp(JSON.parse(json_latlngs)) - - qp_list.each do |qp| - qp[:dossier_id] = dossier.id - qp[:geometry] = qp[:geometry].to_json - QuartierPrioritaire.create(qp) - end - end - end - - def self.save_cadastre!(dossier, json_latlngs) - if dossier.procedure.module_api_carto.cadastre? - cadastre_list = generate_cadastre JSON.parse(json_latlngs) - - cadastre_list.each do |cadastre| - cadastre[:dossier_id] = dossier.id - cadastre[:geometry] = cadastre[:geometry].to_json - Cadastre.create(cadastre) - end - end - end - def self.generate_qp(coordinates) coordinates.flat_map do |coordinate| ApiCarto::QuartiersPrioritairesAdapter.new( diff --git a/app/services/user_routes_authorization_service.rb b/app/services/user_routes_authorization_service.rb deleted file mode 100644 index dd2cbce18..000000000 --- a/app/services/user_routes_authorization_service.rb +++ /dev/null @@ -1,8 +0,0 @@ -class UserRoutesAuthorizationService - def self.authorized_route?(controller, dossier) - auth = controller.route_authorization - - auth[:states].include?(dossier.state) && - (auth[:api_carto].nil? ? true : auth[:api_carto] == dossier.use_legacy_carto?) - end -end diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb deleted file mode 100644 index 22a2ceb5a..000000000 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ /dev/null @@ -1,242 +0,0 @@ -shared_examples 'carte_controller_spec' do - describe 'GET #show' do - describe 'before_action authorized_routes?' do - context 'when dossier’s procedure have api carto actived' do - context 'when dossier does not have a valid state' do - before do - dossier.state = Dossier.states.fetch(:en_instruction) - dossier.save - - get :show, params: { dossier_id: dossier.id } - end - - it { is_expected.to redirect_to root_path } - end - end - - context 'when dossier’s procedure does not have api carto actived' do - let(:dossier) { create(:dossier) } - - before do - get :show, params: { dossier_id: dossier.id } - end - - it { is_expected.to redirect_to(root_path) } - end - end - - context 'user is not connected' do - before do - sign_out user - end - - it 'redirects to users/sign_in' do - get :show, params: { dossier_id: dossier.id } - expect(response).to redirect_to('/users/sign_in') - end - end - - it 'returns http success if carto is activated' do - get :show, params: { dossier_id: dossier.id } - expect(response).to have_http_status(:success) - end - - context 'when procedure not have activate api carto' do - it 'redirection on user dossier list' do - get :show, params: { dossier_id: dossier_with_no_carto.id } - expect(response).to redirect_to(root_path) - end - end - - context 'when dossier id not exist' do - it 'redirection on user dossier list' do - get :show, params: { dossier_id: bad_dossier_id } - expect(response).to redirect_to(root_path) - end - end - - it_behaves_like "not owner of dossier", :show - end - - describe 'POST #save' do - context 'it cleans json_latlngs' do - let(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction)) } - let(:json_latlngs) { multipolygon.to_json } - - before do - post :save, params: { dossier_id: dossier.id, selection: json_latlngs } - dossier.reload - end - - context 'when json_latlngs is invalid' do - let(:multipolygon) do - [ - [ - { lat: 1, lng: 1 }, - { lat: 1, lng: 2 }, - { lat: 1, lng: 1 } - ] - ] - end - - it { expect(dossier.json_latlngs).to be_nil } - end - - context 'when json_latlngs is valid' do - let(:multipolygon) do - [ - [ - { lat: 1, lng: 1 }, - { lat: 1, lng: 2 }, - { lat: 2, lng: 2 }, - { lat: 1, lng: 1 } - ] - ] - end - - it { expect(dossier.json_latlngs).to eq(json_latlngs) } - end - end - - context 'En train de modifier la localisation' do - let(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction)) } - before do - post :save, params: { dossier_id: dossier.id, selection: '' } - end - - it 'Redirection vers le formulaire de la procedure' do - expect(response).to redirect_to(brouillon_dossier_path(dossier)) - end - end - - describe 'Save quartier prioritaire' do - let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) } - - before do - allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter) - .to receive(:results) - .and_return([{ :code => "QPCODE1234", :nom => "QP de test", :commune => "Paris", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }]) - - post :save, params: { dossier_id: dossier.id, selection: json_latlngs } - end - - context 'when json_latlngs params is empty' do - context 'when dossier have quartier prioritaire in database' do - let!(:dossier) { create(:dossier, :with_two_quartier_prioritaires) } - - before do - dossier.reload - end - - context 'when value is empty' do - let(:json_latlngs) { '' } - it { expect(dossier.quartier_prioritaires.size).to eq(0) } - end - - context 'when value is empty array' do - let(:json_latlngs) { '[]' } - it { expect(dossier.quartier_prioritaires.size).to eq(0) } - end - end - end - - context 'when json_latlngs params is informed' do - let(:json_latlngs) { '[[{"lat":48.87442541960633,"lng":2.3859214782714844},{"lat":48.87273183590832,"lng":2.3850631713867183},{"lat":48.87081237174292,"lng":2.3809432983398438},{"lat":48.8712640169951,"lng":2.377510070800781},{"lat":48.87510283703279,"lng":2.3778533935546875},{"lat":48.87544154230615,"lng":2.382831573486328},{"lat":48.87442541960633,"lng":2.3859214782714844}]]' } - - it { expect(dossier.quartier_prioritaires.size).to eq(1) } - - describe 'Quartier Prioritaire' do - subject { QuartierPrioritaire.last } - - it { expect(subject.code).to eq('QPCODE1234') } - it { expect(subject.commune).to eq('Paris') } - it { expect(subject.nom).to eq('QP de test') } - it { expect(subject.dossier_id).to eq(dossier.id) } - end - end - end - - describe 'Save cadastre' do - let(:module_api_carto) { create(:module_api_carto, :with_cadastre) } - - before do - allow_any_instance_of(ApiCarto::CadastreAdapter) - .to receive(:results) - .and_return([{ :surface_intersection => "0.0006", :surface_parcelle => 11252.692583090324, :numero => "0013", :feuille => 1, :section => "CD", :code_dep => "30", :nom_com => "Le Grau-du-Roi", :code_com => "133", :code_arr => "000", :geometry => { :type => "MultiPolygon", :coordinates => [[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]] } }]) - - post :save, params: { dossier_id: dossier.id, selection: json_latlngs } - end - - context 'when json_latlngs params is empty' do - context 'when dossier have cadastres in database' do - let!(:dossier) { create(:dossier, :with_two_cadastres) } - - before do - dossier.reload - end - - context 'when value is empty' do - let(:json_latlngs) { '' } - it { expect(dossier.cadastres.size).to eq(0) } - end - - context 'when value is empty array' do - let(:json_latlngs) { '[]' } - it { expect(dossier.cadastres.size).to eq(0) } - end - end - end - - context 'when json_latlngs params is informed' do - let(:json_latlngs) { '[[{"lat":48.87442541960633,"lng":2.3859214782714844},{"lat":48.87273183590832,"lng":2.3850631713867183},{"lat":48.87081237174292,"lng":2.3809432983398438},{"lat":48.8712640169951,"lng":2.377510070800781},{"lat":48.87510283703279,"lng":2.3778533935546875},{"lat":48.87544154230615,"lng":2.382831573486328},{"lat":48.87442541960633,"lng":2.3859214782714844}]]' } - - it { expect(dossier.cadastres.size).to eq(1) } - - describe 'Cadastre' do - subject { Cadastre.last } - - it { expect(subject.surface_intersection).to eq('0.0006') } - it { expect(subject.surface_parcelle).to eq(11252.6925830903) } - it { expect(subject.numero).to eq('0013') } - it { expect(subject.feuille).to eq(1) } - it { expect(subject.section).to eq('CD') } - it { expect(subject.code_dep).to eq('30') } - it { expect(subject.nom_com).to eq('Le Grau-du-Roi') } - it { expect(subject.code_com).to eq('133') } - it { expect(subject.code_arr).to eq('000') } - it { expect(subject.geometry).to eq({ "type" => "MultiPolygon", "coordinates" => [[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]] }) } - end - end - end - end - - describe 'POST #zones' do - let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) } - render_views - - before do - allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter) - .to receive(:results) - .and_return([{ :code => "QPCODE1234", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }]) - - post :zones, params: { dossier_id: dossier.id, selection: json_latlngs.to_json }, format: 'js' - end - - context 'when coordinates are empty' do - let(:json_latlngs) { [] } - - it 'Quartier Prioritaire Adapter does not call' do - expect(response.body).to include("DS.cartoDrawZones({\"quartiersPrioritaires\":[]});") - end - end - - context 'when coordinates are informed' do - let(:json_latlngs) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]] } - - it { expect(response.body).not_to be_nil } - it { expect(response.body).to include('QPCODE1234') } - it { expect(response.body).to include('MultiPolygon') } - it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') } - end - end -end diff --git a/spec/controllers/users/carte_controller_spec.rb b/spec/controllers/users/carte_controller_spec.rb deleted file mode 100644 index 5b238161c..000000000 --- a/spec/controllers/users/carte_controller_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper' -require 'controllers/users/carte_controller_shared_example' - -RSpec.describe Users::CarteController, type: :controller do - let(:bad_adresse) { 'babouba' } - - let(:module_api_carto) { create(:module_api_carto, :with_api_carto) } - let(:procedure) { create(:procedure, module_api_carto: module_api_carto) } - let(:dossier) { create(:dossier, procedure: procedure) } - - let(:owner_user) { dossier.user } - let(:invite_by_user) { create :user, email: 'invite@plop.com' } - - let(:dossier_with_no_carto) { create(:dossier) } - let!(:etablissement) { create(:etablissement, dossier: dossier) } - let(:bad_dossier_id) { Dossier.count + 1000 } - let(:adresse) { etablissement.geo_adresse } - - before do - create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email - - sign_in user - end - - context 'when sign in user is the owner' do - let(:user) { owner_user } - - it_should_behave_like "carte_controller_spec" - end - - context 'when sign in user is an invite by owner' do - let(:user) { invite_by_user } - - it_should_behave_like "carte_controller_spec" - end -end diff --git a/spec/controllers/users_controller_shared_example.rb b/spec/controllers/users_controller_shared_example.rb deleted file mode 100644 index 325303c6d..000000000 --- a/spec/controllers/users_controller_shared_example.rb +++ /dev/null @@ -1,43 +0,0 @@ -shared_examples 'current_user_dossier_spec' do - context 'when no dossier_id is filled' do - it { expect { subject.current_user_dossier }.to raise_error ActiveRecord::RecordNotFound } - end - - context 'when dossier_id is given as a param' do - context 'when dossier id is valid' do - it 'returns current user dossier' do - expect(subject.current_user_dossier dossier.id).to eq(dossier) - end - end - - context 'when dossier id is incorrect' do - it { expect { subject.current_user_dossier 666 }.to raise_error ActiveRecord::RecordNotFound } - end - end - - context 'when no params[] is given' do - context 'when dossier id is valid' do - before do - subject.params[:dossier_id] = dossier.id - end - - it 'returns current user dossier' do - expect(subject.current_user_dossier).to eq(dossier) - end - end - - context 'when dossier id is incorrect' do - it { expect { subject.current_user_dossier }.to raise_error ActiveRecord::RecordNotFound } - end - - context 'when dossier_id is given as a param' do - before do - subject.params[:dossier_id] = 1 - end - - it 'returns dossier with the id on params past' do - expect(subject.current_user_dossier dossier.id).to eq(dossier) - end - end - end -end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb deleted file mode 100644 index 0af27ab75..000000000 --- a/spec/controllers/users_controller_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' - -require 'controllers/users_controller_shared_example' - -describe UsersController, type: :controller do - describe '#current_user_dossier' do - let(:owner_user) { create(:user) } - let(:invite_user) { create :user, email: 'invite@plop.com' } - let(:not_invite_user) { create :user, email: 'not_invite@plop.com' } - - let(:dossier) { create(:dossier, user: owner_user) } - - context 'when user is the owner' do - before do - sign_in owner_user - end - - it_should_behave_like "current_user_dossier_spec" - end - - context 'when user is invite by the owner' do - before do - create :invite, email: invite_user.email, dossier: dossier, user: invite_user - sign_in invite_user - end - - it_should_behave_like "current_user_dossier_spec" - end - end -end diff --git a/spec/services/user_routes_authorization_service_spec.rb b/spec/services/user_routes_authorization_service_spec.rb deleted file mode 100644 index a3e0eee5e..000000000 --- a/spec/services/user_routes_authorization_service_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' - -describe UserRoutesAuthorizationService do - describe '#authorize_route?' do - let(:module_api_carto) { create :module_api_carto, use_api_carto: use_api_carto } - let(:procedure) { create :procedure, module_api_carto: module_api_carto } - let(:dossier) { create :dossier, procedure: procedure, state: state } - - let(:use_api_carto) { false } - - subject { described_class.authorized_route? controller, dossier } - - describe 'carte' do - let(:controller) { Users::CarteController } - - context 'when use_api_carto is false' do - describe 'brouillon' do - let(:state) { Dossier.states.fetch(:brouillon) } - it { is_expected.to be_falsey } - end - - describe 'en_construction' do - let(:state) { Dossier.states.fetch(:en_construction) } - it { is_expected.to be_falsey } - end - - describe 'accepte' do - let(:state) { Dossier.states.fetch(:accepte) } - it { is_expected.to be_falsey } - end - end - - context 'when use_api_carto is true' do - let(:use_api_carto) { true } - - describe 'brouillon' do - let(:state) { Dossier.states.fetch(:brouillon) } - it { is_expected.to be_truthy } - end - - describe 'en_construction' do - let(:state) { Dossier.states.fetch(:en_construction) } - it { is_expected.to be_truthy } - end - - describe 'accepte' do - let(:state) { Dossier.states.fetch(:accepte) } - it { is_expected.to be_falsey } - end - end - end - end -end From 5632929d3d7f0c548aba6b3e124a8127db972cc0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:51:16 +0100 Subject: [PATCH 2/8] Remove old caro editor --- app/javascript/old_design/carto.js | 52 ---------------- app/javascript/packs/application-old.js | 2 - app/views/users/carte/_map.html.haml | 8 --- app/views/users/carte/_zones.html.haml | 25 -------- app/views/users/carte/show.html.haml | 28 --------- app/views/users/carte/zones.js.erb | 2 - .../drawing_a_zone_with_freedraw_spec.rb | 57 ------------------ spec/views/users/carte/show.html.haml_spec.rb | 60 ------------------- 8 files changed, 234 deletions(-) delete mode 100644 app/javascript/old_design/carto.js delete mode 100644 app/views/users/carte/_map.html.haml delete mode 100644 app/views/users/carte/_zones.html.haml delete mode 100644 app/views/users/carte/show.html.haml delete mode 100644 app/views/users/carte/zones.js.erb delete mode 100644 spec/features/users/drawing_a_zone_with_freedraw_spec.rb delete mode 100644 spec/views/users/carte/show.html.haml_spec.rb diff --git a/app/javascript/old_design/carto.js b/app/javascript/old_design/carto.js deleted file mode 100644 index 0db35839a..000000000 --- a/app/javascript/old_design/carto.js +++ /dev/null @@ -1,52 +0,0 @@ -import { CREATE } from 'leaflet-freedraw'; -import { on } from '@utils'; -import { getData } from '../shared/data'; -import { - initMap, - geocodeAddress, - drawUserSelection, - drawCadastre, - drawQuartiersPrioritaires, - addFreeDrawEvents -} from '../shared/carte'; - -function initialize() { - const element = document.getElementById('map'); - - if (element) { - const data = getData('carto'); - const map = initMap(element, data.position, true); - - addAddressSelectEvent(map); - - on('#new', 'click', () => { - map.freeDraw.mode(CREATE); - }); - - const cartoDrawZones = data => { - drawCadastre(map, data, true); - drawQuartiersPrioritaires(map, data, true); - }; - - window.DS = { cartoDrawZones }; - - // draw external polygons - cartoDrawZones(data); - - // draw user polygon - drawUserSelection(map, data, true); - addFreeDrawEvents(map, 'input[name=selection]'); - } -} - -addEventListener('turbolinks:load', initialize); - -function addAddressSelectEvent(map) { - on( - '#search-by-address input[type=address]', - 'autocomplete:select', - (_, { label }) => { - geocodeAddress(map, label); - } - ); -} diff --git a/app/javascript/packs/application-old.js b/app/javascript/packs/application-old.js index 8fab56073..3ef0c6774 100644 --- a/app/javascript/packs/application-old.js +++ b/app/javascript/packs/application-old.js @@ -11,8 +11,6 @@ import '../shared/autocomplete'; import '../shared/remote-input'; import '../shared/franceconnect'; -import '../old_design/carto'; - // Start Rails helpers Rails.start(); Turbolinks.start(); diff --git a/app/views/users/carte/_map.html.haml b/app/views/users/carte/_map.html.haml deleted file mode 100644 index b4e8b93e1..000000000 --- a/app/views/users/carte/_map.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -#carte-page.row - .col-md-12.col-lg-12 - #map.carte.edit - - %span.zones - = render partial: 'zones', locals: { dossier: dossier, error: @error } - -= render partial: 'shared/champs/carte/init', locals: { dossier: dossier } diff --git a/app/views/users/carte/_zones.html.haml b/app/views/users/carte/_zones.html.haml deleted file mode 100644 index 9155d85dd..000000000 --- a/app/views/users/carte/_zones.html.haml +++ /dev/null @@ -1,25 +0,0 @@ -- if dossier.procedure.module_api_carto.quartiers_prioritaires? - .col-md-9.col-lg-9#qp.col-md-3.col-lg-3.list - %h3.text-info Quartiers prioritaires - - if dossier.quartier_prioritaires.blank? - Aucun quartier prioritaire sur les zones séléctionnées - - else - %ul - - dossier.quartier_prioritaires.each do |qp| - %li #{qp.commune} : #{qp.nom} - - - if error.present? - %b Merci de dessiner une surface plus petite afin de récupérer les quartiers prioritaires. - -- if dossier.procedure.module_api_carto.cadastre? - .col-md-9.col-lg-9#cadastre.col-md-3.col-lg-3.list - %h3.text-warning Parcelles cadastrales - - if dossier.cadastres.blank? - Aucune parcelle cadastrale sur les zones séléctionnées - - else - %ul - - dossier.cadastres.each do |cadastre| - %li Parcelle nº #{cadastre.numero} - Feuille #{cadastre.code_arr} #{cadastre.section} #{cadastre.feuille} - - - if error.present? - %b Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales. diff --git a/app/views/users/carte/show.html.haml b/app/views/users/carte/show.html.haml deleted file mode 100644 index d536f03e2..000000000 --- a/app/views/users/carte/show.html.haml +++ /dev/null @@ -1,28 +0,0 @@ -.row#carto-page - .col-lg-12.col-md-12.col-sm-12.col-xs-12 - %h2 - Localisation - %h4.text-primary - Positionnez-vous et dessinez sur la carte la zone d'action de votre demande. - %br - - .content{ style: 'margin-bottom: 60px;' } - %button#new.btn.btn-md.btn-success{ type: 'button' } - %i.fa.fa-pencil - Ajouter une zone - - %span#search-by-address{ style: 'margin-left: 20px;' } - %input.form-control{ type: :address, data: { autocomplete: 'address' }, placeholder: 'Rechercher une adresse' } - %br - %br - - = render partial: 'users/carte/map', locals: { dossier: @dossier } - - = form_tag(url_for({ controller: :carte, action: :save, dossier_id: @dossier.id }), class: 'form-inline', method: 'POST') do - %br - %input{ type: 'hidden', value: "#{@dossier.json_latlngs}", name: 'selection', data: { remote: true, url: users_dossier_carte_zones_path(@dossier), method: 'POST' } } - - - if @dossier.brouillon? - = render partial: '/layouts/etape_suivante' - - else - = render partial: '/layouts/modifications_terminees' diff --git a/app/views/users/carte/zones.js.erb b/app/views/users/carte/zones.js.erb deleted file mode 100644 index 34fdb41a0..000000000 --- a/app/views/users/carte/zones.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -DS.cartoDrawZones(<%= raw(@data.to_json) %>); -<%= render_to_element('.zones', partial: 'zones', locals: { dossier: @dossier, error: @error }) %> diff --git a/spec/features/users/drawing_a_zone_with_freedraw_spec.rb b/spec/features/users/drawing_a_zone_with_freedraw_spec.rb deleted file mode 100644 index ef7fe3c92..000000000 --- a/spec/features/users/drawing_a_zone_with_freedraw_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'spec_helper' - -feature 'drawing a zone with freedraw' do - let(:user) { create(:user) } - let(:module_api_carto) { create(:module_api_carto, :with_api_carto) } - let(:procedure) { create(:procedure, module_api_carto: module_api_carto) } - let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, user: user) } - - context 'when user is not logged in' do - before do - visit users_dossier_carte_path dossier_id: dossier.id - end - - scenario 'he is redirected to login page' do - expect(page).to have_css('#new_user') - end - - scenario 'he logs in and he is redirected to carte page', vcr: { cassette_name: 'drawing_a_zone_with_freedraw_redirected_to_carte_page' } do - within('#new_user') do - page.find_by_id('user_email').set user.email - page.find_by_id('user_password').set user.password - page.click_on 'Se connecter' - end - expect(page).to have_css('.content #map') - end - end - - context 'when user is logged in' do - before do - login_as user, scope: :user - end - - context 'when he is visiting the map page' do - before do - visit users_dossier_carte_path dossier_id: dossier.id - end - - context 'when procedure have api carto activated' do - scenario 'he is redirected to carte page', vcr: { cassette_name: 'drawing_a_zone_with_freedraw_redirected_to_carte_page' } do - expect(page).to have_css('.content #map') - end - end - - context 'when procedure does not have api carto activated' do - let(:module_api_carto) { create(:module_api_carto) } - - scenario 'he is redirect to user dossiers index' do - expect(page).to have_css('.dossiers-table') - end - - scenario 'alert message is present' do - expect(page).to have_content('Le statut de votre dossier n\'autorise pas cette URL') - end - end - end - end -end diff --git a/spec/views/users/carte/show.html.haml_spec.rb b/spec/views/users/carte/show.html.haml_spec.rb deleted file mode 100644 index 6aa85457f..000000000 --- a/spec/views/users/carte/show.html.haml_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'spec_helper' - -describe 'users/carte/show.html.haml', type: :view do - let(:state) { Dossier.states.fetch(:brouillon) } - let(:dossier) { create(:dossier, state: state) } - let(:dossier_id) { dossier.id } - - before do - assign(:dossier, dossier) - end - - context 'sur la page de la carte d\'une demande' do - before do - render - end - it 'le formulaire envoie vers /users/dossiers/:dossier_id/carte en #POST' do - expect(rendered).to have_selector("form[action='/users/dossiers/#{dossier_id}/carte'][method=post]") - end - - it 'la carte est bien présente' do - expect(rendered).to have_selector('#map') - end - - context 'présence des inputs hidden' do - it 'stockage du json des polygons dessinés' do - expect(rendered).to have_selector('input[type=hidden][name=selection]', visible: false) - end - end - - context 'si la page précédente n\'est pas la page du dossier' do - it 'le bouton "Etape suivante" est présent' do - expect(rendered).to have_selector('#etape_suivante') - end - - # it 'le bouton Etape suivante possède un onclick correct' do - # expect(rendered).to have_selector('input[type=submit][id=etape_suivante][onclick=\'submit_check_draw(event)\']') - # end - end - - context 'si la page précédente est la page du dossier' do - let(:state) { Dossier.states.fetch(:en_construction) } - - it 'le bouton "Etape suivante" n\'est pas présent' do - expect(rendered).to_not have_selector('#etape_suivante') - end - - it 'le bouton "Modification terminé" est présent' do - expect(rendered).to have_selector('#modification_terminee') - end - - # it 'le bouton "Modification terminé" possède un onclick correct' do - # expect(rendered).to have_selector('input[type=submit][id=modification_terminee][onclick=\'submit_check_draw(event)\']') - # end - - it 'le lien de retour à la page du dossier est présent' do - expect(rendered).to have_selector("a[href='/dossiers/#{dossier_id}']") - end - end - end -end From 36f6f54337c27a8ca5044f9f809189ddda798d39 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:53:13 +0100 Subject: [PATCH 3/8] Remove unused carto models --- app/models/cadastre.rb | 7 --- app/models/dossier.rb | 14 ----- app/models/module_api_carto.rb | 4 -- app/models/procedure.rb | 8 +-- app/models/quartier_prioritaire.rb | 7 --- app/models/user_geometry.rb | 40 ------------- spec/factories/cadastre.rb | 8 --- spec/factories/dossier.rb | 14 ----- spec/factories/module_api_carto.rb | 27 --------- spec/factories/procedure.rb | 13 ----- spec/factories/quartier_prioritaire.rb | 8 --- .../new_user/dossier_creation_spec.rb | 10 +--- spec/models/cadastre_spec.rb | 16 ------ spec/models/dossier_spec.rb | 57 ------------------- spec/models/module_api_carto_spec.rb | 13 ----- spec/models/procedure_spec.rb | 1 - spec/models/quartier_prioritaire_spec.rb | 19 ------- 17 files changed, 3 insertions(+), 263 deletions(-) delete mode 100644 app/models/cadastre.rb delete mode 100644 app/models/quartier_prioritaire.rb delete mode 100644 app/models/user_geometry.rb delete mode 100644 spec/factories/cadastre.rb delete mode 100644 spec/factories/module_api_carto.rb delete mode 100644 spec/factories/quartier_prioritaire.rb delete mode 100644 spec/models/cadastre_spec.rb delete mode 100644 spec/models/module_api_carto_spec.rb delete mode 100644 spec/models/quartier_prioritaire_spec.rb diff --git a/app/models/cadastre.rb b/app/models/cadastre.rb deleted file mode 100644 index 4d356f3cc..000000000 --- a/app/models/cadastre.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Cadastre < ApplicationRecord - belongs_to :dossier, touch: true - - def geometry - JSON.parse(read_attribute(:geometry)) - end -end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index d5d6273c8..386849c83 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -20,8 +20,6 @@ class Dossier < ApplicationRecord has_many :pieces_justificatives, dependent: :destroy has_many :champs, -> { public_only.ordered }, dependent: :destroy has_many :champs_private, -> { private_only.ordered }, class_name: 'Champ', dependent: :destroy - has_many :quartier_prioritaires, dependent: :destroy - has_many :cadastres, dependent: :destroy has_many :commentaires, dependent: :destroy has_many :invites, dependent: :destroy has_many :follows @@ -74,8 +72,6 @@ class Dossier < ApplicationRecord piece_justificative_file_attachment: :blob ], pieces_justificatives: [], - quartier_prioritaires: [], - cadastres: [], etablissement: [], individual: [], user: []) @@ -247,20 +243,10 @@ class Dossier < ApplicationRecord end end - def use_legacy_carto? - procedure.use_legacy_carto? - end - def expose_legacy_carto_api? procedure.expose_legacy_carto_api? end - def user_geometry - if json_latlngs.present? - UserGeometry.new(json_latlngs) - end - end - def geo_position if etablissement.present? point = ApiAdresse::PointAdapter.new(etablissement.geo_adresse).geocode diff --git a/app/models/module_api_carto.rb b/app/models/module_api_carto.rb index 2dee12b93..7d43a418a 100644 --- a/app/models/module_api_carto.rb +++ b/app/models/module_api_carto.rb @@ -1,7 +1,3 @@ class ModuleAPICarto < ApplicationRecord belongs_to :procedure - - validates :use_api_carto, presence: true, allow_blank: true, allow_nil: false - validates :quartiers_prioritaires, presence: true, allow_blank: true, allow_nil: false - validates :cadastre, presence: true, allow_blank: true, allow_nil: false end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 2021d69b2..2498604cf 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -32,7 +32,6 @@ class Procedure < ApplicationRecord accepts_nested_attributes_for :types_de_champ, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true - accepts_nested_attributes_for :module_api_carto accepts_nested_attributes_for :types_de_champ_private mount_uploader :logo, ProcedureLogoUploader @@ -131,12 +130,8 @@ class Procedure < ApplicationRecord publiee? || archivee? end - def use_legacy_carto? - module_api_carto.use_api_carto? && !module_api_carto.migrated? - end - def expose_legacy_carto_api? - module_api_carto.use_api_carto? && module_api_carto.migrated? + module_api_carto&.use_api_carto? && module_api_carto&.migrated? end # Warning: dossier after_save build_default_champs must be removed @@ -207,7 +202,6 @@ class Procedure < ApplicationRecord procedure = self.deep_clone(include: { types_de_piece_justificative: nil, - module_api_carto: nil, attestation_template: nil, types_de_champ: :drop_down_list, types_de_champ_private: :drop_down_list diff --git a/app/models/quartier_prioritaire.rb b/app/models/quartier_prioritaire.rb deleted file mode 100644 index 5e3f37e0b..000000000 --- a/app/models/quartier_prioritaire.rb +++ /dev/null @@ -1,7 +0,0 @@ -class QuartierPrioritaire < ApplicationRecord - belongs_to :dossier, touch: true - - def geometry - JSON.parse(read_attribute(:geometry)) - end -end diff --git a/app/models/user_geometry.rb b/app/models/user_geometry.rb deleted file mode 100644 index 74633bc8d..000000000 --- a/app/models/user_geometry.rb +++ /dev/null @@ -1,40 +0,0 @@ -class UserGeometry - alias :read_attribute_for_serialization :send - - def initialize(json_latlngs) - @json_latlngs = json_latlngs - end - - def geometry - to_geo_json(@json_latlngs) - end - - def type_de_champ - { - id: -1, - libelle: 'user_geometry', - type_champ: 'user_geometry', - order_place: -1, - descripton: '' - } - end - - private - - def to_geo_json(json_latlngs) - json = JSON.parse(json_latlngs) - - coordinates = json.map do |lat_longs| - outbounds = lat_longs.map do |lat_long| - [lat_long['lng'], lat_long['lat']] - end - - [outbounds] - end - - { - type: 'MultiPolygon', - coordinates: coordinates - } - end -end diff --git a/spec/factories/cadastre.rb b/spec/factories/cadastre.rb deleted file mode 100644 index 49f21e5c8..000000000 --- a/spec/factories/cadastre.rb +++ /dev/null @@ -1,8 +0,0 @@ -FactoryBot.define do - factory :cadastre do - numero { '001' } - feuille { 1 } - section { 'OM' } - geometry { '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}' } - end -end diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 7449915f8..ddcef3b01 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -31,20 +31,6 @@ FactoryBot.define do end end - trait :with_two_quartier_prioritaires do - after(:build) do |dossier, _evaluator| - dossier.quartier_prioritaires << create(:quartier_prioritaire) - dossier.quartier_prioritaires << create(:quartier_prioritaire) - end - end - - trait :with_two_cadastres do - after(:build) do |dossier, _evaluator| - dossier.cadastres << create(:cadastre) - dossier.cadastres << create(:cadastre) - end - end - trait :archived do archived { true } end diff --git a/spec/factories/module_api_carto.rb b/spec/factories/module_api_carto.rb deleted file mode 100644 index 6a366c776..000000000 --- a/spec/factories/module_api_carto.rb +++ /dev/null @@ -1,27 +0,0 @@ -FactoryBot.define do - factory :module_api_carto do - use_api_carto { false } - quartiers_prioritaires { false } - cadastre { false } - - trait :with_api_carto do - use_api_carto { true } - end - - trait :with_quartiers_prioritaires do - use_api_carto { true } - quartiers_prioritaires { true } - end - - trait :with_cadastre do - use_api_carto { true } - cadastre { true } - end - - trait :with_qp_and_cadastre do - use_api_carto { true } - quartiers_prioritaires { true } - cadastre { true } - end - end -end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 7206a4504..f9a848939 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -29,13 +29,6 @@ FactoryBot.define do end end - after(:build) do |procedure, _evaluator| - if procedure.module_api_carto.nil? - module_api_carto = create(:module_api_carto) - procedure.module_api_carto = module_api_carto - end - end - trait :with_path do path { generate(:published_path) } end @@ -52,12 +45,6 @@ FactoryBot.define do end end - trait :with_api_carto do - after(:build) do |procedure, _evaluator| - procedure.module_api_carto.use_api_carto = true - end - end - trait :for_individual do after(:build) do |procedure, _evaluator| procedure.for_individual = true diff --git a/spec/factories/quartier_prioritaire.rb b/spec/factories/quartier_prioritaire.rb deleted file mode 100644 index 617ff2f6a..000000000 --- a/spec/factories/quartier_prioritaire.rb +++ /dev/null @@ -1,8 +0,0 @@ -FactoryBot.define do - factory :quartier_prioritaire do - code { 'QPcode' } - commune { 'Paris' } - nom { 'Test des QP' } - geometry { '{"type": "MultiPolygon", "coordinates": [[[[2.37112834276229, 48.8773116214902], [2.37163254350824, 48.8775780792784], [2.37112834276229, 48.8773116214902]]]]}' } - end -end diff --git a/spec/features/new_user/dossier_creation_spec.rb b/spec/features/new_user/dossier_creation_spec.rb index 84fc98621..23785d9cb 100644 --- a/spec/features/new_user/dossier_creation_spec.rb +++ b/spec/features/new_user/dossier_creation_spec.rb @@ -11,7 +11,7 @@ feature 'Creating a new dossier:' do end context 'when the procedure has identification by individual' do - let(:procedure) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative, ask_birthday: ask_birthday) } + let(:procedure) { create(:procedure, :published, :for_individual, :with_type_de_champ, :with_two_type_de_piece_justificative, ask_birthday: ask_birthday) } let(:ask_birthday) { false } let(:expected_birthday) { nil } @@ -25,9 +25,6 @@ feature 'Creating a new dossier:' do it do click_button('Continuer') - expect(page).to have_current_path(users_dossier_carte_path(procedure.dossiers.last.id)) - click_button('Etape suivante') - expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) expect(user.dossiers.first.individual.birthdate).to eq(expected_birthday) @@ -61,7 +58,7 @@ feature 'Creating a new dossier:' do end context 'when identifying through SIRET' do - let(:procedure) { create(:procedure, :published, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) } + let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_two_type_de_piece_justificative) } let(:dossier) { procedure.dossiers.last } before do @@ -86,9 +83,6 @@ feature 'Creating a new dossier:' do expect(page).to have_content('OCTO-TECHNOLOGY') click_on 'Continuer avec ces informations' - expect(page).to have_current_path(users_dossier_carte_path(dossier)) - click_button('Etape suivante') - expect(page).to have_current_path(brouillon_dossier_path(dossier)) end diff --git a/spec/models/cadastre_spec.rb b/spec/models/cadastre_spec.rb deleted file mode 100644 index fd6c8978f..000000000 --- a/spec/models/cadastre_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' - -describe Cadastre do - it { is_expected.to have_db_column(:surface_intersection) } - it { is_expected.to have_db_column(:surface_parcelle) } - it { is_expected.to have_db_column(:numero) } - it { is_expected.to have_db_column(:feuille) } - it { is_expected.to have_db_column(:section) } - it { is_expected.to have_db_column(:code_dep) } - it { is_expected.to have_db_column(:nom_com) } - it { is_expected.to have_db_column(:code_com) } - it { is_expected.to have_db_column(:code_arr) } - it { is_expected.to have_db_column(:geometry) } - - it { is_expected.to belong_to(:dossier) } -end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index e923aca40..a27d889eb 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -754,18 +754,6 @@ describe Dossier do it { is_expected.to eq(modif_date) } end - context 'when a quartier_prioritaire is modified' do - before { dossier.quartier_prioritaires << create(:quartier_prioritaire) } - - it { is_expected.to eq(modif_date) } - end - - context 'when a cadastre is modified' do - before { dossier.cadastres << create(:cadastre) } - - it { is_expected.to eq(modif_date) } - end - context 'when a commentaire is modified' do before { dossier.commentaires << create(:commentaire) } @@ -802,51 +790,6 @@ describe Dossier do end end - describe 'geometry' do - let(:dossier) { create(:dossier, json_latlngs: json_latlngs) } - let(:json_latlngs) { nil } - - subject{ dossier.user_geometry } - - context 'when there are no map' do - it { is_expected.to eq(nil) } - end - - context 'when there are 2 polygones' do - let(:json_latlngs) do - '[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}], - [{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]' - end - - let(:expected) do - { - "type": "MultiPolygon", - "coordinates": - [ - [ - [ - [102.0, 2.0], - [103.0, 3.0], - [102.0, 2.0] - ] - ], - [ - [ - [102.0, 2.0], - [103.0, 3.0], - [102.0, 2.0] - ] - ] - ] - } - end - - subject{ dossier.user_geometry.geometry } - - it { is_expected.to eq(expected) } - end - end - describe "#delete_and_keep_track" do let(:dossier) { create(:dossier) } let(:deleted_dossier) { DeletedDossier.find_by!(dossier_id: dossier.id) } diff --git a/spec/models/module_api_carto_spec.rb b/spec/models/module_api_carto_spec.rb deleted file mode 100644 index 7672fd865..000000000 --- a/spec/models/module_api_carto_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe ModuleAPICarto do - describe 'assocations' do - it { is_expected.to belong_to(:procedure) } - end - - describe 'attributes' do - it { is_expected.to have_db_column(:use_api_carto) } - it { is_expected.to have_db_column(:quartiers_prioritaires) } - it { is_expected.to have_db_column(:cadastre) } - end -end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 9b5c7ece6..aa9934e67 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -357,7 +357,6 @@ describe Procedure do it 'should duplicate specific objects with different id' do expect(subject.id).not_to eq(procedure.id) - expect(subject.module_api_carto).to have_same_attributes_as(procedure.module_api_carto) expect(subject.types_de_piece_justificative.size).to eq procedure.types_de_piece_justificative.size expect(subject.types_de_champ.size).to eq procedure.types_de_champ.size diff --git a/spec/models/quartier_prioritaire_spec.rb b/spec/models/quartier_prioritaire_spec.rb deleted file mode 100644 index fa84ab8ed..000000000 --- a/spec/models/quartier_prioritaire_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe QuartierPrioritaire do - it { is_expected.to have_db_column(:code) } - it { is_expected.to have_db_column(:nom) } - it { is_expected.to have_db_column(:commune) } - it { is_expected.to have_db_column(:geometry) } - - it { is_expected.to belong_to(:dossier) } - - describe 'geometry' do - let(:qp) { create :quartier_prioritaire, geometry: qp_geometry } - let(:qp_geometry) { File.open('spec/fixtures/files/qp_geometry_value.txt').read } - - subject { qp.geometry } - - it { is_expected.to eq JSON.parse(qp_geometry) } - end -end From d988638c581abffabc344062f09fac2bdfe0b47e Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:55:14 +0100 Subject: [PATCH 4/8] Simplify API carte serializer --- app/serializers/champ_serializer.rb | 26 ++++-------- app/serializers/dossier_serializer.rb | 9 +--- app/serializers/procedure_serializer.rb | 6 ++- .../api/v1/dossiers_controller_spec.rb | 42 +------------------ .../api/v1/procedures_controller_spec.rb | 13 +----- spec/serializers/dossier_serializer_spec.rb | 5 +-- 6 files changed, 18 insertions(+), 83 deletions(-) diff --git a/app/serializers/champ_serializer.rb b/app/serializers/champ_serializer.rb index 2638ce622..c6c30a3f9 100644 --- a/app/serializers/champ_serializer.rb +++ b/app/serializers/champ_serializer.rb @@ -11,7 +11,7 @@ class ChampSerializer < ActiveModel::Serializer def value case object - when GeoArea, UserGeometry, Cadastre, QuartierPrioritaire + when GeoArea object.geometry when Champs::CarteChamp if object.value.present? @@ -40,7 +40,7 @@ class ChampSerializer < ActiveModel::Serializer def type_de_champ case object - when GeoArea, UserGeometry, Cadastre, QuartierPrioritaire + when GeoArea legacy_type_de_champ else object.type_de_champ @@ -76,28 +76,18 @@ class ChampSerializer < ActiveModel::Serializer end def legacy_carto_libelle - case object - when UserGeometry, Cadastre, QuartierPrioritaire - object.class.name.underscore.tr('_', ' ') + if object.source == GeoArea.sources.fetch(:selection_utilisateur) + 'user geometry' else - if object.source == GeoArea.sources.fetch(:selection_utilisateur) - 'user geometry' - else - object.source.to_s.tr('_', ' ') - end + object.source.to_s.tr('_', ' ') end end def legacy_carto_type_champ - case object - when UserGeometry, Cadastre, QuartierPrioritaire - object.class.name.underscore + if object.source == GeoArea.sources.fetch(:selection_utilisateur) + 'user_geometry' else - if object.source == GeoArea.sources.fetch(:selection_utilisateur) - 'user_geometry' - else - object.source.to_s - end + object.source.to_s end end end diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index 851cf7f62..869aa727c 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -28,14 +28,7 @@ class DossierSerializer < ActiveModel::Serializer def champs champs = object.champs.to_a - if object.use_legacy_carto? - champs += object.quartier_prioritaires - champs += object.cadastres - - if object.user_geometry.present? - champs << object.user_geometry - end - elsif object.expose_legacy_carto_api? + if object.expose_legacy_carto_api? champ_carte = champs.find do |champ| champ.type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:carte) end diff --git a/app/serializers/procedure_serializer.rb b/app/serializers/procedure_serializer.rb index d1a7a491c..674d8ab91 100644 --- a/app/serializers/procedure_serializer.rb +++ b/app/serializers/procedure_serializer.rb @@ -37,6 +37,10 @@ class ProcedureSerializer < ActiveModel::Serializer end def geographic_information - object.module_api_carto + if object.expose_legacy_carto_api? + object.module_api_carto + else + ModuleAPICarto.new(procedure: object) + end end end diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index d5566f0f2..b62cfc04f 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe API::V1::DossiersController do let(:admin) { create(:administrateur) } let(:token) { admin.renew_api_token } - let(:procedure) { create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) } + let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) } let(:wrong_procedure) { create(:procedure) } it { expect(described_class).to be < APIController } @@ -253,46 +253,6 @@ describe API::V1::DossiersController do it { expect(subject[:type_champ]).to eq('text') } end end - - context 'when the dossier includes a quartier prioritaire' do - before do - dossier.quartier_prioritaires << create(:quartier_prioritaire) - end - - subject do - super().find { |champ| champ[:type_de_champ][:type_champ] == 'quartier_prioritaire' } - end - - it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'quartier prioritaire', type_champ: 'quartier_prioritaire', order_place: -1, descripton: '' }) } - it { expect(subject[:value]).to match(dossier.quartier_prioritaires.first.geometry.symbolize_keys) } - end - - context 'when the dossier includes a cadastre' do - before do - dossier.cadastres << create(:cadastre) - end - - subject do - super().find { |champ| champ[:type_de_champ][:type_champ] == 'cadastre' } - end - - it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'cadastre', type_champ: 'cadastre', order_place: -1, descripton: '' }) } - it { expect(subject[:value]).to match(dossier.cadastres.first.geometry.symbolize_keys) } - end - - context 'when the dossier includes some user geometry' do - before do - dossier.json_latlngs = '[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]' - dossier.save - end - - subject do - super().find { |champ| champ[:type_de_champ][:type_champ] == 'user_geometry' } - end - - it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'user geometry', type_champ: 'user_geometry', order_place: -1, descripton: '' }) } - it { expect(subject[:value]).to match(UserGeometry.new(dossier.json_latlngs).geometry) } - end end describe 'champs_private' do diff --git a/spec/controllers/api/v1/procedures_controller_spec.rb b/spec/controllers/api/v1/procedures_controller_spec.rb index 24eba07ea..08c6d6278 100644 --- a/spec/controllers/api/v1/procedures_controller_spec.rb +++ b/spec/controllers/api/v1/procedures_controller_spec.rb @@ -25,8 +25,7 @@ describe API::V1::ProceduresController, type: :controller do it { is_expected.to have_http_status(200) } describe 'body' do - let(:module_api_carto) { create(:module_api_carto, use_api_carto: true, quartiers_prioritaires: true, cadastre: true) } - let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, module_api_carto: module_api_carto, administrateur: admin) } + let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) } let(:response) { get :show, params: { id: procedure.id, token: token } } subject { JSON.parse(response.body, symbolize_names: true)[:procedure] } @@ -65,16 +64,6 @@ describe API::V1::ProceduresController, type: :controller do it { expect(subject[:libelle]).to eq(pj.libelle) } it { expect(subject[:description]).to eq(pj.description) } end - - it { is_expected.to have_key(:geographic_information) } - - describe 'geographic_information' do - subject { super()[:geographic_information] } - - it { expect(subject[:use_api_carto]).to be_truthy } - it { expect(subject[:quartiers_prioritaires]).to be_truthy } - it { expect(subject[:cadastre]).to be_truthy } - end end end end diff --git a/spec/serializers/dossier_serializer_spec.rb b/spec/serializers/dossier_serializer_spec.rb index e16e6f84e..aa9e51a28 100644 --- a/spec/serializers/dossier_serializer_spec.rb +++ b/spec/serializers/dossier_serializer_spec.rb @@ -18,7 +18,7 @@ describe DossierSerializer do context 'champs' do subject { super()[:champs] } - let(:dossier) { create(:dossier, :en_construction, :with_two_quartier_prioritaires, procedure: create(:procedure, :published, :with_api_carto, :with_type_de_champ)) } + let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure, :published, :with_type_de_champ)) } before do dossier.champs << create(:champ_carte) @@ -29,12 +29,11 @@ describe DossierSerializer do end it { - expect(subject.size).to eq(8) + expect(subject.size).to eq(6) expect(subject[0][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:text)) expect(subject[1][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:carte)) expect(subject[2][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:siret)) - expect(subject[7][:type_de_champ][:type_champ]).to eq('quartier_prioritaire') expect(subject[1][:geo_areas].size).to eq(0) expect(subject[2][:etablissement]).to be_present From 9ff65efea8606dba1b50513ec1fc333e9ad5a9b2 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:56:14 +0100 Subject: [PATCH 5/8] Remove deprecated carto from dossiers controller --- app/controllers/new_user/dossiers_controller.rb | 6 +----- spec/controllers/new_user/dossiers_controller_spec.rb | 8 -------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 1788c4003..57e8e6117 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -61,11 +61,7 @@ module NewUser @dossier.update!(autorisation_donnees: true) flash.notice = "Identité enregistrée" - if @dossier.use_legacy_carto? - redirect_to users_dossier_carte_path(@dossier.id) - else - redirect_to brouillon_dossier_path(@dossier) - end + redirect_to brouillon_dossier_path(@dossier) else flash.now.alert = @dossier.individual.errors.full_messages render :identite diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index b66a5f448..6bc393ea2 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -175,14 +175,6 @@ describe NewUser::DossiersController, type: :controller do it do expect(response).to redirect_to(brouillon_dossier_path(dossier)) end - - context 'on a procedure with carto' do - let(:procedure) { create(:procedure, :for_individual, :with_api_carto) } - - it do - expect(response).to redirect_to(users_dossier_carte_path(dossier)) - end - end end context 'when the identite cannot be updated by the user' do From c6ef30f3e186424fb46fb85c58700dac84229743 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:57:29 +0100 Subject: [PATCH 6/8] Remove unused carto from instructeur interface --- .../new_gestionnaire/dossiers/print.html.haml | 16 ----------- .../new_user/dossiers/etablissement.html.haml | 10 +------ app/views/shared/champs/carte/_init.html.haml | 9 ------- app/views/shared/dossiers/_demande.html.haml | 5 ---- app/views/shared/dossiers/_map.html.haml | 19 ------------- .../dossiers/brouillon.html.haml_spec.rb | 2 +- .../dossiers/identite.html.haml_spec.rb | 2 +- .../dossiers/_demande.html.haml_spec.rb | 8 ------ spec/views/shared/dossiers/_map_spec.rb | 27 ------------------- 9 files changed, 3 insertions(+), 95 deletions(-) delete mode 100644 app/views/shared/champs/carte/_init.html.haml delete mode 100644 app/views/shared/dossiers/_map.html.haml delete mode 100644 spec/views/shared/dossiers/_map_spec.rb diff --git a/app/views/new_gestionnaire/dossiers/print.html.haml b/app/views/new_gestionnaire/dossiers/print.html.haml index 0e9f98214..052b569c3 100644 --- a/app/views/new_gestionnaire/dossiers/print.html.haml +++ b/app/views/new_gestionnaire/dossiers/print.html.haml @@ -17,22 +17,6 @@ - if champs.any? = render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' } -- if @dossier.use_legacy_carto? - %h3 Cartographie - - if @dossier.quartier_prioritaires.any? - %h4 Quartiers prioritaires - %table - - @dossier.quartier_prioritaires.each do |q| - %tr - %td= q.nom - - - if @dossier.cadastres.any? - %h4 Parcelles cadastrales - %table - - @dossier.cadastres.each do |p| - %tr - %td= "Parcelle n° #{p.numero} - Feuille #{p.code_arr} #{p.section} #{p.feuille}" - - if @dossier.types_de_piece_justificative.any? %h3 Pièces jointes diff --git a/app/views/new_user/dossiers/etablissement.html.haml b/app/views/new_user/dossiers/etablissement.html.haml index 822d54325..21bd3755a 100644 --- a/app/views/new_user/dossiers/etablissement.html.haml +++ b/app/views/new_user/dossiers/etablissement.html.haml @@ -24,12 +24,4 @@ .actions = link_to 'Utiliser un autre numéro SIRET', siret_dossier_path(@dossier), class: 'button' - - - if @dossier.use_legacy_carto? - / Until the old layout is gone, we need to disable turbolinks - / to avoid the map loading twice (once for the turbolinks preview, - / once when turbolinks notices the layout are differents and reloads - / the page.) - = link_to 'Continuer avec ces informations', users_dossier_carte_path(@dossier), class: 'button primary', data: { turbolinks: false } - - else - = link_to 'Continuer avec ces informations', brouillon_dossier_path(@dossier), class: 'button primary' + = link_to 'Continuer avec ces informations', brouillon_dossier_path(@dossier), class: 'button primary' diff --git a/app/views/shared/champs/carte/_init.html.haml b/app/views/shared/champs/carte/_init.html.haml deleted file mode 100644 index 049256589..000000000 --- a/app/views/shared/champs/carte/_init.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -:javascript - DATA.push({ - carto: { - position: #{raw(dossier.geo_position.to_json)}, - selection: #{raw(ensure_safe_json(dossier.json_latlngs))}, - cadastres: #{raw(dossier.cadastres.to_json)}, - quartiersPrioritaires: #{raw(dossier.quartier_prioritaires.to_json)} - } - }); diff --git a/app/views/shared/dossiers/_demande.html.haml b/app/views/shared/dossiers/_demande.html.haml index 915af81fd..140c5c27b 100644 --- a/app/views/shared/dossiers/_demande.html.haml +++ b/app/views/shared/dossiers/_demande.html.haml @@ -15,11 +15,6 @@ .card = render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at, profile: profile } - - if dossier.use_legacy_carto? - .tab-title Cartographie - .card - = render partial: "shared/dossiers/map", locals: { dossier: dossier } - - if dossier.types_de_piece_justificative.any? .tab-title Pièces jointes .card diff --git a/app/views/shared/dossiers/_map.html.haml b/app/views/shared/dossiers/_map.html.haml deleted file mode 100644 index a972cc400..000000000 --- a/app/views/shared/dossiers/_map.html.haml +++ /dev/null @@ -1,19 +0,0 @@ -- if dossier.json_latlngs.nil? - %h2.empty-text Non renseigné -- else - #map - - - if dossier.quartier_prioritaires.any? - .card-title Quartiers prioritaires - %ul - - dossier.quartier_prioritaires.each do |q| - %li= q.nom - - - if dossier.cadastres.any? - .card-title Parcelles cadastrales - %ul - - dossier.cadastres.each do |p| - %li - = "Parcelle n° #{p.numero} - Feuille #{p.code_arr} #{p.section} #{p.feuille}" - - = render partial: 'shared/champs/carte/init', locals: { dossier: dossier } diff --git a/spec/views/new_user/dossiers/brouillon.html.haml_spec.rb b/spec/views/new_user/dossiers/brouillon.html.haml_spec.rb index d5951c8f3..c8b916910 100644 --- a/spec/views/new_user/dossiers/brouillon.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/brouillon.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'new_user/dossiers/brouillon.html.haml', type: :view do - let(:procedure) { create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, :with_notice, for_individual: true) } + let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_notice, for_individual: true) } let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: Dossier.states.fetch(:brouillon), procedure: procedure) } let(:footer) { view.content_for(:footer) } diff --git a/spec/views/new_user/dossiers/identite.html.haml_spec.rb b/spec/views/new_user/dossiers/identite.html.haml_spec.rb index 0431dc931..c9db3953e 100644 --- a/spec/views/new_user/dossiers/identite.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/identite.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'new_user/dossiers/identite.html.haml', type: :view do - let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: Dossier.states.fetch(:brouillon), procedure: create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, for_individual: true)) } + let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: Dossier.states.fetch(:brouillon), procedure: create(:procedure, :with_two_type_de_piece_justificative, for_individual: true)) } let(:footer) { view.content_for(:footer) } before do diff --git a/spec/views/shared/dossiers/_demande.html.haml_spec.rb b/spec/views/shared/dossiers/_demande.html.haml_spec.rb index 7cbfddb54..4c1a7d796 100644 --- a/spec/views/shared/dossiers/_demande.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_demande.html.haml_spec.rb @@ -59,12 +59,4 @@ describe 'shared/dossiers/demande.html.haml', type: :view do expect(rendered).to have_text('Pièces jointes') end end - - context 'when the dossier uses maps' do - let(:procedure) { create(:procedure, :published, :with_api_carto) } - - it 'renders the maps infos' do - expect(rendered).to have_text('Cartographie') - end - end end diff --git a/spec/views/shared/dossiers/_map_spec.rb b/spec/views/shared/dossiers/_map_spec.rb deleted file mode 100644 index 250a1fb8d..000000000 --- a/spec/views/shared/dossiers/_map_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'spec_helper' - -describe 'shared/dossiers/map.html.haml', type: :view do - subject do - render(partial: 'shared/dossiers/map.html.haml', locals: { dossier: dossier }) - end - - describe "javascript variables printing" do - let(:dossier) { create(:dossier, json_latlngs: json_latlngs) } - - context 'with a correct json' do - let(:json_latlngs) { "[[{\"lat\":50.659255436656736,\"lng\":3.080635070800781},{\"lat\":50.659255436656736,\"lng\":3.079690933227539},{\"lat\":50.659962770886516,\"lng\":3.0800342559814453},{\"lat\":50.659962770886516,\"lng\":3.0811500549316406},{\"lat\":50.659255436656736,\"lng\":3.080635070800781}]]" } - - before { subject } - - it { expect(rendered).to have_content('selection: [[{"lat":50.659255436656736,"lng":3.080635070800781},{"lat":50.659255436656736,"lng":3.079690933227539},{"lat":50.659962770886516,"lng":3.0800342559814453},{"lat":50.659962770886516,"lng":3.0811500549316406},{"lat":50.659255436656736,"lng":3.080635070800781}]],') } - end - - context 'without a correct json' do - let(:json_latlngs) { "dossier" } - - before { subject } - - it { expect(rendered).to have_content('selection: {},') } - end - end -end From 1897b2775cfb45ae49a02ef25055ae1cae62b8e1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:58:46 +0100 Subject: [PATCH 7/8] 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 From 575a437f97b2a5c256d1dc56f54ce2834e3ef314 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 27 Nov 2018 15:59:09 +0100 Subject: [PATCH 8/8] Remove carto from admin/procedure controller --- .../admin/procedures_controller.rb | 8 +---- .../admin/procedures_controller_spec.rb | 29 +------------------ 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 973776036..0f954bde3 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -58,17 +58,11 @@ class Admin::ProceduresController < AdminController def new @procedure ||= Procedure.new - @procedure.module_api_carto ||= ModuleAPICarto.new @availability = Procedure::PATH_AVAILABLE end def create @procedure = Procedure.new(procedure_params) - - if @procedure.valid? - @procedure.module_api_carto = ModuleAPICarto.new - end - @path = @procedure.path @availability = Procedure.path_availability(current_administrateur, @procedure.path) @@ -268,7 +262,7 @@ class Admin::ProceduresController < AdminController if Flipflop.publish_draft? editable_params << :path end - params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :individual_with_siret, :ask_birthday, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id) + params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :individual_with_siret, :ask_birthday).merge(administrateur_id: current_administrateur.id) end end end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index b755f0a6f..fc0a1f429 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -12,9 +12,6 @@ describe Admin::ProceduresController, type: :controller do let(:organisation) { 'Organisation de test' } let(:direction) { 'Direction de test' } let(:cadre_juridique) { 'cadre juridique' } - let(:use_api_carto) { '0' } - let(:quartiers_prioritaires) { '0' } - let(:cadastre) { '0' } let(:duree_conservation_dossiers_dans_ds) { 3 } let(:duree_conservation_dossiers_hors_ds) { 6 } @@ -27,12 +24,7 @@ describe Admin::ProceduresController, type: :controller do direction: direction, cadre_juridique: cadre_juridique, duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds, - duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds, - module_api_carto_attributes: { - use_api_carto: use_api_carto, - quartiers_prioritaires: quartiers_prioritaires, - cadastre: cadastre - } + duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds } } @@ -255,8 +247,6 @@ describe Admin::ProceduresController, type: :controller do let(:description) { 'blabla' } let(:organisation) { 'plop' } let(:direction) { 'plap' } - let(:use_api_carto) { '1' } - let(:cadastre) { '1' } let(:duree_conservation_dossiers_dans_ds) { 7 } let(:duree_conservation_dossiers_hors_ds) { 5 } @@ -273,14 +263,6 @@ describe Admin::ProceduresController, type: :controller do it { expect(subject.duree_conservation_dossiers_hors_ds).to eq(duree_conservation_dossiers_hors_ds) } end - describe 'procedure module api carto attributs in database' do - subject { procedure.module_api_carto } - - it { expect(subject.use_api_carto).to be_truthy } - it { expect(subject.quartiers_prioritaires).to be_falsey } - it { expect(subject.cadastre).to be_truthy } - end - it { is_expected.to redirect_to(edit_admin_procedure_path id: procedure.id) } it { expect(flash[:notice]).to be_present } end @@ -293,14 +275,6 @@ describe Admin::ProceduresController, type: :controller do describe 'flash message is present' do it { expect(flash[:alert]).to be_present } end - - describe 'procedure module api carto attributs in database' do - subject { procedure.module_api_carto } - - it { expect(subject.use_api_carto).to be_falsey } - it { expect(subject.quartiers_prioritaires).to be_falsey } - it { expect(subject.cadastre).to be_falsey } - end end context 'when procedure is brouillon' do @@ -334,7 +308,6 @@ describe Admin::ProceduresController, type: :controller do it { expect(subject.for_individual).not_to eq procedure_params[:for_individual] } it { expect(subject.individual_with_siret).not_to eq procedure_params[:individual_with_siret] } - it { expect(subject.use_legacy_carto?).not_to eq procedure_params[:module_api_carto_attributes][:use_api_carto] } end end end