end delete type de piece justificative
This commit is contained in:
parent
bd5dc1e35a
commit
17ca244a2f
6 changed files with 58 additions and 2 deletions
|
@ -9,6 +9,14 @@ class Admin::PiecesJustificativesController < AdminController
|
||||||
render 'show', format: :js
|
render 'show', format: :js
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@procedure.types_de_piece_justificative.find(params[:id]).destroy
|
||||||
|
|
||||||
|
render 'show', format: :js
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render json: { message: 'Type de piece justificative not found' }, status: 404
|
||||||
|
end
|
||||||
|
|
||||||
def update_params
|
def update_params
|
||||||
params
|
params
|
||||||
.require(:procedure)
|
.require(:procedure)
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
%h4 Description
|
%h4 Description
|
||||||
=ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
=ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
||||||
|
|
||||||
-if ff.object.id.nil?
|
- if ff.object.id.nil?
|
||||||
.form-group#add_type_de_piece_justificative_button
|
.form-group#add_type_de_piece_justificative_button
|
||||||
%br
|
%br
|
||||||
= f.submit('Ajouter la pièce')
|
= f.submit('Ajouter la pièce')
|
||||||
|
- else
|
||||||
|
= link_to("", admin_procedure_piece_justificative_path(@procedure, ff.object.id), method: :delete, remote: true, id: "delete_type_de_piece_justificative_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :types_de_champ, only: [:destroy]
|
resources :types_de_champ, only: [:destroy]
|
||||||
resource :pieces_justificatives, only: [:show, :update]
|
resource :pieces_justificatives, only: [:show, :update]
|
||||||
|
resources :pieces_justificatives, only: :destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe Admin::PiecesJustificativesController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #update' do
|
describe 'PUT #update' do
|
||||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||||
let(:procedure_id) { procedure.id }
|
let(:procedure_id) { procedure.id }
|
||||||
let(:libelle) { 'RIB' }
|
let(:libelle) { 'RIB' }
|
||||||
|
@ -62,4 +62,31 @@ describe Admin::PiecesJustificativesController, type: :controller do
|
||||||
it { expect{ subject }.not_to change(TypeDePieceJustificative, :count) }
|
it { expect{ subject }.not_to change(TypeDePieceJustificative, :count) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'DELETE #destroy' do
|
||||||
|
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||||
|
let!(:pj) { create(:type_de_piece_justificative, procedure: procedure) }
|
||||||
|
let(:procedure_id) { procedure.id }
|
||||||
|
let(:pj_id) { pj.id }
|
||||||
|
let(:request) { delete :destroy, procedure_id: procedure_id, id: pj_id }
|
||||||
|
subject { request }
|
||||||
|
context 'when procedure is not found' do
|
||||||
|
let(:procedure_id) { 9_999_999 }
|
||||||
|
it { expect(subject.status).to eq(404) }
|
||||||
|
end
|
||||||
|
context 'when pj id does not exist' do
|
||||||
|
let(:pj_id) { 9_999_999 }
|
||||||
|
it { expect(subject.status).to eq(404) }
|
||||||
|
end
|
||||||
|
context 'when pj id exist but is not linked to procedure' do
|
||||||
|
let(:procedure_1) { create(:procedure, administrateur: admin) }
|
||||||
|
let!(:pj_1) { create(:type_de_piece_justificative, procedure: procedure_1) }
|
||||||
|
let(:pj_id) { pj_1 }
|
||||||
|
it { expect(subject.status).to eq(404) }
|
||||||
|
end
|
||||||
|
context 'when pj is found' do
|
||||||
|
it { expect(subject.status).to eq(200) }
|
||||||
|
it { expect{ subject }.to change(TypeDePieceJustificative, :count).by(-1) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,5 +1,9 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :type_de_piece_justificative do
|
factory :type_de_piece_justificative do
|
||||||
|
|
||||||
|
libelle 'RIB'
|
||||||
|
description 'Releve identité bancaire'
|
||||||
|
|
||||||
trait :rib do
|
trait :rib do
|
||||||
libelle 'RIB'
|
libelle 'RIB'
|
||||||
description 'Releve identité bancaire'
|
description 'Releve identité bancaire'
|
||||||
|
|
|
@ -43,6 +43,20 @@ feature 'add a new type de piece justificative', js: true do
|
||||||
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_1_libelle')
|
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_1_libelle')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
context 'when user delete pj' do
|
||||||
|
before do
|
||||||
|
pj = procedure.types_de_piece_justificative.first
|
||||||
|
page.find_by_id("delete_type_de_piece_justificative_#{pj.id}").click
|
||||||
|
wait_for_ajax
|
||||||
|
end
|
||||||
|
scenario 'removes pj from page' do
|
||||||
|
within '#liste_piece_justificative' do
|
||||||
|
expect(page).not_to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle')
|
||||||
|
expect(page.body).not_to match(libelle)
|
||||||
|
expect(page.body).not_to match(description)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue