diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 86fb24fc1..700c7da20 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -294,7 +294,7 @@ class Dossier < ActiveRecord::Base procedure.cerfa_flag? && cerfa.size != 0 end - def convert_specific_values_to_string(hash_to_convert) + def convert_specific_hash_values_to_string(hash_to_convert) hash = {} hash_to_convert.each do |key, value| value = value.to_s if !value.kind_of?(Time) && !value.nil? @@ -303,6 +303,15 @@ class Dossier < ActiveRecord::Base return hash end + def convert_specific_array_values_to_string(array_to_convert) + array = [] + array_to_convert.each do |value| + value = value.to_s if !value.kind_of?(Time) && !value.nil? + array << value + end + return array + end + def export_entreprise_data unless entreprise.nil? etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h @@ -311,12 +320,12 @@ class Dossier < ActiveRecord::Base etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h end - return convert_specific_values_to_string(etablissement_attr).merge(convert_specific_values_to_string(entreprise_attr)) + return convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr)) end def export_default_columns dossier_attr = DossierSerializer.new(self).attributes - dossier_attr = convert_specific_values_to_string(dossier_attr) + dossier_attr = convert_specific_hash_values_to_string(dossier_attr) dossier_attr = dossier_attr.merge(self.export_entreprise_data) return dossier_attr end @@ -345,7 +354,7 @@ class Dossier < ActiveRecord::Base data = [] headers = dossiers.first.export_headers dossiers.each do |dossier| - data << dossier.data_with_champs + data << dossier.convert_specific_array_values_to_string(data_with_champs) end if ["csv"].include?(format) return SpreadsheetArchitect.to_csv(data: data, headers: headers) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 8c53b2dba..0bd7f73a8 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -659,12 +659,12 @@ describe Dossier do end end - describe '#convert_specific_values_to_string(hash_to_convert)' do + describe '#convert_specific_hash_values_to_string(hash_to_convert)' do let(:procedure) { create(:procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier_serialized_attributes) { DossierSerializer.new(dossier).attributes } - subject { dossier.convert_specific_values_to_string(dossier_serialized_attributes) } + subject { dossier.convert_specific_hash_values_to_string(dossier_serialized_attributes) } it { expect(dossier_serialized_attributes[:id]).to be_an(Integer) } it { expect(dossier_serialized_attributes[:created_at]).to be_a(Time) } @@ -681,6 +681,14 @@ describe Dossier do it { expect(subject[:state]).to be_a(String) } end + describe '#convert_specific_array_values_to_string(array_to_convert)' do + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + let(:dossier_data_with_champs) { dossier.data_with_champs } + + subject { dossier.convert_specific_hash_values_to_string(dossier_data_with_champs) } + end + describe '#export_entreprise_data' do let(:procedure) { create(:procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } @@ -768,6 +776,12 @@ describe Dossier do let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } subject { dossier.data_with_champs } + it do + binding.pry + end + it { expect(subject[0]).to be_a_kind_of(Integer)} + it { expect(subject[1]).to be_a_kind_of(Time)} + it { expect(subject[2]).to be_a_kind_of(Time)} it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) } end