GeoArea on API expose fields per source type
This commit is contained in:
parent
5a8a4b393f
commit
fd490efb59
3 changed files with 61 additions and 21 deletions
|
@ -1,16 +1,34 @@
|
||||||
class GeoAreaSerializer < ActiveModel::Serializer
|
class GeoAreaSerializer < ActiveModel::Serializer
|
||||||
attributes :geometry,
|
attributes :geometry, :source
|
||||||
:source,
|
|
||||||
:surface_intersection,
|
attribute :surface_intersection, if: :include_cadastre?
|
||||||
:surface_parcelle,
|
attribute :surface_parcelle, if: :include_cadastre?
|
||||||
:numero,
|
attribute :numero, if: :include_cadastre?
|
||||||
:feuille,
|
attribute :feuille, if: :include_cadastre?
|
||||||
:section,
|
attribute :section, if: :include_cadastre?
|
||||||
:code_dep,
|
attribute :code_dep, if: :include_cadastre?
|
||||||
:nom_com,
|
attribute :nom_com, if: :include_cadastre?
|
||||||
:code_com,
|
attribute :code_com, if: :include_cadastre?
|
||||||
:code_arr,
|
attribute :code_arr, if: :include_cadastre?
|
||||||
:code,
|
|
||||||
:nom,
|
attribute :code, if: :include_quartier_prioritaire?
|
||||||
:commune
|
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
|
end
|
||||||
|
|
|
@ -3,5 +3,11 @@ FactoryBot.define do
|
||||||
source { GeoArea.sources.fetch(:cadastre) }
|
source { GeoArea.sources.fetch(:cadastre) }
|
||||||
numero { '42' }
|
numero { '42' }
|
||||||
feuille { 'A11' }
|
feuille { 'A11' }
|
||||||
|
|
||||||
|
trait :quartier_prioritaire do
|
||||||
|
source { GeoArea.sources.fetch(:quartier_prioritaire) }
|
||||||
|
nom { 'XYZ' }
|
||||||
|
commune { 'Paris' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,13 +6,29 @@ describe Champs::CarteChampSerializer do
|
||||||
let(:geo_area) { create(:geo_area) }
|
let(:geo_area) { create(:geo_area) }
|
||||||
let(:champ) { create(:type_de_champ_carte).champ.create(geo_areas: [geo_area]) }
|
let(:champ) { create(:type_de_champ_carte).champ.create(geo_areas: [geo_area]) }
|
||||||
|
|
||||||
it {
|
context 'and geo_area is cadastre' do
|
||||||
expect(subject[:geo_areas].first).to include(
|
it {
|
||||||
source: GeoArea.sources.fetch(:cadastre),
|
expect(subject[:geo_areas].first).to include(
|
||||||
numero: '42',
|
source: GeoArea.sources.fetch(:cadastre),
|
||||||
feuille: 'A11'
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue