2017-06-29 15:31:29 +02:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe NewGestionnaire::DossiersController, type: :controller do
|
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
2017-07-11 15:45:20 +02:00
|
|
|
|
let(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :replied, procedure: procedure) }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
|
|
|
|
describe 'attestation' do
|
2017-07-06 16:33:36 +02:00
|
|
|
|
before { sign_in(gestionnaire) }
|
|
|
|
|
|
2017-06-29 15:31:29 +02:00
|
|
|
|
context 'when a dossier has an attestation' do
|
|
|
|
|
let(:fake_pdf) { double(read: 'pdf content') }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
let!(:dossier) { create(:dossier, :replied, attestation: Attestation.new, procedure: procedure) }
|
|
|
|
|
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) }
|
|
|
|
|
let!(:dossier) { create(:dossier, :replied, attestation: Attestation.new, procedure: procedure) }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
|
|
|
|
it 'returns the attestation pdf' do
|
|
|
|
|
allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf)
|
|
|
|
|
|
|
|
|
|
expect(controller).to receive(:send_data)
|
|
|
|
|
.with('pdf content', filename: 'attestation.pdf', type: 'application/pdf') do
|
|
|
|
|
controller.render nothing: true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
get :attestation, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-07-11 15:45:20 +02:00
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
context "when gestionnaire is signed in" do
|
|
|
|
|
before { sign_in(gestionnaire) }
|
2017-07-11 15:45:20 +02:00
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
describe 'follow' do
|
2017-07-17 15:14:19 +02:00
|
|
|
|
before do
|
|
|
|
|
expect_any_instance_of(Dossier).to receive(:next_step!).with('gestionnaire', 'follow')
|
|
|
|
|
patch :follow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
|
|
|
|
it { expect(gestionnaire.followed_dossiers).to match([dossier]) }
|
2017-07-17 12:28:09 +02:00
|
|
|
|
it { expect(flash.notice).to eq('Dossier suivi') }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
describe 'unfollow' do
|
|
|
|
|
before do
|
|
|
|
|
gestionnaire.followed_dossiers << dossier
|
|
|
|
|
patch :unfollow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
gestionnaire.reload
|
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
it { expect(gestionnaire.followed_dossiers).to match([]) }
|
2017-07-17 12:28:09 +02:00
|
|
|
|
it { expect(flash.notice).to eq("Vous ne suivez plus le dossier nº #{dossier.id}") }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
describe 'archive' do
|
|
|
|
|
before do
|
|
|
|
|
patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(dossier.archived).to be true }
|
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'unarchive' do
|
|
|
|
|
before do
|
|
|
|
|
dossier.update_attributes(archived: true)
|
|
|
|
|
patch :unarchive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(dossier.archived).to be false }
|
|
|
|
|
it { expect(response).to redirect_to(procedures_url) }
|
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
describe "#show" do
|
|
|
|
|
let(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) }
|
|
|
|
|
let(:dossier){ create(:dossier, :replied, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
subject { get :show, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
|
|
|
|
|
|
|
|
|
|
context "when gestionnaire is not logged in" do
|
|
|
|
|
before { subject }
|
|
|
|
|
it { expect(response).to redirect_to(new_user_session_path) }
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-06 16:33:36 +02:00
|
|
|
|
context "when gestionnaire is logged in" do
|
|
|
|
|
before { sign_in(gestionnaire) }
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
subject
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when gestionnaire is not affected on procedure" do
|
|
|
|
|
let(:dossier){ create(:dossier, :replied) }
|
|
|
|
|
it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
|
|
|
|
|
describe "commentaire" do
|
|
|
|
|
let(:saved_commentaire) { dossier.commentaires.first }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
sign_in(gestionnaire)
|
|
|
|
|
|
|
|
|
|
post :create_commentaire, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
commentaire: { body: 'body' }
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(saved_commentaire.body).to eq('body') }
|
|
|
|
|
it { expect(saved_commentaire.email).to eq(gestionnaire.email) }
|
|
|
|
|
it { expect(saved_commentaire.dossier).to eq(dossier) }
|
|
|
|
|
it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) }
|
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|