2015-09-22 15:00:59 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Backoffice::DossiersController, type: :controller do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, :with_user) }
|
2015-09-22 15:00:59 +02:00
|
|
|
let(:dossier_id) { dossier.id }
|
|
|
|
let(:bad_dossier_id) { Dossier.count + 10 }
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
context "l'utilisateur est connecté" do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :show, id: dossier_id
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "le numéro de dossier n'existe pas" do
|
|
|
|
get :show, id: bad_dossier_id
|
2015-09-23 16:56:30 +02:00
|
|
|
expect(response).to redirect_to('/backoffice')
|
2015-09-22 15:00:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "L'utilisateur n'est pas connecté mais le numéro de dossier est correct" do
|
|
|
|
subject { get :show, id: dossier_id }
|
|
|
|
it { is_expected.to redirect_to('/gestionnaires/sign_in') }
|
|
|
|
end
|
|
|
|
end
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
describe 'POST #valid' do
|
2015-09-24 16:51:14 +02:00
|
|
|
context 'le gestionnaire valide un dossier' do
|
|
|
|
before do
|
2015-11-02 15:31:15 +01:00
|
|
|
dossier.initiated!
|
2015-09-24 16:51:14 +02:00
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
it 'dossier change is state for validated' do
|
|
|
|
post :valid, dossier_id: dossier_id
|
2015-09-24 16:51:14 +02:00
|
|
|
|
|
|
|
dossier.reload
|
2015-11-02 11:45:52 +01:00
|
|
|
expect(dossier.state).to eq('validated')
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
describe 'POST #close' do
|
2015-10-09 12:05:07 +02:00
|
|
|
context 'le gestionnaire taite un dossier' do
|
|
|
|
before do
|
2015-11-02 15:46:43 +01:00
|
|
|
dossier.submitted!
|
2015-10-09 12:05:07 +02:00
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
it 'dossier change is state for closed' do
|
|
|
|
post :close, dossier_id: dossier_id
|
2015-10-09 12:05:07 +02:00
|
|
|
|
|
|
|
dossier.reload
|
2015-11-02 15:00:28 +01:00
|
|
|
expect(dossier.state).to eq('closed')
|
2015-10-09 12:05:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-22 15:00:59 +02:00
|
|
|
end
|