Add Carte champs support to the API
This commit is contained in:
parent
17418edb54
commit
7cf225d443
4 changed files with 52 additions and 0 deletions
11
app/serializers/champs/carte_champ_serializer.rb
Normal file
11
app/serializers/champs/carte_champ_serializer.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class Champs::CarteChampSerializer < ChampSerializer
|
||||||
|
has_many :geo_areas
|
||||||
|
|
||||||
|
def value
|
||||||
|
if object.value.present?
|
||||||
|
JSON.parse(object.value)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
app/serializers/geo_area_serializer.rb
Normal file
16
app/serializers/geo_area_serializer.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
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
|
||||||
|
end
|
7
spec/factories/geo_area.rb
Normal file
7
spec/factories/geo_area.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :geo_area do
|
||||||
|
source { GeoArea.sources.fetch(:cadastre) }
|
||||||
|
numero { '42' }
|
||||||
|
feuille { 'A11' }
|
||||||
|
end
|
||||||
|
end
|
18
spec/serializers/champs/carte_champ_serializer_spec.rb
Normal file
18
spec/serializers/champs/carte_champ_serializer_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
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]) }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(subject[:geo_areas].first).to include(
|
||||||
|
source: GeoArea.sources.fetch(:cadastre),
|
||||||
|
numero: '42',
|
||||||
|
feuille: 'A11'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue