Add individual infos to flat table export serializer

This commit is contained in:
Mathieu Magnin 2017-04-13 15:05:55 +02:00
parent f5e8631b71
commit 320d5da40f
5 changed files with 66 additions and 17 deletions

View file

@ -245,7 +245,7 @@ class Dossier < ActiveRecord::Base
end
def data_with_champs
serialized_dossier = DossierProcedureSerializer.new(self)
serialized_dossier = DossierTableExportSerializer.new(self)
data = serialized_dossier.attributes.values
data += self.champs.order('type_de_champ_id ASC').map(&:value)
data += self.export_entreprise_data.values
@ -253,7 +253,7 @@ class Dossier < ActiveRecord::Base
end
def export_headers
serialized_dossier = DossierProcedureSerializer.new(self)
serialized_dossier = DossierTableExportSerializer.new(self)
headers = serialized_dossier.attributes.keys
headers += self.procedure.types_de_champ.order('id ASC').map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
headers += self.export_entreprise_data.keys

View file

@ -1,13 +0,0 @@
class DossierProcedureSerializer < ActiveModel::Serializer
attributes :id,
:created_at,
:updated_at,
:archived,
:mandataire_social,
:state,
:initiated_at,
:received_at,
:processed_at
attribute :followers_gestionnaires_emails, key: :emails_accompagnateurs
end

View file

@ -0,0 +1,34 @@
class DossierTableExportSerializer < ActiveModel::Serializer
attributes :id,
:created_at,
:updated_at,
:archived,
:mandataire_social,
:state,
:initiated_at,
:received_at,
:processed_at
attribute :followers_gestionnaires_emails, key: :emails_accompagnateurs
attributes :individual_gender,
:individual_prenom,
:individual_nom,
:individual_birthdate
def individual_prenom
object.individual.try(:prenom)
end
def individual_nom
object.individual.try(:nom)
end
def individual_birthdate
object.individual.try(:birthdate)
end
def individual_gender
object.individual.try(:gender)
end
end

View file

@ -1,5 +1,6 @@
FactoryGirl.define do
factory :individual do
gender 'M.'
nom 'Julien'
prenom 'Xavier'
birthdate '20/01/1991'

View file

@ -576,6 +576,10 @@ describe Dossier do
it { expect(subject[:entreprise_date_creation]).to eq('Thu, 28 Jan 2016 10:16:29 UTC +00:0') }
it { expect(subject[:entreprise_nom]).to be_nil }
it { expect(subject[:entreprise_prenom]).to be_nil }
it { expect(subject[:individual_gender]).to be_nil }
it { expect(subject[:individual_prenom]).to be_nil }
it { expect(subject[:individual_nom]).to be_nil }
it { expect(subject[:individual_birthdate]).to be_nil }
context 'when dossier does not have enterprise' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
@ -598,7 +602,11 @@ describe Dossier do
subject { dossier.export_headers }
it { expect(subject).to include(:description) }
it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
it { expect(subject).to include(:individual_gender) }
it { expect(subject).to include(:individual_nom) }
it { expect(subject).to include(:individual_prenom) }
it { expect(subject).to include(:individual_birthdate) }
it { expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
end
describe '#data_with_champs' do
@ -614,7 +622,22 @@ describe Dossier do
it { expect(subject[7]).to eq(date2) }
it { expect(subject[8]).to eq(date3) }
it { expect(subject[9]).to eq(dossier.followers_gestionnaires_emails) }
it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
it { expect(subject[10]).to be_nil }
it { expect(subject[11]).to be_nil }
it { expect(subject[12]).to be_nil }
it { expect(subject[13]).to be_nil }
it { expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
context 'dossier for individual' do
let(:dossier_with_individual) { create(:dossier, :for_individual, user: user, procedure: procedure) }
subject { dossier_with_individual.data_with_champs }
it { expect(subject[10]).to eq(dossier_with_individual.individual.gender) }
it { expect(subject[11]).to eq(dossier_with_individual.individual.prenom) }
it { expect(subject[12]).to eq(dossier_with_individual.individual.nom) }
it { expect(subject[13]).to eq(dossier_with_individual.individual.birthdate) }
end
end
describe "#full_data_string" do
@ -631,6 +654,10 @@ describe Dossier do
dossier.processed_at,
gestionnaire.email,
nil,
nil,
nil,
nil,
nil,
"44011762001530",
"true",
"4950Z",