[#1995] Add gender and birthdate fields to API
This commit is contained in:
parent
a872acfb97
commit
2f769ca933
2 changed files with 17 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
class IndividualSerializer < ActiveModel::Serializer
|
||||
attribute :gender, key: :civilite
|
||||
attributes :nom, :prenom
|
||||
attribute :birthdate, key: :date_naissance, if: :include_birthdate?
|
||||
|
||||
def include_birthdate?
|
||||
object&.dossier&.procedure&.ask_birthday
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
describe IndividualSerializer do
|
||||
describe '#attributes' do
|
||||
let(:individual){ Individual.create(nom: 'nom', prenom: 'prenom') }
|
||||
let(:procedure) { build(:procedure) }
|
||||
let(:dossier) { build(:dossier, procedure: procedure) }
|
||||
let(:individual) { build(:individual, gender: 'M.', nom: 'nom', prenom: 'prenom', birthdate: Date.new(2001, 8, 27), dossier: dossier) }
|
||||
|
||||
subject { IndividualSerializer.new(individual).serializable_hash }
|
||||
|
||||
it { is_expected.to include(civilite: 'M.') }
|
||||
it { is_expected.to include(nom: 'nom') }
|
||||
it { is_expected.to include(prenom: 'prenom') }
|
||||
it { is_expected.not_to have_key(:date_naissance) }
|
||||
|
||||
context 'when the procedure asks for a birthdate' do
|
||||
let(:procedure) { build(:procedure, ask_birthday: true) }
|
||||
|
||||
it { is_expected.to include(date_naissance: Date.new(2001, 8, 27)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue