New feature : User, Guest and Gestionnaire can be upload a document with theirs comments

This commit is contained in:
Xavier J 2016-04-20 16:51:57 +02:00
parent fb2eeddf97
commit b15c2bbb2b
19 changed files with 214 additions and 59 deletions

View file

@ -6,6 +6,10 @@ describe Users::CommentairesController, type: :controller do
let(:email_commentaire) { 'test@test.com' }
let(:texte_commentaire) { 'Commentaire de test' }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
end
describe '#POST create' do
context 'création correct d\'un commentaire' do
subject do
@ -26,6 +30,53 @@ describe Users::CommentairesController, type: :controller do
end
end
context 'when document is upload whith a commentaire' do
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
subject do
sign_in dossier.user
post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}
end
it 'create a new piece justificative' do
expect { subject }.to change(PieceJustificative, :count).by(1)
end
it 'clamav check the pj' do
expect(ClamavService).to receive(:safe_file?)
subject
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }
before do
subject
end
it 'not have a type de pj' do
expect(pj.type_de_piece_justificative).to be_nil
end
it 'content not be nil' do
expect(pj.content).not_to be_nil
end
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
before do
subject
end
it 'have a piece justificative reference' do
expect(commentaire.piece_justificative).not_to be_nil
expect(commentaire.piece_justificative).to eq PieceJustificative.last
end
end
end
describe 'change dossier state after post a comment' do
context 'when user is connected' do
context 'when dossier is at state replied' do
@ -39,7 +90,7 @@ describe Users::CommentairesController, type: :controller do
subject { dossier.state }
it {is_expected.to eq('updated')}
it { is_expected.to eq('updated') }
end
end
end