Refactor link attribute generation on ProcedureSerializer
This commit is contained in:
parent
7cf225d443
commit
4ebc0b7f4c
4 changed files with 25 additions and 4 deletions
|
@ -276,7 +276,7 @@ class Admin::ProceduresController < AdminController
|
|||
if @procedure&.locked?
|
||||
params.require(:procedure).permit(*editable_params)
|
||||
else
|
||||
params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :lien_demarche, :for_individual, :individual_with_siret, :ask_birthday, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
|
||||
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
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class ProcedureSerializer < ActiveModel::Serializer
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
attribute :libelle, key: :label
|
||||
attribute :lien_demarche, key: :link
|
||||
|
||||
attributes :id,
|
||||
:description,
|
||||
|
@ -8,10 +9,21 @@ class ProcedureSerializer < ActiveModel::Serializer
|
|||
:direction,
|
||||
:archived_at,
|
||||
:geographic_information,
|
||||
:total_dossier
|
||||
:total_dossier,
|
||||
:link
|
||||
|
||||
has_one :geographic_information, serializer: ModuleApiCartoSerializer
|
||||
has_many :types_de_champ, serializer: TypeDeChampSerializer
|
||||
has_many :types_de_champ_private, serializer: TypeDeChampSerializer
|
||||
has_many :types_de_piece_justificative, serializer: TypeDePieceJustificativeSerializer
|
||||
|
||||
def link
|
||||
if object.path.present?
|
||||
if object.brouillon_avec_lien?
|
||||
commencer_test_url(procedure_path: object.path)
|
||||
else
|
||||
commencer_url(procedure_path: object.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,7 +36,6 @@ describe API::V1::ProceduresController, type: :controller do
|
|||
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[:link]).to eq(procedure.lien_demarche) }
|
||||
it { expect(subject[:archived_at]).to eq(procedure.archived_at) }
|
||||
it { expect(subject[:total_dossier]).to eq(procedure.total_dossier) }
|
||||
it { is_expected.to have_key(:types_de_champ) }
|
||||
|
|
10
spec/serializers/procedure_serializer_spec.rb
Normal file
10
spec/serializers/procedure_serializer_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
describe ProcedureSerializer do
|
||||
describe '#attributes' do
|
||||
subject { ProcedureSerializer.new(procedure).serializable_hash }
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
|
||||
it {
|
||||
is_expected.to include(link: "http://localhost:3000/commencer/#{procedure.path}")
|
||||
}
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue