Merge pull request #2892 from tchak/carte-rpg

Add RPG carte source
This commit is contained in:
Paul Chavard 2018-10-23 18:18:48 +02:00 committed by GitHub
commit f0610c493c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 404 additions and 86 deletions

View file

@ -46,6 +46,14 @@ class Champs::CarteController < ApplicationController
qp
end
end
if @champ.parcelles_agricoles?
parcelles_agricoles = ModuleApiCartoService.generate_rpg(geo_json)
geo_areas += parcelles_agricoles.map do |parcelle_agricole|
parcelle_agricole[:source] = GeoArea.sources.fetch(:parcelle_agricole)
parcelle_agricole
end
end
end
@champ.geo_areas = geo_areas.map do |geo_area|

View file

@ -10,7 +10,8 @@ module ChampHelper
position: champ.position,
selection: champ.value.present? ? JSON.parse(champ.value) : [],
quartiersPrioritaires: champ.quartiers_prioritaires? ? champ.quartiers_prioritaires : [],
cadastres: champ.cadastres? ? champ.cadastres : []
cadastres: champ.cadastres? ? champ.cadastres : [],
parcellesAgricoles: champ.parcelles_agricoles? ? champ.parcelles_agricoles : []
}.to_json)
# rubocop:enable Rails/OutputSafety
end

View file

