Fix csv export with no dossiers

This commit is contained in:
Mathieu Magnin 2017-04-12 17:59:12 +02:00
parent 33d033d680
commit 080c7c3d04
2 changed files with 8 additions and 7 deletions

View file

@ -134,9 +134,7 @@ class Procedure < ActiveRecord::Base
exportable_dossiers = dossiers.downloadable
headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : []
data = exportable_dossiers.map do |dossier|
dossier.full_data_strings_array
end
data = exportable_dossiers.any? ? exportable_dossiers.map { |d| d.full_data_strings_array } : [[]]
{
headers: headers,

View file

@ -261,11 +261,15 @@ describe Procedure do
let(:procedure) { create :procedure }
subject { procedure.generate_export }
context 'when there are no dossiers' do
it { expect(subject[:data]).to eq([]) }
shared_examples "export is empty" do
it { expect(subject[:data]).to eq([[]]) }
it { expect(subject[:headers]).to eq([]) }
end
context 'when there are no dossiers' do
it_behaves_like "export is empty"
end
context 'when there are some dossiers' do
let!(:dossier){ create(:dossier, procedure: procedure, state: 'initiated') }
let!(:dossier2){ create(:dossier, procedure: procedure, state: 'closed') }
@ -277,8 +281,7 @@ describe Procedure do
context 'when there is a draft dossier' do
let!(:dossier_not_exportable){ create(:dossier, procedure: procedure, state: 'draft') }
it { expect(subject[:data]).to eq([]) }
it { expect(subject[:headers]).to eq([]) }
it_behaves_like "export is empty"
end
end
end