diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb index 0b7404fe3..a64d21d16 100644 --- a/app/models/cerfa.rb +++ b/app/models/cerfa.rb @@ -2,4 +2,8 @@ class Cerfa < ActiveRecord::Base belongs_to :dossier mount_uploader :content, CerfaUploader + + def empty? + content.blank? + end end \ No newline at end of file diff --git a/spec/factories/cerfa.rb b/spec/factories/cerfa.rb new file mode 100644 index 000000000..221352c54 --- /dev/null +++ b/spec/factories/cerfa.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :cerfa do + + end +end \ No newline at end of file diff --git a/spec/models/cerfa_spec.rb b/spec/models/cerfa_spec.rb index ca4d8d45c..07b1c3d65 100644 --- a/spec/models/cerfa_spec.rb +++ b/spec/models/cerfa_spec.rb @@ -9,4 +9,15 @@ describe Cerfa do it { is_expected.to belong_to(:dossier) } end + describe 'empty?' do + subject { create(:cerfa, content: content)} + context 'when content exist' do + let(:content) { File.open('./spec/support/files/piece_jointe_388.pdf') } + it { expect(subject).not_to be_empty } + end + context 'when content is nil' do + let(:content) { nil } + it { expect(subject).to be_empty } + end + end end \ No newline at end of file