2019-07-01 15:55:37 +02:00
|
|
|
describe ActiveStorage::DownloadableFile do
|
2019-07-25 15:57:00 +02:00
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
subject(:list) { ActiveStorage::DownloadableFile.create_list_from_dossier(dossier) }
|
2019-07-01 15:55:37 +02:00
|
|
|
|
|
|
|
describe 'create_list_from_dossier' do
|
|
|
|
context 'when no piece_justificative is present' do
|
|
|
|
it { expect(list).to match([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a piece_justificative' do
|
|
|
|
before do
|
2019-07-25 15:57:00 +02:00
|
|
|
dossier.champs << create(:champ, :piece_justificative, :with_piece_justificative_file)
|
2019-07-01 15:55:37 +02:00
|
|
|
end
|
|
|
|
|
2020-06-24 12:50:43 +02:00
|
|
|
it { expect(list.length).to eq 1 }
|
2019-07-01 15:55:37 +02:00
|
|
|
end
|
2019-09-03 15:17:19 +02:00
|
|
|
|
2020-06-24 15:21:51 +02:00
|
|
|
context 'when there is a private piece_justificative' do
|
|
|
|
before do
|
|
|
|
dossier.champs_private << create(:champ, :piece_justificative, :with_piece_justificative_file, private: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(list.length).to eq 1 }
|
|
|
|
end
|
|
|
|
|
2019-09-03 15:17:19 +02:00
|
|
|
context 'when there is a repetition bloc' do
|
|
|
|
let(:champ) { build(:champ_repetition_with_piece_jointe) }
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, champs: [champ]) }
|
|
|
|
|
|
|
|
it 'should have 4 piece_justificatives' do
|
2020-06-24 12:50:43 +02:00
|
|
|
expect(list.size).to eq 4
|
2019-09-03 15:17:19 +02:00
|
|
|
end
|
|
|
|
end
|
2019-11-20 15:54:53 +01:00
|
|
|
|
|
|
|
context 'when there is a message with no attachment' do
|
|
|
|
let(:commentaire) { create(:commentaire) }
|
|
|
|
let(:dossier) { commentaire.dossier }
|
|
|
|
|
2020-06-24 12:50:43 +02:00
|
|
|
it { expect(list.length).to eq 0 }
|
2019-11-20 15:54:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a message with an attachment' do
|
|
|
|
let(:commentaire) { create(:commentaire, :with_file) }
|
|
|
|
let(:dossier) { commentaire.dossier }
|
|
|
|
|
2020-06-24 12:50:43 +02:00
|
|
|
it { expect(list.length).to eq 1 }
|
2019-11-20 15:54:53 +01:00
|
|
|
end
|
2019-07-01 15:55:37 +02:00
|
|
|
end
|
|
|
|
end
|