2015-09-23 12:04:57 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Users::DossiersController, type: :controller do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:user) { create(:user) }
|
2015-11-27 13:56:54 +01:00
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
let(:procedure) { create(:procedure, :published) }
|
2015-12-03 12:00:22 +01:00
|
|
|
let(:procedure_id) { procedure.id }
|
2016-06-20 13:57:57 +02:00
|
|
|
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
2015-09-23 19:20:03 +02:00
|
|
|
let(:dossier_id) { dossier.id }
|
2015-12-03 12:00:22 +01:00
|
|
|
|
|
|
|
describe 'GET #new' do
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { get :new, params: { procedure_id: procedure_id } }
|
2015-12-03 12:00:22 +01:00
|
|
|
|
|
|
|
context 'when params procedure_id is present' do
|
|
|
|
context 'when procedure_id is valid' do
|
|
|
|
context 'when user is logged in' do
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
sign_in user
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
it { is_expected.to have_http_status(302) }
|
2018-10-04 09:43:19 +02:00
|
|
|
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
|
2016-06-20 13:57:57 +02:00
|
|
|
|
|
|
|
it { expect { subject }.to change(Dossier, :count).by 1 }
|
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
context 'when procedure is archived' do
|
2018-08-14 11:47:47 +02:00
|
|
|
let(:procedure) { create(:procedure, :archived) }
|
2015-12-03 12:00:22 +01:00
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
it { is_expected.to redirect_to dossiers_path }
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when user is not logged' do
|
|
|
|
it { is_expected.to have_http_status(302) }
|
2016-06-20 13:57:57 +02:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure_id is not valid' do
|
|
|
|
let(:procedure_id) { 0 }
|
|
|
|
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
sign_in user
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
it { is_expected.to redirect_to dossiers_path }
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2016-06-09 17:49:38 +02:00
|
|
|
|
|
|
|
context 'when procedure is not published' do
|
2018-08-14 11:47:47 +02:00
|
|
|
let(:procedure) { create(:procedure) }
|
2016-06-09 17:49:38 +02:00
|
|
|
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
sign_in user
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
it { is_expected.to redirect_to dossiers_path }
|
2018-08-14 11:47:47 +02:00
|
|
|
|
|
|
|
context 'and brouillon param is passed' do
|
|
|
|
subject { get :new, params: { procedure_id: procedure_id, brouillon: true } }
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(302) }
|
2018-10-04 09:43:19 +02:00
|
|
|
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
|
2018-08-14 11:47:47 +02:00
|
|
|
end
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-29 17:35:34 +02:00
|
|
|
describe 'GET #commencer' do
|
2018-05-23 15:36:50 +02:00
|
|
|
subject { get :commencer, params: { procedure_path: path } }
|
|
|
|
let(:path) { procedure.path }
|
2016-06-29 17:35:34 +02:00
|
|
|
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
|
2016-11-07 17:08:33 +01:00
|
|
|
|
2018-08-14 11:47:47 +02:00
|
|
|
context 'when procedure path does not exist' do
|
|
|
|
let(:path) { 'hello' }
|
2016-11-07 17:08:33 +01:00
|
|
|
|
2018-08-14 11:47:47 +02:00
|
|
|
it { expect(subject).to redirect_to(root_path) }
|
2016-11-07 17:08:33 +01:00
|
|
|
end
|
2018-08-14 11:47:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #commencer_test' do
|
|
|
|
before do
|
|
|
|
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { get :commencer_test, params: { procedure_path: path } }
|
|
|
|
let(:procedure) { create(:procedure, :with_path) }
|
|
|
|
let(:path) { procedure.path }
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true) }
|
2017-07-06 14:40:06 +02:00
|
|
|
|
2018-08-14 11:47:47 +02:00
|
|
|
context 'when procedure path does not exist' do
|
2018-05-23 15:36:50 +02:00
|
|
|
let(:path) { 'hello' }
|
|
|
|
|
|
|
|
it { expect(subject).to redirect_to(root_path) }
|
|
|
|
end
|
2016-06-29 17:35:34 +02:00
|
|
|
end
|
2016-10-25 17:39:53 +02:00
|
|
|
end
|