From 64fdc7a2af319bcf1cf7a7cbc0503c5c43f3a2ba Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 5 Apr 2017 15:07:00 +0200 Subject: [PATCH 1/4] Remove a Dossier#convert_specific_array_values_to_string useless test --- spec/models/dossier_spec.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index ddc469b50..328e21d28 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -512,14 +512,6 @@ 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) } From df878b9ef442c99c6ab02bab0b98d59d12c22099 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 5 Apr 2017 15:10:58 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Change=20Dossier#convert=5Fspecific=5Farray?= =?UTF-8?q?=5Fvalues=5Fto=5Fstring=E2=80=99s=20signature=20and=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - It is always called with the data_with_champs argument - Changing the signature requires a change of name in this case --- app/models/dossier.rb | 4 ++-- app/models/procedure.rb | 2 +- spec/models/dossier_spec.rb | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 5cf14b5ea..f0401ccc0 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -216,9 +216,9 @@ class Dossier < ActiveRecord::Base return hash end - def convert_specific_array_values_to_string(array_to_convert) + def full_data_strings_array array = [] - array_to_convert.each do |value| + data_with_champs.each do |value| value = value.to_s if !value.kind_of?(Time) && !value.nil? array << value end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 0ffbc4714..0a1b46f92 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -135,7 +135,7 @@ class Procedure < ActiveRecord::Base headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : [] data = exportable_dossiers.map do |dossier| - dossier.convert_specific_array_values_to_string(dossier.data_with_champs) + dossier.full_data_strings_array end { diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 328e21d28..63092998b 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -616,6 +616,52 @@ describe Dossier do 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) } end + + describe "#full_data_string" do + let(:expected_string) { + [ + dossier.id.to_s, + dossier.created_at, + dossier.updated_at, + "false", + "false", + "draft", + dossier.initiated_at, + dossier.received_at, + dossier.processed_at, + gestionnaire.email, + nil, + "44011762001530", + "true", + "4950Z", + "Transports par conduites", + "GRTGAZ IMMEUBLE BORA 6 RUE RAOUL NORDLING 92270 BOIS COLOMBES", + "6", + "RUE", + "RAOUL NORDLING", + "IMMEUBLE BORA", + "92270", + "BOIS COLOMBES", + "92009", + "440117620", + "537100000", + "FR27440117620", + "SA à conseil d'administration (s.a.i.)", + "5599", + "GRTGAZ", + "GRTGAZ", + "44011762001530", + "51", + dossier.entreprise.date_creation, + nil, + nil + ] + } + + subject { dossier } + + it { expect(dossier.full_data_strings_array).to eq(expected_string)} + end end describe '#Dossier.to_csv' do From ae5b4f62493a069b99916d394f7bc9fcfb5253a6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 5 Apr 2017 15:11:44 +0200 Subject: [PATCH 3/4] Refactor Dossier#full_data_strings_array --- app/models/dossier.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index f0401ccc0..fda340de9 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -217,12 +217,9 @@ class Dossier < ActiveRecord::Base end def full_data_strings_array - array = [] - data_with_champs.each do |value| - value = value.to_s if !value.kind_of?(Time) && !value.nil? - array << value + data_with_champs.map do |value| + value.nil? || value.kind_of?(Time) ? value : value.to_s end - return array end def export_entreprise_data From 1db37894c206c859c3b417499c185d9c37a31c3b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 11 Apr 2017 11:38:48 +0200 Subject: [PATCH 4/4] Factorize some code in Dossier#serialize_value_for_export --- app/models/dossier.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index fda340de9..bdadb8c00 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -210,7 +210,7 @@ class Dossier < ActiveRecord::Base 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? + value = serialize_value_for_export(value) hash.store(key, value) end return hash @@ -218,7 +218,7 @@ class Dossier < ActiveRecord::Base def full_data_strings_array data_with_champs.map do |value| - value.nil? || value.kind_of?(Time) ? value : value.to_s + serialize_value_for_export(value) end end @@ -303,4 +303,8 @@ class Dossier < ActiveRecord::Base end end + def serialize_value_for_export(value) + value.nil? || value.kind_of?(Time) ? value : value.to_s + end + end