demarches-normaliennes/spec/controllers/users/dossiers_controller_spec.rb

100 lines
2.9 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Users::DossiersController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) }
let(:procedure_id) { procedure.id }
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
2015-09-23 19:20:03 +02:00
let(:dossier_id) { dossier.id }
describe 'GET #new' do
subject { get :new, params: { procedure_id: procedure_id } }
context 'when params procedure_id is present' do
context 'when procedure_id is valid' do
context 'when user is logged in' do
before do
sign_in user
end
it { is_expected.to have_http_status(302) }
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
it { expect { subject }.to change(Dossier, :count).by 1 }
context 'when procedure is archived' do
2018-08-14 11:47:47 +02:00
let(:procedure) { create(:procedure, :archived) }
it { is_expected.to redirect_to dossiers_path }
end
end
context 'when user is not logged' do
it { is_expected.to have_http_status(302) }
it { is_expected.to redirect_to new_user_session_path }
end
end
context 'when procedure_id is not valid' do
let(:procedure_id) { 0 }
before do
sign_in user
end
it { is_expected.to redirect_to dossiers_path }
end
context 'when procedure is not published' do
2018-08-14 11:47:47 +02:00
let(:procedure) { create(:procedure) }
before do
sign_in user
end
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) }
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
2018-08-14 11:47:47 +02:00
end
end
2015-09-23 19:20:03 +02:00
end
end
describe 'GET #commencer' do
2018-05-23 15:36:50 +02:00
subject { get :commencer, params: { procedure_path: 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) }
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) }
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
end
end