feat(Users::CommencerController#commencer): ensure to redirect to replaced_by_procedure when it exisits
This commit is contained in:
parent
80edf23446
commit
7f1018c5b0
2 changed files with 16 additions and 2 deletions
|
@ -5,8 +5,8 @@ module Users
|
|||
def commencer
|
||||
@procedure = retrieve_procedure
|
||||
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
|
||||
@revision = @procedure.published_revision
|
||||
|
||||
@revision = @procedure.published_revision
|
||||
render 'commencer/show'
|
||||
end
|
||||
|
||||
|
@ -69,7 +69,10 @@ module Users
|
|||
def procedure_not_found
|
||||
procedure = Procedure.find_by(path: params[:path])
|
||||
|
||||
if procedure&.close?
|
||||
if procedure&.replaced_by_procedure
|
||||
redirect_to commencer_path(path: procedure.replaced_by_procedure.path)
|
||||
return
|
||||
elsif procedure&.close?
|
||||
flash.alert = procedure.service.presence ?
|
||||
t('errors.messages.procedure_archived.with_service_and_phone_email', service_name: procedure.service.nom, service_phone_number: procedure.service.telephone, service_email: procedure.service.email) :
|
||||
t('errors.messages.procedure_archived.with_organisation_only', organisation_name: procedure.organisation)
|
||||
|
|
|
@ -51,6 +51,17 @@ describe Users::CommencerController, type: :controller do
|
|||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when procedure has a replaced_by_procedure' do
|
||||
let(:path) { published_procedure.path }
|
||||
|
||||
it 'redirects to new procedure' do
|
||||
replaced_by_procedure = create(:procedure, :published)
|
||||
published_procedure.update!(replaced_by_procedure_id: replaced_by_procedure.id)
|
||||
published_procedure.close!
|
||||
expect(subject).to redirect_to(commencer_path(path: replaced_by_procedure.path))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#commencer_test' do
|
||||
|
|
Loading…
Reference in a new issue