@ -6,6 +6,7 @@ import {
geocodeAddress,
drawCadastre,
drawQuartiersPrioritaires,
drawParcellesAgricoles,
drawUserSelection,
addFreeDrawEvents
} from '../../shared/carte';
@ -30,6 +31,7 @@ function diplayMap(element, data, initial = false) {
// draw external polygons
drawCadastre(map, data, editable);
drawQuartiersPrioritaires(map, data, editable);
drawParcellesAgricoles(map, data, editable);
// draw user polygon
if (initial) {

View file

@ -57,6 +57,19 @@ export function drawQuartiersPrioritaires(
);
}
export function drawParcellesAgricoles(
map,
{ parcellesAgricoles },
editable = false
) {
drawLayer(
map,
parcellesAgricoles,
editable ? RPG_POLYGON_STYLE : noEditStyle(RPG_POLYGON_STYLE),
'parcellesAgricoles'
);
}
export function drawUserSelection(map, { selection }, editable = false) {
let hasSelection = selection && selection.length > 0;
@ -170,6 +183,10 @@ const QP_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, {
fillColor: '#31708f'
});
const RPG_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, {
fillColor: '#31708f'
});
delegate('click', '.carte.edit', event => {
let element = event.target;
let isPath = element.matches('.leaflet-container g path');

View file

@ -1,23 +1,49 @@
class ApiGeo::API
TIMEOUT = 15
def self.regions
url = [API_GEO_URL, "regions"].join("/")
call(url)
call(url, { fields: :nom })
end
def self.departements
url = [API_GEO_URL, "departements"].join("/")
call(url)
call(url, { fields: :nom })
end
def self.pays
File.open('app/lib/api_geo/pays.json').read
parse(File.open('app/lib/api_geo/pays.json').read)
end
def self.search_rpg(geojson)
url = [API_GEO_SANDBOX_URL, "rpg", "parcelles", "search"].join("/")
call(url, geojson, :post)
end
private
def self.call(url)
RestClient.get(url, params: { fields: :nom })
rescue RestClient::ServiceUnavailable
def self.parse(body)
JSON.parse(body, symbolize_names: true)
end
def self.call(url, body, method = :get)
response = Typhoeus::Request.new(
url,
method: method,
params: method == :get ? body : nil,
body: method == :post ? body : nil,
timeout: TIMEOUT,
accept_encoding: 'gzip',
headers: {
'Accept' => 'application/json',
'Accept-Encoding' => 'gzip, deflate'
}.merge(method == :post ? { 'Content-Type' => 'application/json' } : {})
).run
if response.success?
parse(response.body)
else
nil
end
end
end

View file

@ -0,0 +1,24 @@
class ApiGeo::RPGAdapter
def initialize(coordinates)
@coordinates = GeojsonService.to_json_polygon_for_rpg(coordinates)
end
def data_source
@data_source ||= ApiGeo::API.search_rpg(@coordinates)
end
def results
data_source[:features].map do |feature|
feature[:properties]
.stringify_keys
.transform_keys(&:underscore)
.symbolize_keys
.slice(
:culture,
:code_culture,
:surface,
:bio
).merge({ geometry: feature[:geometry] })
end
end
end

View file

@ -15,6 +15,12 @@ class Champs::CarteChamp < Champ
end
end
def parcelles_agricoles
geo_areas.select do |area|
area.source == GeoArea.sources.fetch(:parcelle_agricole)
end
end
def cadastres?
type_de_champ&.cadastres && type_de_champ.cadastres != '0'
end
@ -23,6 +29,10 @@ class Champs::CarteChamp < Champ
type_de_champ&.quartiers_prioritaires && type_de_champ.quartiers_prioritaires != '0'
end
def parcelles_agricoles?
type_de_champ&.parcelles_agricoles && type_de_champ.parcelles_agricoles != '0'
end
def position
if dossier.present?
dossier.geo_position

View file

@ -1,5 +1,5 @@
class Champs::DepartementChamp < Champs::TextChamp
def self.departements
JSON.parse(ApiGeo::API.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger')
ApiGeo::API.departements.map { |liste| "#{liste[:code]} - #{liste[:nom]}" }.push('99 - Étranger')
end
end

View file

@ -1,5 +1,5 @@
class Champs::PaysChamp < Champs::TextChamp
def self.pays
JSON.parse(ApiGeo::API.pays).pluck("nom")
ApiGeo::API.pays.pluck(:nom)
end
end

View file

@ -1,5 +1,5 @@
class Champs::RegionChamp < Champs::TextChamp
def self.regions
JSON.parse(ApiGeo::API.regions).sort_by { |e| e['nom'] }.pluck("nom")
ApiGeo::API.regions.sort_by { |e| e[:nom] }.pluck(:nom)
end
end

View file

@ -13,14 +13,20 @@ class GeoArea < ApplicationRecord
:code_arr,
:code,
:nom,
:commune
:commune,
:culture,
:code_culture,
:surface,
:bio
]
enum source: {
quartier_prioritaire: 'quartier_prioritaire',
cadastre: 'cadastre'
cadastre: 'cadastre',
parcelle_agricole: 'parcelle_agricole'
}
scope :quartiers_prioritaires, -> { where(source: sources.fetch(:quartier_prioritaire)) }
scope :cadastres, -> { where(source: sources.fetch(:cadastre)) }
scope :parcelles_agricoles, -> { where(source: sources.fetch(:parcelle_agricole)) }
end

View file

@ -31,7 +31,7 @@ class TypeDeChamp < ApplicationRecord
belongs_to :procedure
store :options, accessors: [:cadastres, :quartiers_prioritaires]
store :options, accessors: [:cadastres, :quartiers_prioritaires, :parcelles_agricoles]
after_initialize :set_dynamic_type

View file

@ -1,16 +1,34 @@
class GeoAreaSerializer < ActiveModel::Serializer
attributes :geometry,
:source,
:surface_intersection,
:surface_parcelle,
:numero,
:feuille,
:section,
:code_dep,
:nom_com,
:code_com,
:code_arr,
:code,
:nom,
:commune
attributes :geometry, :source
attribute :surface_intersection, if: :include_cadastre?
attribute :surface_parcelle, if: :include_cadastre?
attribute :numero, if: :include_cadastre?
attribute :feuille, if: :include_cadastre?
attribute :section, if: :include_cadastre?
attribute :code_dep, if: :include_cadastre?
attribute :nom_com, if: :include_cadastre?
attribute :code_com, if: :include_cadastre?
attribute :code_arr, if: :include_cadastre?
attribute :code, if: :include_quartier_prioritaire?
attribute :nom, if: :include_quartier_prioritaire?
attribute :commune, if: :include_quartier_prioritaire?
attribute :culture, if: :include_parcelle_agricole?
attribute :code_culture, if: :include_parcelle_agricole?
attribute :surface, if: :include_parcelle_agricole?
attribute :bio, if: :include_parcelle_agricole?
def include_cadastre?
object.source == GeoArea.sources.fetch(:cadastre)
end
def include_quartier_prioritaire?
object.source == GeoArea.sources.fetch(:quartier_prioritaire)
end
def include_parcelle_agricole?
object.source == GeoArea.sources.fetch(:parcelle_agricole)
end
end

View file

@ -25,4 +25,15 @@ class GeojsonService
polygon.to_json
end
def self.to_json_polygon_for_rpg(coordinates)
polygon = {
polygonIntersects: {
type: "Polygon",
coordinates: [coordinates]
}
}
polygon.to_json
end
end

View file

@ -38,4 +38,12 @@ class ModuleApiCartoService
).results
end
end
def self.generate_rpg(coordinates)
coordinates.flat_map do |coordinate|
ApiGeo::RPGAdapter.new(
coordinate.map { |element| [element['lng'], element['lat']] }
).results
end
end
end

View file

@ -16,6 +16,7 @@ class TypesDeChampService
:piece_justificative_template,
:quartiers_prioritaires,
:cadastres,
:parcelles_agricoles,
drop_down_list_attributes: [:value, :id]
])

View file

@ -47,6 +47,10 @@
%label
= ff.check_box :cadastres
Cadastre
%br
%label
= ff.check_box :parcelles_agricoles
Parcelles Agricoles
- hide_mandatory = (ff.object.object.private? || type_champ == TypeDeChamp.type_champs.fetch(:explication))
.form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil }

View file

@ -25,3 +25,17 @@
%ul
- champ.cadastres.each do |pc|
%li Parcelle n° #{pc.numero} - Feuille #{pc.code_arr} #{pc.section} #{pc.feuille}
- if champ.parcelles_agricoles?
.areas-title Parcelles agricoles (RPG)
.areas
- if error.present?
.error Merci de dessiner une surface plus petite afin de récupérer les parcelles agricoles.
- elsif champ.value.blank?
Aucune zone tracée
- elsif champ.parcelles_agricoles.blank?
= t('errors.messages.parcelles_agricoles_empty', count: champ.zones.size)
- else
%ul
- champ.parcelles_agricoles.each do |pa|
%li Culture : #{pa.culture} - Surface : #{pa.surface} ha

View file

@ -0,0 +1 @@
Typhoeus::Config.user_agent = "demarches-simplifiees.fr"

View file

@ -3,6 +3,7 @@ API_ADRESSE_URL = "https://api-adresse.data.gouv.fr"
API_CARTO_URL = "https://apicarto.sgmap.fr"
API_ENTREPRISE_URL = "https://entreprise.api.gouv.fr/v2"
API_GEO_URL = "https://geo.api.gouv.fr"
API_GEO_SANDBOX_URL = "https://sandbox.geo.api.gouv.fr"
HELPSCOUT_API_URL = "https://api.helpscout.net/v2"
PIPEDRIVE_API_URL = "https://api.pipedrive.com/v1"

View file

@ -183,6 +183,9 @@ fr:
quartiers_prioritaires_empty:
one: "Aucun quartier prioritaire sur la zone séléctionnée"
other: "Aucun quartier prioritaire sur les zones séléctionnées"
parcelles_agricoles_empty:
one: "Aucune parcelle agricole sur la zone séléctionnée"
other: "Aucune parcelle agricole sur les zones séléctionnées"
date:
abbr_day_names:

View file

@ -36,7 +36,7 @@ describe Champs::CarteController, type: :controller do
context 'when coordinates are empty' do
let(:selection) { [] }
it { expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[]});") }
it { expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});") }
end
context 'when coordinates are informed' do

