2016-02-22 15:22:06 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Users::Dossiers::CommentairesController, type: :controller do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
let(:texte_commentaire) { 'Commentaire de test' }
|
|
|
|
|
|
|
|
describe '#POST create' do
|
2017-01-30 15:17:45 +01:00
|
|
|
subject {
|
2018-01-16 13:34:24 +01:00
|
|
|
post :create, params: { dossier_id: dossier.id, texte_commentaire: texte_commentaire }
|
2017-01-30 15:17:45 +01:00
|
|
|
dossier.reload
|
|
|
|
}
|
|
|
|
|
2016-02-22 15:22:06 +01:00
|
|
|
context 'when invite is connected' do
|
|
|
|
let!(:invite) { create(:invite, :with_user, dossier: dossier) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in invite.user
|
2017-01-30 15:17:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
|
|
|
is_expected.to redirect_to users_dossiers_invite_path(invite.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should notify user' do
|
|
|
|
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
|
2018-05-25 18:05:28 +02:00
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
2017-01-30 15:17:45 +01:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connected' do
|
|
|
|
before do
|
|
|
|
sign_in dossier.user
|
|
|
|
end
|
2016-02-22 15:22:06 +01:00
|
|
|
|
2017-01-30 15:17:45 +01:00
|
|
|
it 'do not send a mail to notify user' do
|
|
|
|
expect(NotificationMailer).to_not receive(:new_answer)
|
|
|
|
subject
|
2016-02-22 15:22:06 +01:00
|
|
|
end
|
2017-01-30 15:17:45 +01:00
|
|
|
end
|
|
|
|
end
|
2016-02-22 15:22:06 +01:00
|
|
|
end
|