Remove carriage returns in address in CSV format only

This commit is contained in:
Guillaume Lazzara 2016-05-24 15:58:21 +02:00
parent 63cf35a748
commit f62c9ebec9
4 changed files with 7 additions and 5 deletions

View file

@ -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

View file

@ -0,0 +1,5 @@
class EtablissementCsvSerializer < EtablissementSerializer
def adresse
object.adresse.chomp.gsub("\r\n", ' ').gsub("\r", '')
end
end

View file

@ -12,7 +12,4 @@ class EtablissementSerializer < ActiveModel::Serializer
:localite,
:code_insee_localite
def adresse
object.adresse.chomp.gsub("\r\n", ' ')
end
end

View file

@ -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') }