View file

@ -3,5 +3,11 @@ FactoryBot.define do
source { GeoArea.sources.fetch(:cadastre) }
numero { '42' }
feuille { 'A11' }
trait :quartier_prioritaire do
source { GeoArea.sources.fetch(:quartier_prioritaire) }
nom { 'XYZ' }
commune { 'Paris' }
end
end
end

View file

@ -7,21 +7,23 @@ http_interactions:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Accept:
- "*/*"
- application/json
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
Expect:
- ''
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
- nginx/1.10.3 (Ubuntu)
Date:
- Fri, 16 Dec 2016 09:25:41 GMT
- Tue, 23 Oct 2018 13:11:36 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
@ -30,13 +32,12 @@ http_interactions:
- keep-alive
Vary:
- Accept-Encoding
- Accept-Encoding
X-Powered-By:
- Express
Access-Control-Allow-Origin:
- "*"
Etag:
- W/"cc1-lXUcIlpPmDfvrGONl0WWsQ"
- W/"cc1-jlb3C7xpXUEaq56Wojrp9rAkoH8"
Strict-Transport-Security:
- max-age=15552000
Content-Encoding:
@ -44,27 +45,7 @@ http_interactions:
body:
encoding: ASCII-8BIT
string: !binary |-
H4sIAAAAAAAAA22Wy27bMBBFfyXwJpsKqF96dOfYrZsibow4MFAUXTARGxOQ
xZYSjbpF/yfZ5w/0YyVlpDq0sxTmajg8vJzh1z+9Um9773oTVfbe9O51Lt3H
237v75suUpUSsQFjRaGkQXAYBH/IKspl9FHYWkZLo3eyvGeqEdStqIomhfsJ
CccnCRfCqFptA1VMlcmbx/sN10nCsCzL4O80CKvm8YE/Z4zaO4T6b4OQQ/ef
YD8guJN7o8G3T4YX2rpqHSgb3WyaZ7LuE+dUFDuRa8Dpk99UlLUoUAHJTTfC
yLJmgUT2Eo5e2CIN2U03POw+uU21Mc3jb65AcC5cSb/Flc275IPJsQGiVgjF
BRTT5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JlcyIsImNvZGUiOiI3OSJ9LHsibm9tIjoiU29tbWUiLCJjb2RlIjoiODAifSx7Im5vbSI6IlRhcm4iLCJjb2RlIjoiODEifSx7Im5vbSI6IlRhcm4tZXQtR2Fyb25uZSIsImNvZGUiOiI4MiJ9LHsibm9tIjoiVmFyIiwiY29kZSI6IjgzIn0seyJub20iOiJWYXVjbHVzZSIsImNvZGUiOiI4NCJ9LHsibm9tIjoiVmVuZMOpZSIsImNvZGUiOiI4NSJ9LHsibm9tIjoiVmllbm5lIiwiY29kZSI6Ijg2In0seyJub20iOiJIYXV0ZS1WaWVubmUiLCJjb2RlIjoiODcifSx7Im5vbSI6IlZvc2dlcyIsImNvZGUiOiI4OCJ9LHsibm9tIjoiWW9ubmUiLCJjb2RlIjoiODkifSx7Im5vbSI6IlRlcnJpdG9pcmUgZGUgQmVsZm9ydCIsImNvZGUiOiI5MCJ9LHsibm9tIjoiRXNzb25uZSIsImNvZGUiOiI5MSJ9LHsibm9tIjoiSGF1dHMtZGUtU2VpbmUiLCJjb2RlIjoiOTIifSx7Im5vbSI6IlNlaW5lLVNhaW50LURlbmlzIiwiY29kZSI6IjkzIn0seyJub20iOiJWYWwtZGUtTWFybmUiLCJjb2RlIjoiOTQifSx7Im5vbSI6IlZhbC1kJ09pc2UiLCJjb2RlIjoiOTUifSx7Im5vbSI6Ikd1YWRlbG91cGUiLCJjb2RlIjoiOTcxIn0seyJub20iOiJNYXJ0aW5pcXVlIiwiY29kZSI6Ijk3MiJ9LHsibm9tIjoiR3V5YW5lIiwiY29kZSI6Ijk3MyJ9LHsibm9tIjoiTGEgUsOpdW5pb24iLCJjb2RlIjoiOTc0In0seyJub20iOiJNYXlvdHRlIiwiY29kZSI6Ijk3NiJ9XQ==
http_version:
recorded_at: Fri, 16 Dec 2016 09:25:37 GMT
recorded_with: VCR 3.0.3
recorded_at: Tue, 23 Oct 2018 13:11:36 GMT
recorded_with: VCR 4.0.0

