destroy export_template

This commit is contained in:
Christophe Robillard 2024-03-12 17:28:43 +01:00 committed by simon lehericey
parent 93f1fd5ebf
commit 2c28d97f3f
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
5 changed files with 28 additions and 2 deletions

View file

@ -37,6 +37,14 @@ module Instructeurs
end
end
def destroy
if @export_template.destroy
redirect_to exports_instructeur_procedure_path(procedure: @procedure), notice: "Le modèle d'export #{@export_template.name} a bien été supprimé"
else
redirect_to exports_instructeur_procedure_path(procedure: @procedure), alert: "Le modèle d'export #{@export_template.name} n'a pu être supprimé"
end
end
def preview
param = params.require(:export_template).keys.first
@preview_param = param.delete_prefix("tiptap_")

View file

@ -3,6 +3,7 @@ class ExportTemplate < ApplicationRecord
belongs_to :groupe_instructeur
has_one :procedure, through: :groupe_instructeur
has_many :exports, dependent: :nullify
validates_with ExportTemplateValidator
DOSSIER_STATE = Dossier.states.fetch(:en_construction)

View file

@ -47,7 +47,11 @@
= f.submit "Enregistrer", class: "fr-btn"
%li
= link_to "Annuler", instructeur_procedure_path(@procedure), class: "fr-btn fr-btn--secondary"
- if @export_template.sample_dossier
- if @export_template.persisted?
%li
= link_to "Supprimer", instructeur_export_template_path(@export_template, procedure_id: @procedure.id), method: :delete, data: { confirm: "Voulez-vous vraiment supprimer ce modèle ? Il sera supprimé pour tous les instructeurs du groupe"}, class: "fr-btn fr-btn--secondary"
- sample_dossier = @procedure.dossier_for_preview(current_instructeur)
- if sample_dossier
.fr-col-12.fr-col-md-4.fr-background-alt--blue-france
.export-template-preview.fr-p-2w.sticky--top
%h2.fr-h4 Aperçu

View file

@ -450,7 +450,7 @@ Rails.application.routes.draw do
resources :procedures, only: [:index, :show], param: :procedure_id do
member do
resources :archives, only: [:index, :create]
resources :export_templates, only: [:new, :create, :edit, :update] do
resources :export_templates, only: [:new, :create, :edit, :update, :destroy] do
collection do
get 'preview'
end

View file

@ -117,4 +117,17 @@ describe Instructeurs::ExportTemplatesController, type: :controller do
end
end
end
describe '#destroy' do
let(:export_template) { create(:export_template, groupe_instructeur:) }
let(:subject) { delete :destroy, params: { procedure_id: procedure.id, id: export_template.id } }
context 'with valid params' do
it 'redirect to some page' do
subject
expect(response).to redirect_to(exports_instructeur_procedure_path(procedure:))
expect(flash.notice).to eq "Le modèle d'export Mon export a bien été supprimé"
end
end
end
end