Merge pull request #91 from sgmap/fix_csv_export_with_no_dossiers
Fix csv export with no dossiers
This commit is contained in:
commit
3c3d0fcfbd
2 changed files with 8 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue