add empty to piece_jointe

This commit is contained in:
Tanguy PATTE 2015-08-18 16:51:57 +02:00
parent f49477dee7
commit bda3a410c4
2 changed files with 15 additions and 8 deletions

View file

@ -5,13 +5,7 @@ class PieceJointe < ActiveRecord::Base
mount_uploader :content, PieceJointeUploader
# TODO: remove this function, find another way
def self.get_array_id_pj_valid_for_dossier(dossier_id)
@array_id_pj_valides = []
where(dossier_id: dossier_id).each do |pj_valide|
@array_id_pj_valides << pj_valide.type_piece_jointe_id
end
@array_id_pj_valides
def empty?
content.blank?
end
end

View file

@ -27,4 +27,17 @@ describe PieceJointe do
end
end
end
describe '#empty?' do
let(:piece_jointe) { create(:piece_jointe, content: content) }
subject { piece_jointe.empty? }
context 'when content is nil' do
let(:content) { nil }
it { is_expected.to be_truthy }
end
context 'when content exist' do
let(:content) { File.open('./spec/support/files/piece_jointe_388.pdf') }
it { is_expected.to be_falsey }
end
end
end