Merge pull request #2400 from tchak/fix-test-dossier-page

Fix test dossier page
This commit is contained in:
Paul Chavard 2018-08-14 14:55:09 +00:00 committed by GitHub
commit 0f5ae8eea6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 14 deletions

View file

@ -5,7 +5,7 @@ class Users::DossiersController < UsersController
SESSION_USER_RETURN_LOCATION = 'user_return_to'
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 only: [:show] do
@ -14,12 +14,12 @@ class Users::DossiersController < UsersController
def commencer_test
procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
procedure = procedure_path&.test_procedure
procedure = procedure_path&.procedure
if procedure.present?
redirect_to new_users_dossier_path(procedure_id: procedure.id)
if procedure&.brouillon_avec_lien?
redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true)
else
flash.alert = "Procédure inconnue"
flash.alert = "La procédure est inconnue."
redirect_to root_path
end
end
@ -37,7 +37,7 @@ class Users::DossiersController < UsersController
redirect_to new_users_dossier_path(procedure_id: procedure.id)
end
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
end
end
@ -45,9 +45,13 @@ class Users::DossiersController < UsersController
def new
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
update_current_user_siret! siret if siret.present?

View file

@ -118,7 +118,7 @@ describe Users::DossiersController, type: :controller do
end
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 }
end
@ -140,13 +140,20 @@ describe Users::DossiersController, type: :controller do
end
context 'when procedure is not published' do
let(:procedure) { create(:procedure, published_at: nil) }
let(:procedure) { create(:procedure) }
before do
sign_in user
end
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
@ -158,13 +165,26 @@ describe Users::DossiersController, type: :controller do
it { expect(subject.status).to eq 302 }
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
context 'when procedure is archived' do
let(:procedure) { create(:procedure, :archived) }
context 'when procedure path does not exist' do
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
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' }
it { expect(subject).to redirect_to(root_path) }