Fix bug download CSV
This commit is contained in:
parent
8409b660cf
commit
177295f6e4
2 changed files with 15 additions and 3 deletions
|
@ -286,9 +286,14 @@ class Dossier < ActiveRecord::Base
|
|||
|
||||
def as_csv(options={})
|
||||
dossier_attr = DossierSerializer.new(self).attributes
|
||||
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)
|
||||
|
||||
unless entreprise.nil?
|
||||
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 = dossier_attr.merge(etablissement_attr).merge(entreprise_attr)
|
||||
end
|
||||
|
||||
dossier_attr
|
||||
end
|
||||
|
||||
def reset!
|
||||
|
|
|
@ -689,6 +689,13 @@ 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 }
|
||||
|
||||
context 'when dossier does not have enterprise' do
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
subject { dossier.as_csv }
|
||||
|
||||
it { expect(subject[:archived]).to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reset!' do
|
||||
|
|
Loading…
Reference in a new issue