gestionnaire: move commentaire creation into a service
This commit is contained in:
parent
d31cc04b23
commit
750e1e0c83
4 changed files with 79 additions and 34 deletions
48
spec/services/commentaire_service_spec.rb
Normal file
48
spec/services/commentaire_service_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe CommentaireService do
|
||||
describe '.create' do
|
||||
let(:dossier) { create :dossier }
|
||||
let(:sender) { dossier.user }
|
||||
let(:body) { 'Contenu du message.' }
|
||||
let(:file) { nil }
|
||||
let(:scan_result) { true }
|
||||
|
||||
subject(:commentaire) { CommentaireService.create(sender, dossier, { body: body, file: file }) }
|
||||
|
||||
before do
|
||||
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||
end
|
||||
|
||||
it 'creates a new valid commentaire' do
|
||||
expect(commentaire.email).to eq sender.email
|
||||
expect(commentaire.dossier).to eq dossier
|
||||
expect(commentaire.body).to eq '<p>Contenu du message.</p>'
|
||||
expect(commentaire.file).to be_blank
|
||||
expect(commentaire).to be_valid
|
||||
end
|
||||
|
||||
context 'when the body is empty' do
|
||||
let(:body) { nil }
|
||||
|
||||
it 'creates an invalid comment' do
|
||||
expect(commentaire.body).to be nil
|
||||
expect(commentaire.valid?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it has a file' do
|
||||
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||
|
||||
it 'saves the attached file' do
|
||||
expect(commentaire.file).to be_present
|
||||
expect(commentaire).to be_valid
|
||||
end
|
||||
|
||||
context 'and a virus' do
|
||||
let(:scan_result) { false }
|
||||
it { expect(commentaire).not_to be_valid }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue