Merge pull request #2400 from tchak/fix-test-dossier-page
Fix test dossier page
This commit is contained in:
commit
0f5ae8eea6
2 changed files with 38 additions and 14 deletions
|
@ -5,7 +5,7 @@ class Users::DossiersController < UsersController
|
||||||
SESSION_USER_RETURN_LOCATION = 'user_return_to'
|
SESSION_USER_RETURN_LOCATION = 'user_return_to'
|
||||||
|
|
||||||
before_action :store_user_location!, only: :new
|
before_action :store_user_location!, only: :new
|
||||||
before_action :authenticate_user!, except: :commencer
|
before_action :authenticate_user!, except: [:commencer, :commencer_test]
|
||||||
before_action :check_siret, only: :siret_informations
|
before_action :check_siret, only: :siret_informations
|
||||||
|
|
||||||
before_action only: [:show] do
|
before_action only: [:show] do
|
||||||
|
@ -14,12 +14,12 @@ class Users::DossiersController < UsersController
|
||||||
|
|
||||||
def commencer_test
|
def commencer_test
|
||||||
procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
|
procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
|
||||||
procedure = procedure_path&.test_procedure
|
procedure = procedure_path&.procedure
|
||||||
|
|
||||||
if procedure.present?
|
if procedure&.brouillon_avec_lien?
|
||||||
redirect_to new_users_dossier_path(procedure_id: procedure.id)
|
redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true)
|
||||||
else
|
else
|
||||||
flash.alert = "Procédure inconnue"
|
flash.alert = "La procédure est inconnue."
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ class Users::DossiersController < UsersController
|
||||||
redirect_to new_users_dossier_path(procedure_id: procedure.id)
|
redirect_to new_users_dossier_path(procedure_id: procedure.id)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
flash.alert = "Procédure inconnue"
|
flash.alert = "La procédure est inconnue, ou la création de nouveaux dossiers pour cette procédure est terminée."
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,9 +45,13 @@ class Users::DossiersController < UsersController
|
||||||
def new
|
def new
|
||||||
erase_user_location!
|
erase_user_location!
|
||||||
|
|
||||||
procedure = Procedure.publiees.find(params[:procedure_id])
|
if params[:brouillon]
|
||||||
|
procedure = Procedure.brouillon.find(params[:procedure_id])
|
||||||
|
else
|
||||||
|
procedure = Procedure.publiees.find(params[:procedure_id])
|
||||||
|
end
|
||||||
|
|
||||||
dossier = Dossier.create(procedure: procedure, user: current_user, state: 'brouillon')
|
dossier = Dossier.create!(procedure: procedure, user: current_user, state: 'brouillon')
|
||||||
siret = params[:siret] || current_user.siret
|
siret = params[:siret] || current_user.siret
|
||||||
|
|
||||||
update_current_user_siret! siret if siret.present?
|
update_current_user_siret! siret if siret.present?
|
||||||
|
|
|
@ -118,7 +118,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when procedure is archived' do
|
context 'when procedure is archived' do
|
||||||
let(:procedure) { create(:procedure, archived_at: Time.now) }
|
let(:procedure) { create(:procedure, :archived) }
|
||||||
|
|
||||||
it { is_expected.to redirect_to dossiers_path }
|
it { is_expected.to redirect_to dossiers_path }
|
||||||
end
|
end
|
||||||
|
@ -140,13 +140,20 @@ describe Users::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when procedure is not published' do
|
context 'when procedure is not published' do
|
||||||
let(:procedure) { create(:procedure, published_at: nil) }
|
let(:procedure) { create(:procedure) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in user
|
sign_in user
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to redirect_to dossiers_path }
|
it { is_expected.to redirect_to dossiers_path }
|
||||||
|
|
||||||
|
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 users_dossier_path(id: Dossier.last) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -158,13 +165,26 @@ describe Users::DossiersController, type: :controller do
|
||||||
it { expect(subject.status).to eq 302 }
|
it { expect(subject.status).to eq 302 }
|
||||||
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
|
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
|
||||||
|
|
||||||
context 'when procedure is archived' do
|
context 'when procedure path does not exist' do
|
||||||
let(:procedure) { create(:procedure, :archived) }
|
let(:path) { 'hello' }
|
||||||
|
|
||||||
it { expect(subject.status).to eq 200 }
|
it { expect(subject).to redirect_to(root_path) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #commencer_test' do
|
||||||
|
before do
|
||||||
|
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when procedure path dose not exist' do
|
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) }
|
||||||
|
|
||||||
|
context 'when procedure path does not exist' do
|
||||||
let(:path) { 'hello' }
|
let(:path) { 'hello' }
|
||||||
|
|
||||||
it { expect(subject).to redirect_to(root_path) }
|
it { expect(subject).to redirect_to(root_path) }
|
||||||
|
|
Loading…
Reference in a new issue