View file

@ -7,21 +7,23 @@ http_interactions:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Accept:
- "*/*"
- application/json
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
Expect:
- ''
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
- nginx/1.10.3 (Ubuntu)
Date:
- Fri, 16 Dec 2016 09:24:28 GMT
- Tue, 23 Oct 2018 13:11:36 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
@ -30,13 +32,12 @@ http_interactions:
- keep-alive
Vary:
- Accept-Encoding
- Accept-Encoding
X-Powered-By:
- Express
Access-Control-Allow-Origin:
- "*"
Etag:
- W/"2dd-2SAFdhiM3SIQ2017gqYxbw"
- W/"28d-5OgIzgwL+0K2UaO0foKduqMMBrA"
Strict-Transport-Security:
- max-age=15552000
Content-Encoding:
@ -44,14 +45,7 @@ http_interactions:
body:
encoding: ASCII-8BIT
string: !binary |-
H4sIAAAAAAAAA11Ry2rDMBD8FeNLLxE0rybpzTE0F6eYHHopPSyWSASyNllJ
Abf0F/ofvucP/GO1aIvXPQm0M7MzO68fqcU6fUx3AaQyGM4qnaQVStX/3U/T
z8kfYA/ktdWXwAEzBtiFBiwfztmwgOTQtcFqtEx/MdJv0HvOf2DT7ssoIZV4
IrAVA025xVxZT0q8gEmkSgrUxJAzvmyLgY54tL+CJyVyrH3XDt5mK7b9GakG
KzWXW4/nUpTgosMcDGgnSl0BjRhzfqzMOKh68AnqM0QfGUll+7dAItD8jgtu
vITGxXAG/udbcvktKR9lhzxL3kZ2CdrHLaLQNQanrShRewzREPVXVG5grpaj
Hu0xKImVOPQ8p41BK/ZaalE21LW2a0dUXmEWropi1MOpu8XE5syx61FMwqvq
i/4Biby7eZXIu+w90GBswyPlSI7F3fRqb99L+pyA3QIAAA==
W3sibm9tIjoiR3VhZGVsb3VwZSIsImNvZGUiOiIwMSJ9LHsibm9tIjoiTWFydGluaXF1ZSIsImNvZGUiOiIwMiJ9LHsibm9tIjoiR3V5YW5lIiwiY29kZSI6IjAzIn0seyJub20iOiJMYSBSw6l1bmlvbiIsImNvZGUiOiIwNCJ9LHsibm9tIjoiTWF5b3R0ZSIsImNvZGUiOiIwNiJ9LHsibm9tIjoiw45sZS1kZS1GcmFuY2UiLCJjb2RlIjoiMTEifSx7Im5vbSI6IkNlbnRyZS1WYWwgZGUgTG9pcmUiLCJjb2RlIjoiMjQifSx7Im5vbSI6IkJvdXJnb2duZS1GcmFuY2hlLUNvbXTDqSIsImNvZGUiOiIyNyJ9LHsibm9tIjoiTm9ybWFuZGllIiwiY29kZSI6IjI4In0seyJub20iOiJIYXV0cy1kZS1GcmFuY2UiLCJjb2RlIjoiMzIifSx7Im5vbSI6IkdyYW5kIEVzdCIsImNvZGUiOiI0NCJ9LHsibm9tIjoiUGF5cyBkZSBsYSBMb2lyZSIsImNvZGUiOiI1MiJ9LHsibm9tIjoiQnJldGFnbmUiLCJjb2RlIjoiNTMifSx7Im5vbSI6Ik5vdXZlbGxlLUFxdWl0YWluZSIsImNvZGUiOiI3NSJ9LHsibm9tIjoiT2NjaXRhbmllIiwiY29kZSI6Ijc2In0seyJub20iOiJBdXZlcmduZS1SaMO0bmUtQWxwZXMiLCJjb2RlIjoiODQifSx7Im5vbSI6IlByb3ZlbmNlLUFscGVzLUPDtHRlIGQnQXp1ciIsImNvZGUiOiI5MyJ9LHsibm9tIjoiQ29yc2UiLCJjb2RlIjoiOTQifV0=
http_version:
recorded_at: Fri, 16 Dec 2016 09:24:25 GMT
recorded_with: VCR 3.0.3
recorded_at: Tue, 23 Oct 2018 13:11:36 GMT
recorded_with: VCR 4.0.0

