From c04627431c38bc65e1e28cd06e28d6519db85983 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Tue, 12 Jan 2016 15:11:42 +0100 Subject: [PATCH] add module api carto in api procedure --- app/decorators/procedure_decorator.rb | 3 +++ app/serializers/module_api_carto_serializer.rb | 7 +++++++ app/serializers/procedure_serializer.rb | 11 ++++++++--- .../api/v1/procedures_controller_spec.rb | 14 +++++++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 app/serializers/module_api_carto_serializer.rb diff --git a/app/decorators/procedure_decorator.rb b/app/decorators/procedure_decorator.rb index d6a8183cd..445753b64 100644 --- a/app/decorators/procedure_decorator.rb +++ b/app/decorators/procedure_decorator.rb @@ -9,4 +9,7 @@ class ProcedureDecorator < Draper::Decorator return 'logo-tps.png' if logo.blank? logo end + def geographic_information + module_api_carto + end end diff --git a/app/serializers/module_api_carto_serializer.rb b/app/serializers/module_api_carto_serializer.rb new file mode 100644 index 000000000..6fbdcc7b1 --- /dev/null +++ b/app/serializers/module_api_carto_serializer.rb @@ -0,0 +1,7 @@ +class ModuleApiCartoSerializer < ActiveModel::Serializer + attributes :use_api_carto, + :quartiers_prioritaires, + :cadastre + + +end \ No newline at end of file diff --git a/app/serializers/procedure_serializer.rb b/app/serializers/procedure_serializer.rb index 6e517a789..e21025a37 100644 --- a/app/serializers/procedure_serializer.rb +++ b/app/serializers/procedure_serializer.rb @@ -1,11 +1,16 @@ class ProcedureSerializer < ActiveModel::Serializer + attribute :libelle, key: :label + attribute :lien_demarche, key: :link + attributes :id, - :libelle, :description, :organisation, :direction, - :lien_demarche, - :archived + :archived, + :geographic_information + + + has_one :geographic_information, serializer: ModuleApiCartoSerializer has_many :types_de_champ, serializer: TypeDeChampSerializer has_many :types_de_piece_justificative, serializer: TypeDePieceJustificativeSerializer end diff --git a/spec/controllers/api/v1/procedures_controller_spec.rb b/spec/controllers/api/v1/procedures_controller_spec.rb index 075d32f76..f3a080c6c 100644 --- a/spec/controllers/api/v1/procedures_controller_spec.rb +++ b/spec/controllers/api/v1/procedures_controller_spec.rb @@ -18,16 +18,17 @@ describe API::V1::ProceduresController do subject { get :show, id: procedure, token: admin.api_token } it { expect(subject.status).to eq(200) } describe 'body' do - let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) } + 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(:response) { get :show, id: procedure.id, token: admin.api_token } subject { JSON.parse(response.body, symbolize_names: true)[:procedure] } it { expect(subject[:id]).to eq(procedure.id) } - it { expect(subject[:libelle]).to eq(procedure.libelle) } + it { expect(subject[:label]).to eq(procedure.libelle) } it { expect(subject[:description]).to eq(procedure.description) } it { expect(subject[:organisation]).to eq(procedure.organisation) } it { expect(subject[:direction]).to eq(procedure.direction) } - it { expect(subject[:lien_demarche]).to eq(procedure.lien_demarche) } + it { expect(subject[:link]).to eq(procedure.lien_demarche) } it { expect(subject[:archived]).to eq(procedure.archived) } it { is_expected.to have_key(:types_de_champ) } it { expect(subject[:types_de_champ]).to be_an(Array) } @@ -50,6 +51,13 @@ describe API::V1::ProceduresController 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