Merge pull request #9196 from colinux/fix-admin-publication-errors

ETQ admin je veux voir les erreurs lorsque la (re-)publication échoue
This commit is contained in:
Colin Darie 2023-06-14 09:56:46 +00:00 committed by GitHub
commit f675d2d1a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View file

@ -278,8 +278,6 @@ module Administrateurs
if @procedure.publish_or_reopen!(current_administrateur) if @procedure.publish_or_reopen!(current_administrateur)
@procedure.publish_revision! @procedure.publish_revision!
flash.notice = "Démarche publiée" flash.notice = "Démarche publiée"
else
flash.alert = @procedure.errors.full_messages
end end
else else
@procedure.publish_revision! @procedure.publish_revision!
@ -287,8 +285,6 @@ module Administrateurs
end end
elsif @procedure.publish_or_reopen!(current_administrateur) elsif @procedure.publish_or_reopen!(current_administrateur)
flash.notice = "Démarche publiée" flash.notice = "Démarche publiée"
else
flash.alert = @procedure.errors.full_messages
end end
if params[:old_procedure].present? && @procedure.errors.empty? if params[:old_procedure].present? && @procedure.errors.empty?
@ -301,6 +297,9 @@ module Administrateurs
end end
redirect_to admin_procedure_path(@procedure) redirect_to admin_procedure_path(@procedure)
rescue ActiveRecord::RecordInvalid
flash.alert = @procedure.errors.full_messages
redirect_to admin_procedure_publication_path(@procedure)
end end
def reset_draft def reset_draft

View file

@ -870,13 +870,15 @@ describe Administrateurs::ProceduresController, type: :controller do
let(:procedure3) { create(:procedure, :published, lien_site_web: lien_site_web) } let(:procedure3) { create(:procedure, :published, lien_site_web: lien_site_web) }
let(:lien_site_web) { 'http://some.administration/' } let(:lien_site_web) { 'http://some.administration/' }
subject(:perform_request) { put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } }
context 'when admin is the owner of the procedure' do context 'when admin is the owner of the procedure' do
context 'procedure path does not exist' do context 'procedure path does not exist' do
let(:path) { 'new_path' } let(:path) { 'new_path' }
let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:lien_site_web) { 'http://mon-site.gouv.fr' }
before do before do
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } perform_request
procedure.reload procedure.reload
end end
@ -895,7 +897,7 @@ describe Administrateurs::ProceduresController, type: :controller do
context 'procedure path exists and is owned by current administrator' do context 'procedure path exists and is owned by current administrator' do
before do before do
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } perform_request
procedure.reload procedure.reload
procedure2.reload procedure2.reload
end end
@ -923,13 +925,22 @@ describe Administrateurs::ProceduresController, type: :controller do
context 'procedure path exists and is not owned by current administrator' do context 'procedure path exists and is not owned by current administrator' do
let(:path) { procedure3.path } let(:path) { procedure3.path }
let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:lien_site_web) { 'http://mon-site.gouv.fr' }
it { expect { put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } }.to raise_error(ActiveRecord::RecordInvalid) }
it {
expect { perform_request }.not_to change { procedure.reload.updated_at }
expect(response).to redirect_to(admin_procedure_publication_path(procedure.id))
expect(flash[:alert]).to have_content "« Lien public » est déjà utilisé"
}
end end
context 'procedure path is invalid' do context 'procedure path is invalid' do
let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:lien_site_web) { 'http://mon-site.gouv.fr' }
let(:path) { 'Invalid Procedure Path' } let(:path) { 'Invalid Procedure Path' }
it { expect { put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } }.to raise_error(ActiveRecord::RecordInvalid) }
it {
expect { perform_request }.not_to change { procedure.reload.updated_at }
expect(flash[:alert]).to have_content "« Lien public » nest pas valide"
}
end end
context 'procedure revision is invalid' do context 'procedure revision is invalid' do
@ -941,7 +952,10 @@ describe Administrateurs::ProceduresController, type: :controller do
types_de_champ_public: [{ type: :repetition, children: [] }]) types_de_champ_public: [{ type: :repetition, children: [] }])
end end
it { expect { put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } }.to raise_error(ActiveRecord::RecordInvalid) } it {
expect { perform_request }.not_to change { procedure.reload.updated_at }
expect(flash[:alert]).to have_content "doit comporter au moins un champ"
}
end end
end end
@ -964,7 +978,10 @@ describe Administrateurs::ProceduresController, type: :controller do
context 'procedure path is valid but lien_site_web is missing' do context 'procedure path is valid but lien_site_web is missing' do
let(:path) { 'new_path2' } let(:path) { 'new_path2' }
let(:lien_site_web) { nil } let(:lien_site_web) { nil }
it { expect { put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web } }.to raise_error(ActiveRecord::RecordInvalid) } it {
expect { perform_request }.not_to change { procedure.reload.updated_at }
expect(flash[:alert]).to have_content "doit être rempli"
}
end end
end end
end end