File diff suppressed because one or more lines are too long

View file

@ -4,18 +4,72 @@ describe ApiGeo::API do
describe '.regions', vcr: { cassette_name: 'api_geo_regions' } do
subject { described_class.regions }
it { expect(subject.code).to eq 200 }
it { expect(subject.size).to eq 18 }
end
describe '.departements', vcr: { cassette_name: 'api_geo_departements' } do
subject { described_class.departements }
it { expect(subject.code).to eq 200 }
it { expect(subject.size).to eq 101 }
end
describe '.pays' do
subject { described_class.pays }
let(:pays) {
JSON.parse(File.open('app/lib/api_geo/pays.json').read, symbolize_names: true)
}
it { is_expected.to eq File.open('app/lib/api_geo/pays.json').read }
it { is_expected.to eq pays }
end
describe '.search_rpg', vcr: { cassette_name: 'api_geo_search_rpg' } do
let(:coordinates) do
[
[
2.3945903778076176,
46.53312237252731
],
[
2.394933700561524,
46.532590956418076
],
[
2.3948478698730473,
46.53170525134736
],
[
2.393732070922852,
46.530760483351195
],
[
2.3909854888916016,
46.5309376286023
],
[
2.391414642333985,
46.531232869403546
],
[
2.3913288116455083,
46.53253190986272
],
[
2.39278793334961,
46.53329951007484
],
[
2.3945903778076176,
46.53312237252731
]
]
end
let(:geo_json) {
GeojsonService.to_json_polygon_for_rpg(coordinates)
}
subject { described_class.search_rpg(geo_json) }
it { expect(subject[:features].size).to eq 3 }
end
end

View file

@ -0,0 +1,61 @@
require 'spec_helper'
describe ApiGeo::RPGAdapter do
subject { described_class.new(coordinates).results }
let(:coordinates) do
[
[
2.3945903778076176,
46.53312237252731
],
[
2.394933700561524,
46.532590956418076
],
[
2.3948478698730473,
46.53170525134736
],
[
2.393732070922852,
46.530760483351195
],
[
2.3909854888916016,
46.5309376286023
],
[
2.391414642333985,
46.531232869403546
],
[
2.3913288116455083,
46.53253190986272
],
[
2.39278793334961,
46.53329951007484
],
[
2.3945903778076176,
46.53312237252731
]
]
end
context 'coordinates are filled', vcr: { cassette_name: 'api_geo_search_rpg' } do
describe 'Attribut filter' do
it { expect(subject.size).to eq(3) }
it do
expect(subject.first.keys).to eq([
:culture,
:code_culture,
:surface,
:bio,
:geometry
])
end
end
end
end

View file

@ -6,13 +6,29 @@ describe Champs::CarteChampSerializer 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