Merge pull request #7646 from betagouv/fix-service-destroy-having-discarded-procedure

fix(service): destroy with discarded procedure
This commit is contained in:
Paul Chavard 2022-08-02 13:08:20 +02:00 committed by GitHub
commit 80edf23446
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View file

@ -64,6 +64,7 @@ module Administrateurs
flash[:alert] = message
redirect_to admin_services_path(procedure_id: params[:procedure_id])
else
service_to_destroy.procedures.with_discarded.discarded.update(service: nil)
service_to_destroy.destroy
redirect_to admin_services_path(procedure_id: params[:procedure_id]),
notice: "#{service_to_destroy.nom} est supprimé"

View file

@ -55,6 +55,9 @@ Rails.application.configure do
# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

View file

@ -135,5 +135,19 @@ describe Administrateurs::ServicesController, type: :controller do
it { expect(flash.notice).to be_nil }
it { expect(response).to redirect_to(admin_services_path(procedure_id: 12)) }
end
context "when a service has some related discarded procedures" do
let!(:procedure) { create(:procedure, :discarded, service: service) }
before do
sign_in(admin.user)
delete :destroy, params: { id: service.id, procedure_id: procedure.id }
end
it { expect { service.reload }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect(flash.alert).to be_nil }
it { expect(flash.notice).to eq("#{service.nom} est supprimé") }
it { expect(procedure.reload.service_id).to be_nil }
end
end
end