demarches-normaliennes/spec/lib/active_storage/downloadable_file_spec.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

describe ActiveStorage::DownloadableFile do
2021-03-08 11:35:20 +01:00
let(:dossier) { create(:dossier, :en_construction, :with_pdf_export) }
subject(:list) { ActiveStorage::DownloadableFile.create_list_from_dossier(dossier) }
describe 'create_list_from_dossier' do
context 'when no piece_justificative is present' do
2021-03-08 11:35:20 +01:00
it { expect(list.length).to eq 1 }
it { expect(list.first[0].record_type).to eq "Dossier" }
end
context 'when there is a piece_justificative' do
before do
dossier.champs << create(:champ_piece_justificative, :with_piece_justificative_file, dossier: dossier)
end
2021-03-08 11:35:20 +01:00
it { expect(list.length).to eq 2 }
end
context 'when there is a private piece_justificative' do
before do
dossier.champs_private << create(:champ_piece_justificative, :with_piece_justificative_file, private: true, dossier: dossier)
end
2021-03-08 11:35:20 +01:00
it { expect(list.length).to eq 2 }
end
context 'when there is a repetition bloc' do
before do
dossier.champs << create(:champ_repetition_with_piece_jointe, dossier: dossier)
end
it 'should have 4 piece_justificatives' do
2021-03-08 11:35:20 +01:00
expect(list.size).to eq 5
end
end
2019-11-20 15:54:53 +01:00
context 'when there is a message with no attachment' do
before do
dossier.commentaires << create(:commentaire, dossier: dossier)
end
2019-11-20 15:54:53 +01:00
2021-03-08 11:35:20 +01:00
it { expect(list.length).to eq 1 }
2019-11-20 15:54:53 +01:00
end
context 'when there is a message with an attachment' do
before do
dossier.commentaires << create(:commentaire, :with_file, dossier: dossier)
end
2019-11-20 15:54:53 +01:00
2021-03-08 11:35:20 +01:00
it { expect(list.length).to eq 2 }
2019-11-20 15:54:53 +01:00
end
end
end