2015-08-17 11:41:57 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-09-21 17:59:03 +02:00
|
|
|
describe PieceJustificative do
|
2015-08-17 11:41:57 +02:00
|
|
|
describe 'database columns' do
|
|
|
|
it { is_expected.to have_db_column(:content) }
|
2016-05-18 11:43:32 +02:00
|
|
|
it { is_expected.to have_db_column(:original_filename) }
|
|
|
|
it { is_expected.to have_db_column(:content_secure_token) }
|
2016-03-14 17:30:22 +01:00
|
|
|
it { is_expected.to have_db_column(:created_at) }
|
2015-08-17 11:41:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:dossier) }
|
2015-09-21 17:59:03 +02:00
|
|
|
it { is_expected.to belong_to(:type_de_piece_justificative) }
|
2016-03-17 17:33:38 +01:00
|
|
|
it { is_expected.to belong_to(:user) }
|
2016-04-20 16:51:57 +02:00
|
|
|
it { is_expected.to have_one(:commentaire) }
|
2016-03-17 17:33:38 +01:00
|
|
|
|
2015-08-17 11:41:57 +02:00
|
|
|
end
|
2015-08-18 16:44:16 +02:00
|
|
|
|
2016-04-20 16:51:57 +02:00
|
|
|
describe 'validations' do
|
|
|
|
context 'content' do
|
|
|
|
it { is_expected.not_to allow_value(nil).for(:content) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:content) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-18 17:00:09 +02:00
|
|
|
describe 'delegation' do
|
2015-09-21 17:59:03 +02:00
|
|
|
it { is_expected.to delegate_method(:libelle).to(:type_de_piece_justificative) }
|
|
|
|
it { is_expected.to delegate_method(:api_entreprise).to(:type_de_piece_justificative) }
|
2015-08-18 16:44:16 +02:00
|
|
|
end
|
2015-08-18 16:51:57 +02:00
|
|
|
|
2016-05-13 16:08:51 +02:00
|
|
|
describe '#empty?', vcr: { cassette_name: 'model_piece_justificative' } do
|
2015-09-21 17:59:03 +02:00
|
|
|
let(:piece_justificative) { create(:piece_justificative, content: content) }
|
|
|
|
subject { piece_justificative.empty? }
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2015-08-18 16:51:57 +02:00
|
|
|
context 'when content exist' do
|
2015-09-21 17:59:03 +02:00
|
|
|
let(:content) { File.open('./spec/support/files/piece_justificative_388.pdf') }
|
2015-08-18 16:51:57 +02:00
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|