Merge pull request #2930 from tchak/migrate-carto
Task to migrate carto to champ carte
This commit is contained in:
commit
4df346b946
35 changed files with 402 additions and 211 deletions
|
@ -66,7 +66,7 @@ class Admin::ProceduresController < AdminController
|
|||
@procedure = Procedure.new(procedure_params)
|
||||
|
||||
if @procedure.valid?
|
||||
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params)
|
||||
@procedure.module_api_carto = ModuleAPICarto.new
|
||||
end
|
||||
|
||||
@path = @procedure.path
|
||||
|
@ -271,8 +271,4 @@ class Admin::ProceduresController < AdminController
|
|||
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)
|
||||
end
|
||||
end
|
||||
|
||||
def create_module_api_carto_params
|
||||
params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,7 +61,7 @@ module NewUser
|
|||
@dossier.update!(autorisation_donnees: true)
|
||||
flash.notice = "Identité enregistrée"
|
||||
|
||||
if @dossier.procedure.module_api_carto.use_api_carto
|
||||
if @dossier.use_legacy_carto?
|
||||
redirect_to users_dossier_carte_path(@dossier.id)
|
||||
else
|
||||
redirect_to brouillon_dossier_path(@dossier)
|
||||
|
|
|
@ -43,7 +43,27 @@ class Champs::CarteChamp < Champ
|
|||
end
|
||||
end
|
||||
|
||||
def zones
|
||||
value.blank? ? [] : JSON.parse(value)
|
||||
def geo_json
|
||||
@geo_json ||= value.blank? ? [] : JSON.parse(value)
|
||||
end
|
||||
|
||||
def user_geometry
|
||||
{
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
geo_json[0].map do |polygon|
|
||||
[polygon['lat'], polygon['lng']]
|
||||
end
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def user_geo_area
|
||||
if geo_json.present?
|
||||
GeoArea.new(
|
||||
geometry: user_geometry,
|
||||
source: GeoArea.sources.fetch(:selection_utilisateur)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -245,6 +245,14 @@ 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)
|
||||
|
|
|
@ -23,7 +23,8 @@ class GeoArea < ApplicationRecord
|
|||
enum source: {
|
||||
quartier_prioritaire: 'quartier_prioritaire',
|
||||
cadastre: 'cadastre',
|
||||
parcelle_agricole: 'parcelle_agricole'
|
||||
parcelle_agricole: 'parcelle_agricole',
|
||||
selection_utilisateur: 'selection_utilisateur'
|
||||
}
|
||||
|
||||
scope :quartiers_prioritaires, -> { where(source: sources.fetch(:quartier_prioritaire)) }
|
||||
|
|
|
@ -30,8 +30,6 @@ class Procedure < ApplicationRecord
|
|||
has_one_attached :notice
|
||||
has_one_attached :deliberation
|
||||
|
||||
delegate :use_api_carto, to: :module_api_carto
|
||||
|
||||
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
|
||||
|
@ -133,6 +131,14 @@ 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?
|
||||
end
|
||||
|
||||
# Warning: dossier after_save build_default_champs must be removed
|
||||
# to save a dossier created from this method
|
||||
def new_dossier
|
||||
|
|
|
@ -5,7 +5,7 @@ class UserGeometry
|
|||
@json_latlngs = json_latlngs
|
||||
end
|
||||
|
||||
def value
|
||||
def geometry
|
||||
to_geo_json(@json_latlngs)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
class CadastreSerializer < ActiveModel::Serializer
|
||||
attributes :value, :type_de_champ
|
||||
|
||||
def value
|
||||
object.geometry
|
||||
end
|
||||
|
||||
def type_de_champ
|
||||
{
|
||||
id: -1,
|
||||
libelle: 'cadastre',
|
||||
type_champ: 'cadastre',
|
||||
order_place: -1,
|
||||
descripton: ''
|
||||
}
|
||||
end
|
||||
end
|
|
@ -5,11 +5,99 @@ class ChampSerializer < ActiveModel::Serializer
|
|||
|
||||
has_one :type_de_champ
|
||||
|
||||
has_many :geo_areas, if: :include_geo_areas?
|
||||
has_one :etablissement, if: :include_etablissement?
|
||||
has_one :entreprise, if: :include_etablissement?
|
||||
|
||||
def value
|
||||
if object.piece_justificative_file.attached?
|
||||
url_for(object.piece_justificative_file)
|
||||
case object
|
||||
when GeoArea, UserGeometry, Cadastre, QuartierPrioritaire
|
||||
object.geometry
|
||||
when Champs::CarteChamp
|
||||
if object.value.present?
|
||||
JSON.parse(object.value)
|
||||
end
|
||||
when Champs::DecimalNumberChamp
|
||||
if object.value.present?
|
||||
object.value.to_f
|
||||
end
|
||||
when Champs::IntegerNumberChamp
|
||||
if object.value.present?
|
||||
object.value.to_i
|
||||
end
|
||||
when Champs::LinkedDropDownListChamp
|
||||
if object.value.present?
|
||||
{ primary: object.primary_value, secondary: object.secondary_value }
|
||||
end
|
||||
when Champs::PieceJustificativeChamp
|
||||
if object.piece_justificative_file.attached?
|
||||
url_for(object.piece_justificative_file)
|
||||
end
|
||||
else
|
||||
object.value
|
||||
end
|
||||
end
|
||||
|
||||
def type_de_champ
|
||||
case object
|
||||
when GeoArea, UserGeometry, Cadastre, QuartierPrioritaire
|
||||
legacy_type_de_champ
|
||||
else
|
||||
object.type_de_champ
|
||||
end
|
||||
end
|
||||
|
||||
def etablissement
|
||||
object.etablissement
|
||||
end
|
||||
|
||||
def entreprise
|
||||
object.etablissement&.entreprise
|
||||
end
|
||||
|
||||
def include_etablissement?
|
||||
object.is_a?(Champs::SiretChamp)
|
||||
end
|
||||
|
||||
def include_geo_areas?
|
||||
object.is_a?(Champs::CarteChamp)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def legacy_type_de_champ
|
||||
{
|
||||
id: -1,
|
||||
libelle: legacy_carto_libelle,
|
||||
type_champ: legacy_carto_type_champ,
|
||||
order_place: -1,
|
||||
descripton: ''
|
||||
}
|
||||
end
|
||||
|
||||
def legacy_carto_libelle
|
||||
case object
|
||||
when UserGeometry, Cadastre, QuartierPrioritaire
|
||||
object.class.name.underscore.tr('_', ' ')
|
||||
else
|
||||
if object.source == GeoArea.sources.fetch(:selection_utilisateur)
|
||||
'user geometry'
|
||||
else
|
||||
object.source.to_s.tr('_', ' ')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def legacy_carto_type_champ
|
||||
case object
|
||||
when UserGeometry, Cadastre, QuartierPrioritaire
|
||||
object.class.name.underscore
|
||||
else
|
||||
if object.source == GeoArea.sources.fetch(:selection_utilisateur)
|
||||
'user_geometry'
|
||||
else
|
||||
object.source.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
class Champs::CarteChampSerializer < ChampSerializer
|
||||
has_many :geo_areas
|
||||
|
||||
def value
|
||||
if object.value.present?
|
||||
JSON.parse(object.value)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
class Champs::DecimalNumberChampSerializer < ChampSerializer
|
||||
def value
|
||||
if object.value.present?
|
||||
object.value.to_f
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
class Champs::IntegerNumberChampSerializer < ChampSerializer
|
||||
def value
|
||||
if object.value.present?
|
||||
object.value.to_i
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
class Champs::LinkedDropDownListChampSerializer < ChampSerializer
|
||||
def value
|
||||
{ primary: object.primary_value, secondary: object.secondary_value }
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
class Champs::SiretChampSerializer < ChampSerializer
|
||||
has_one :etablissement
|
||||
has_one :entreprise
|
||||
|
||||
def etablissement
|
||||
object.etablissement
|
||||
end
|
||||
|
||||
def entreprise
|
||||
object.etablissement&.entreprise
|
||||
end
|
||||
end
|
|
@ -23,11 +23,30 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
has_many :pieces_justificatives
|
||||
has_many :types_de_piece_justificative
|
||||
|
||||
has_many :champs do
|
||||
champs = object.champs + object.quartier_prioritaires + object.cadastres
|
||||
if object.user_geometry.present?
|
||||
champs << object.user_geometry
|
||||
has_many :champs, serializer: ChampSerializer
|
||||
|
||||
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?
|
||||
champ_carte = champs.find do |champ|
|
||||
champ.type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:carte)
|
||||
end
|
||||
|
||||
if champ_carte.present?
|
||||
carto_champs = champ_carte.geo_areas.to_a
|
||||
carto_champs << champ_carte.user_geo_area
|
||||
champs += carto_champs.compact
|
||||
end
|
||||
end
|
||||
|
||||
champs
|
||||
end
|
||||
|
||||
|
@ -74,19 +93,4 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
def processed_at
|
||||
object.processed_at&.in_time_zone('UTC')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_geometry(dossier)
|
||||
{
|
||||
value: dossier.geometry,
|
||||
type_de_champ: {
|
||||
id: -1,
|
||||
libelle: 'user_geometry',
|
||||
type_champ: 'user_geometry',
|
||||
order_place: -1,
|
||||
descripton: ''
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
class QuartierPrioritaireSerializer < ActiveModel::Serializer
|
||||
attributes :value, :type_de_champ
|
||||
|
||||
def value
|
||||
object.geometry
|
||||
end
|
||||
|
||||
def type_de_champ
|
||||
{
|
||||
id: -1,
|
||||
libelle: 'quartier prioritaire',
|
||||
type_champ: 'quartier_prioritaire',
|
||||
order_place: -1,
|
||||
descripton: ''
|
||||
}
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
class UserGeometrySerializer < ActiveModel::Serializer
|
||||
attributes :value, :type_de_champ
|
||||
end
|
|
@ -3,6 +3,6 @@ class UserRoutesAuthorizationService
|
|||
auth = controller.route_authorization
|
||||
|
||||
auth[:states].include?(dossier.state) &&
|
||||
(auth[:api_carto].nil? ? true : auth[:api_carto] == dossier.procedure.use_api_carto)
|
||||
(auth[:api_carto].nil? ? true : auth[:api_carto] == dossier.use_legacy_carto?)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -119,30 +119,6 @@
|
|||
Afficher le drapeau européen
|
||||
|
||||
- if !@procedure.locked?
|
||||
.row
|
||||
.col-md-6
|
||||
%h4 Cartographie
|
||||
|
||||
= f.fields_for :module_api_carto, @procedure.module_api_carto do |ff|
|
||||
.checkbox
|
||||
%label
|
||||
= ff.check_box :use_api_carto, id: "procedure-module-api-carto-use-api-carto"
|
||||
Utilisation de la cartographie
|
||||
|
||||
%ul#modules-api-carto
|
||||
%li
|
||||
.checkbox
|
||||
%label
|
||||
= ff.check_box :quartiers_prioritaires
|
||||
Quartiers prioritaires
|
||||
%li
|
||||
.checkbox
|
||||
%label
|
||||
= ff.check_box :cadastre
|
||||
Cadastre
|
||||
|
||||
.col-md-6
|
||||
|
||||
.row
|
||||
.col-md-6
|
||||
%h4 Particuliers
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
- if champs.any?
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' }
|
||||
|
||||
- if @dossier.procedure.use_api_carto
|
||||
- if @dossier.use_legacy_carto?
|
||||
%h3 Cartographie
|
||||
- if @dossier.quartier_prioritaires.any?
|
||||
%h4 Quartiers prioritaires
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
.actions
|
||||
= link_to 'Utiliser un autre numéro SIRET', siret_dossier_path(@dossier), class: 'button'
|
||||
|
||||
- if @dossier.procedure.use_api_carto
|
||||
- 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
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
- elsif champ.value.blank?
|
||||
Aucune zone tracée
|
||||
- elsif champ.quartiers_prioritaires.blank?
|
||||
= t('errors.messages.quartiers_prioritaires_empty', count: champ.zones.size)
|
||||
= t('errors.messages.quartiers_prioritaires_empty', count: champ.geo_json.size)
|
||||
- else
|
||||
%ul
|
||||
- champ.quartiers_prioritaires.each do |qp|
|
||||
|
@ -20,7 +20,7 @@
|
|||
- elsif champ.value.blank?
|
||||
Aucune zone tracée
|
||||
- elsif champ.cadastres.blank?
|
||||
= t('errors.messages.cadastres_empty', count: champ.zones.size)
|
||||
= t('errors.messages.cadastres_empty', count: champ.geo_json.size)
|
||||
- else
|
||||
%ul
|
||||
- champ.cadastres.each do |pc|
|
||||
|
@ -34,7 +34,7 @@
|
|||
- elsif champ.value.blank?
|
||||
Aucune zone tracée
|
||||
- elsif champ.parcelles_agricoles.blank?
|
||||
= t('errors.messages.parcelles_agricoles_empty', count: champ.zones.size)
|
||||
= t('errors.messages.parcelles_agricoles_empty', count: champ.geo_json.size)
|
||||
- else
|
||||
%ul
|
||||
- champ.parcelles_agricoles.each do |pa|
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
.card
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at, profile: profile }
|
||||
|
||||
- if dossier.procedure.use_api_carto
|
||||
- if dossier.use_legacy_carto?
|
||||
.tab-title Cartographie
|
||||
.card
|
||||
= render partial: "shared/dossiers/map", locals: { dossier: dossier }
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddMigratedToModuleAPICartos < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :module_api_cartos, :migrated, :boolean
|
||||
end
|
||||
end
|
|
@ -408,6 +408,7 @@ ActiveRecord::Schema.define(version: 2018_11_08_151929) do
|
|||
t.boolean "cadastre", default: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "migrated"
|
||||
t.index ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
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
|
|
@ -201,18 +201,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
|
||||
let(:procedure) { Procedure.last }
|
||||
let(:use_api_carto) { '1' }
|
||||
let(:quartiers_prioritaires) { '1' }
|
||||
|
||||
subject { ModuleAPICarto.last }
|
||||
|
||||
it { expect(subject.procedure).to eq(procedure) }
|
||||
it { expect(subject.use_api_carto).to be_truthy }
|
||||
it { expect(subject.quartiers_prioritaires).to be_truthy }
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) }
|
||||
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
|
@ -346,7 +334,7 @@ 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_api_carto).not_to eq procedure_params[:module_api_carto_attributes][:use_api_carto] }
|
||||
it { expect(subject.use_legacy_carto?).not_to eq procedure_params[:module_api_carto_attributes][:use_api_carto] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) }
|
||||
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(:wrong_procedure) { create(:procedure) }
|
||||
|
||||
it { expect(described_class).to be < APIController }
|
||||
|
@ -290,8 +290,8 @@ describe API::V1::DossiersController 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).value) }
|
||||
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
|
||||
|
||||
|
|
|
@ -28,4 +28,41 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
factory :champ_integer_number, class: 'Champs::IntegerNumberChamp' do
|
||||
type_de_champ { create(:type_de_champ_integer_number) }
|
||||
value { '42' }
|
||||
end
|
||||
|
||||
factory :champ_decimal_number, class: 'Champs::DecimalNumberChamp' do
|
||||
type_de_champ { create(:type_de_champ_decimal_number) }
|
||||
value { '42.1' }
|
||||
end
|
||||
|
||||
factory :champ_linked_drop_down_list, class: 'Champs::LinkedDropDownListChamp' do
|
||||
type_de_champ { create(:type_de_champ_linked_drop_down_list) }
|
||||
value { '{}' }
|
||||
end
|
||||
|
||||
factory :champ_carte, class: 'Champs::CarteChamp' do
|
||||
type_de_champ { create(:type_de_champ_carte) }
|
||||
end
|
||||
|
||||
factory :champ_siret, class: 'Champs::SiretChamp' do
|
||||
type_de_champ { create(:type_de_champ_siret) }
|
||||
value { '44011762001530' }
|
||||
etablissement { create(:etablissement) }
|
||||
|
||||
before(:create) do |champ, evaluator|
|
||||
champ.etablissement.signature = champ.etablissement.sign
|
||||
end
|
||||
end
|
||||
|
||||
factory :champ_piece_justificative, class: 'Champs::PieceJustificativeChamp' do
|
||||
type_de_champ { create(:type_de_champ_piece_justificative) }
|
||||
|
||||
after(:create) do |champ, evaluator|
|
||||
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
39
spec/lib/tasks/2018_10_30_migrate_carto_to_carte_spec.rb
Normal file
39
spec/lib/tasks/2018_10_30_migrate_carto_to_carte_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
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
|
|
@ -841,7 +841,7 @@ describe Dossier do
|
|||
}
|
||||
end
|
||||
|
||||
subject{ dossier.user_geometry.value }
|
||||
subject{ dossier.user_geometry.geometry }
|
||||
|
||||
it { is_expected.to eq(expected) }
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ describe ChampSerializer do
|
|||
context 'when type champ is piece justificative' do
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
let(:champ) { create(:champ, type_de_champ: create(:type_de_champ_piece_justificative)) }
|
||||
let(:champ) { create(:champ_piece_justificative) }
|
||||
|
||||
before { champ.piece_justificative_file.attach({ filename: __FILE__, io: File.open(__FILE__) }) }
|
||||
after { champ.piece_justificative_file.purge }
|
||||
|
@ -18,5 +18,45 @@ describe ChampSerializer do
|
|||
|
||||
it { is_expected.to include(value: "blah") }
|
||||
end
|
||||
|
||||
context 'when type champ is carte' do
|
||||
let(:geo_area) { create(:geo_area) }
|
||||
let(:champ) { create(:type_de_champ_carte).champ.create(geo_areas: [geo_area]) }
|
||||
|
||||
context 'and geo_area is cadastre' do
|
||||
it {
|
||||
expect(subject[:geo_areas].first).to include(
|
||||
source: GeoArea.sources.fetch(:cadastre),
|
||||
numero: '42',
|
||||
feuille: 'A11'
|
||||
)
|
||||
expect(subject[:geo_areas].first.key?(:nom)).to be_falsey
|
||||
}
|
||||
end
|
||||
|
||||
context 'and geo_area is quartier_prioritaire' do
|
||||
let(:geo_area) { create(:geo_area, :quartier_prioritaire) }
|
||||
|
||||
it {
|
||||
expect(subject[:geo_areas].first).to include(
|
||||
source: GeoArea.sources.fetch(:quartier_prioritaire),
|
||||
nom: 'XYZ',
|
||||
commune: 'Paris'
|
||||
)
|
||||
expect(subject[:geo_areas].first.key?(:numero)).to be_falsey
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type champ is siret' do
|
||||
let(:etablissement) { create(:etablissement) }
|
||||
let(:champ) { create(:type_de_champ_siret).champ.create(etablissement: etablissement, value: etablissement.siret) }
|
||||
|
||||
it {
|
||||
is_expected.to include(value: etablissement.siret)
|
||||
expect(subject[:etablissement]).to include(siret: etablissement.siret)
|
||||
expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
describe Champs::CarteChampSerializer do
|
||||
describe '#attributes' do
|
||||
subject { Champs::CarteChampSerializer.new(champ).serializable_hash }
|
||||
|
||||
context 'when type champ is carte' do
|
||||
let(:geo_area) { create(:geo_area) }
|
||||
let(:champ) { create(:type_de_champ_carte).champ.create(geo_areas: [geo_area]) }
|
||||
|
||||
context 'and geo_area is cadastre' do
|
||||
it {
|
||||
expect(subject[:geo_areas].first).to include(
|
||||
source: GeoArea.sources.fetch(:cadastre),
|
||||
numero: '42',
|
||||
feuille: 'A11'
|
||||
)
|
||||
expect(subject[:geo_areas].first.key?(:nom)).to be_falsey
|
||||
}
|
||||
end
|
||||
|
||||
context 'and geo_area is quartier_prioritaire' do
|
||||
let(:geo_area) { create(:geo_area, :quartier_prioritaire) }
|
||||
|
||||
it {
|
||||
expect(subject[:geo_areas].first).to include(
|
||||
source: GeoArea.sources.fetch(:quartier_prioritaire),
|
||||
nom: 'XYZ',
|
||||
commune: 'Paris'
|
||||
)
|
||||
expect(subject[:geo_areas].first.key?(:numero)).to be_falsey
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
describe Champs::SiretChampSerializer do
|
||||
describe '#attributes' do
|
||||
subject { Champs::SiretChampSerializer.new(champ).serializable_hash }
|
||||
|
||||
context 'when type champ is siret' do
|
||||
let(:etablissement) { create(:etablissement) }
|
||||
let(:champ) { create(:type_de_champ_siret).champ.create(etablissement: etablissement, value: etablissement.siret) }
|
||||
|
||||
it {
|
||||
is_expected.to include(value: etablissement.siret)
|
||||
expect(subject[:etablissement]).to include(siret: etablissement.siret)
|
||||
expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,5 +14,36 @@ describe DossierSerializer do
|
|||
|
||||
it { is_expected.to include(received_at: dossier.en_instruction_at) }
|
||||
end
|
||||
|
||||
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)) }
|
||||
|
||||
before do
|
||||
dossier.champs << create(:champ_carte)
|
||||
dossier.champs << create(:champ_siret)
|
||||
dossier.champs << create(:champ_integer_number)
|
||||
dossier.champs << create(:champ_decimal_number)
|
||||
dossier.champs << create(:champ_linked_drop_down_list)
|
||||
end
|
||||
|
||||
it {
|
||||
expect(subject.size).to eq(8)
|
||||
|
||||
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
|
||||
expect(subject[2][:entreprise]).to be_present
|
||||
|
||||
expect(subject[3][:value]).to eq(42)
|
||||
expect(subject[4][:value]).to eq(42.1)
|
||||
expect(subject[5][:value]).to eq({ primary: nil, secondary: nil })
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue