Add gestionnaire deletion feature
This commit is contained in:
parent
dcd943a4b5
commit
6b7d3e0ac1
5 changed files with 48 additions and 1 deletions
14
app/assets/javascripts/admin.js
Normal file
14
app/assets/javascripts/admin.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
$(document).on('page:load', destroy_action);
|
||||
$(document).ready(destroy_action);
|
||||
|
||||
function destroy_action(){
|
||||
$("#destroy").on('click', function(){
|
||||
$("#destroy").hide();
|
||||
$("#confirm").show();
|
||||
});
|
||||
|
||||
$("#confirm #cancel").on('click', function(){
|
||||
$("#destroy").show();
|
||||
$("#confirm").hide();
|
||||
});
|
||||
}
|
|
@ -25,6 +25,13 @@ class Admin::GestionnairesController < AdminController
|
|||
redirect_to admin_gestionnaires_path
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
Gestionnaire.find(params[:id]).destroy
|
||||
redirect_to admin_gestionnaires_path
|
||||
end
|
||||
|
||||
|
||||
def create_gestionnaire_params
|
||||
params.require(:gestionnaire).permit(:email)
|
||||
.merge(administrateur_id: current_administrateur.id)
|
||||
|
|
|
@ -6,6 +6,16 @@
|
|||
- @gestionnaires.each do |gestionnaire|
|
||||
%tr
|
||||
%td= gestionnaire.email
|
||||
%td{ style: 'text-align:right' }
|
||||
%span#destroy{ class: "fa fa-times" }
|
||||
#confirm
|
||||
=link_to(admin_gestionnaire_path(id: gestionnaire.id), method: :delete) do
|
||||
%span#valid{ class: "fa fa-check btn-success" }
|
||||
%span#valid
|
||||
Valider
|
||||
%span
|
||||
|
|
||||
%span#cancel{ class: "fa fa-minus btn-danger" }
|
||||
|
||||
= smart_listing.paginate
|
||||
= smart_listing.pagination_per_page_links
|
||||
|
|
|
@ -74,7 +74,7 @@ Rails.application.routes.draw do
|
|||
resource :pieces_justificatives, only: [:show, :update]
|
||||
resources :pieces_justificatives, only: :destroy
|
||||
end
|
||||
resources :gestionnaires, only: [:index, :create]
|
||||
resources :gestionnaires, only: [:index, :create, :destroy]
|
||||
end
|
||||
|
||||
get 'backoffice' => 'backoffice#index'
|
||||
|
|
|
@ -87,4 +87,20 @@ describe Admin::GestionnairesController, type: :controller do
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:email) { 'test@plop.com' }
|
||||
before do
|
||||
post :create, gestionnaire: { email: email }
|
||||
end
|
||||
let(:gestionnaire) { Gestionnaire.last }
|
||||
|
||||
let(:response) { delete :destroy, id: gestionnaire.id }
|
||||
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect(response).to redirect_to admin_gestionnaires_path }
|
||||
it { expect{response}.to change(Gestionnaire, :count).by(-1) }
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue