From f62c9ebec94ff8dfb57c145cadde59ee281e3dae Mon Sep 17 00:00:00 2001 From: Guillaume Lazzara Date: Tue, 24 May 2016 15:58:21 +0200 Subject: [PATCH] Remove carriage returns in address in CSV format only --- app/models/dossier.rb | 2 +- app/serializers/etablissement_csv_serializer.rb | 5 +++++ app/serializers/etablissement_serializer.rb | 3 --- spec/models/dossier_spec.rb | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 app/serializers/etablissement_csv_serializer.rb diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 6bb913e25..900b71fcb 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -190,7 +190,7 @@ class Dossier < ActiveRecord::Base def as_csv(options={}) dossier_attr = DossierSerializer.new(self).attributes - etablissement_attr = EtablissementSerializer.new(self.etablissement).attributes.map {|k, v| ["etablissement.#{k}", v] }.to_h + etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map {|k, v| ["etablissement.#{k}", v] }.to_h entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map {|k, v| ["entreprise.#{k}", v] }.to_h dossier_attr.merge(etablissement_attr).merge(entreprise_attr) end diff --git a/app/serializers/etablissement_csv_serializer.rb b/app/serializers/etablissement_csv_serializer.rb new file mode 100644 index 000000000..ec33919bd --- /dev/null +++ b/app/serializers/etablissement_csv_serializer.rb @@ -0,0 +1,5 @@ +class EtablissementCsvSerializer < EtablissementSerializer + def adresse + object.adresse.chomp.gsub("\r\n", ' ').gsub("\r", '') + end +end \ No newline at end of file diff --git a/app/serializers/etablissement_serializer.rb b/app/serializers/etablissement_serializer.rb index 8df8b1603..b0bcd0c19 100644 --- a/app/serializers/etablissement_serializer.rb +++ b/app/serializers/etablissement_serializer.rb @@ -12,7 +12,4 @@ class EtablissementSerializer < ActiveModel::Serializer :localite, :code_insee_localite - def adresse - object.adresse.chomp.gsub("\r\n", ' ') - end end \ No newline at end of file diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index e6abe45be..5c59b0a39 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -538,7 +538,7 @@ describe Dossier do it { expect(subject['etablissement.siege_social']).to be_truthy } it { expect(subject['etablissement.naf']).to eq('4950Z') } it { expect(subject['etablissement.libelle_naf']).to eq('Transports par conduites') } - it { expect(subject['etablissement.adresse']).to eq("GRTGAZ\r IMMEUBLE BORA\r 6 RUE RAOUL NORDLING\r 92270 BOIS COLOMBES\r") } + it { expect(subject['etablissement.adresse']).to eq("GRTGAZ IMMEUBLE BORA 6 RUE RAOUL NORDLING 92270 BOIS COLOMBES") } it { expect(subject['etablissement.numero_voie']).to eq('6') } it { expect(subject['etablissement.type_voie']).to eq('RUE') } it { expect(subject['etablissement.nom_voie']).to eq('RAOUL NORDLING') }