Can get dossier vide if procedure is closed

This commit is contained in:
Christophe Robillard 2022-08-05 15:45:13 +02:00
parent 29e3b3f831
commit e087582f57
2 changed files with 15 additions and 5 deletions

View file

@ -19,14 +19,14 @@ module Users
end
def dossier_vide_pdf
@procedure = retrieve_procedure
@procedure = retrieve_procedure_with_closed
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
generate_empty_pdf(@procedure.published_revision)
end
def dossier_vide_pdf_test
@procedure = retrieve_procedure
@procedure = retrieve_procedure_with_closed
return procedure_not_found if @procedure.blank? || (@procedure.publiee? && !@procedure.draft_changed?)
generate_empty_pdf(@procedure.draft_revision)
@ -66,6 +66,10 @@ module Users
Procedure.publiees.or(Procedure.brouillons).find_by(path: params[:path])
end
def retrieve_procedure_with_closed
Procedure.publiees.or(Procedure.brouillons).or(Procedure.closes).find_by(path: params[:path])
end
def procedure_not_found
procedure = Procedure.find_by(path: params[:path])

View file

@ -192,22 +192,28 @@ describe Users::CommencerController, type: :controller do
end
describe '#dossier_vide_pdf' do
let(:procedure) { create(:procedure, :published, :with_service, :with_path) }
before { get :dossier_vide_pdf, params: { path: procedure.path } }
context 'published procedure' do
let(:procedure) { create(:procedure, :published, :with_service, :with_path) }
it 'works' do
expect(response).to have_http_status(:success)
end
end
context 'not published procedure' do
context 'not yet published procedure' do
let(:procedure) { create(:procedure, :with_service, :with_path) }
it 'redirects to procedure not found' do
expect(response).to have_http_status(302)
end
end
context 'closed procedure' do
it 'works' do
procedure.service = create(:service)
procedure.close!
expect(response).to have_http_status(:success)
end
end
end
describe '#dossier_vide_test_pdf' do