admin can't reactivate procedure if auto archive on past

This commit is contained in:
Christophe Robillard 2023-10-03 11:11:17 +02:00
parent df621cdeae
commit ba56c79325
2 changed files with 34 additions and 3 deletions

View file

@ -264,9 +264,14 @@ module Administrateurs
draft_revision: :types_de_champ
).find(params[:procedure_id])
@procedure.path = @procedure.suggested_path(current_administrateur)
@current_administrateur = current_administrateur
@closed_procedures = current_administrateur.procedures.with_discarded.closes.map { |p| ["#{p.libelle} (#{p.id})", p.id] }.to_h
if @procedure.auto_archive_on && !@procedure.auto_archive_on.future?
flash.alert = "La date limite de dépôt des dossiers doit être postérieure à la date du jour pour réactiver la procédure. #{view_context.link_to('Veuillez la modifier', edit_admin_procedure_path(@procedure))}"
redirect_to admin_procedure_path(@procedure)
else
@procedure.path = @procedure.suggested_path(current_administrateur)
@current_administrateur = current_administrateur
@closed_procedures = current_administrateur.procedures.with_discarded.closes.map { |p| ["#{p.libelle} (#{p.id})", p.id] }.to_h
end
end
def publish

View file

@ -902,6 +902,32 @@ describe Administrateurs::ProceduresController, type: :controller do
end
end
describe 'GET #publication' do
subject(:perform_request) { get :publication, params: { procedure_id: procedure.id } }
context 'when procedure is closed' do
let(:procedure) { create(:procedure, :closed, administrateur: admin) }
it 'assigns procedure' do
perform_request
expect(response).to have_http_status(:ok)
end
context 'with auto_archive on past' do
before do
procedure.auto_archive_on = Date.today - 1.week
procedure.save(validate: false)
end
it 'suggest to update autoarchive' do
perform_request
expect(response).to redirect_to(admin_procedure_path(procedure.id))
expect(flash.alert).to include('La date limite de dépôt des dossiers doit être postérieure à la date du jour pour réactiver la procédure.')
end
end
end
end
describe 'PUT #publish' do
let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: lien_site_web) }
let(:procedure2) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }