change PieceJustificativeController :
replace edit by show add update
This commit is contained in:
parent
f92f0f46cc
commit
1379d6d495
10 changed files with 145 additions and 99 deletions
|
@ -1,7 +1,24 @@
|
|||
class Admin::PiecesJustificativesController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
|
||||
def edit
|
||||
@procedure = Procedure.find(params[:procedure_id])
|
||||
@types_de_piece_justificative = @procedure.types_de_piece_justificative
|
||||
def show
|
||||
end
|
||||
|
||||
def update
|
||||
@procedure.update_attributes(update_params)
|
||||
render 'show', format: :js
|
||||
end
|
||||
|
||||
def update_params
|
||||
params
|
||||
.require(:procedure)
|
||||
.permit(types_de_piece_justificative_attributes: [:libelle, :description, :id])
|
||||
end
|
||||
|
||||
|
||||
def retrieve_procedure
|
||||
@procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: { message: 'Procedure not found' }, status: 404
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ class Procedure < ActiveRecord::Base
|
|||
has_many :types_de_champ
|
||||
has_many :dossiers
|
||||
accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
|
||||
accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
belongs_to :administrateur
|
||||
|
||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
|
|
|
@ -1,25 +1,16 @@
|
|||
- types_de_piece_justificative.each do |type_de_piece_justificative|
|
||||
- type_de_piece_justificative.id.nil? ? object_for = "new_type_de_piece_justificative[#{index}]" : object_for = 'types_de_piece_justificative[]'
|
||||
|
||||
= f.fields_for object_for, type_de_piece_justificative do |ff|
|
||||
.form-inline{id:"type_de_piece_justificative_#{type_de_piece_justificative.id || index}", class: 'type_de_piece_justificative', style: 'padding-bottom:8px'}
|
||||
.form-group{ style: 'padding-right: 2%' }
|
||||
%h4 Libellé
|
||||
=ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
|
||||
= f.fields_for :types_de_piece_justificative, types_de_piece_justificative do |ff|
|
||||
.form-inline
|
||||
.form-group
|
||||
%h4 Libellé
|
||||
=ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
|
||||
|
||||
.form-group{ style: 'padding-right: 2%' }
|
||||
%h4
|
||||
Description
|
||||
=ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
||||
.form-group
|
||||
%h4 Description
|
||||
=ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
||||
|
||||
=ff.hidden_field '_destroy', value: 'false', class: 'destroy'
|
||||
|
||||
.form-group{ id: "delete_type_de_piece_justificative_#{type_de_piece_justificative.id || index}_button", style: ("display:none" if type_de_piece_justificative.id.nil?) }
|
||||
-if ff.object.id.nil?
|
||||
.form-group#add_type_de_piece_justificative_button
|
||||
%br
|
||||
%button.form-control.btn.btn-danger.fa.fa-trash-o{type: 'button', id: "delete_type_de_piece_justificative_#{type_de_piece_justificative.id || index}_procedure"}
|
||||
|
||||
-if type_de_piece_justificative.id.nil?
|
||||
.form-group#add_type_de_piece_justificative_button
|
||||
%br
|
||||
%button.form-control.btn.btn-success#add_type_de_piece_justificative_procedure{type: 'button'} Ajouter
|
||||
= f.submit('Ajouter la pièce')
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
%ul.nav.nav-tabs
|
||||
%li
|
||||
= link_to('Description', admin_procedure_path(@procedure))
|
||||
%li
|
||||
= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
|
||||
%li.active
|
||||
= link_to('Pièces justificatives', edit_admin_procedure_pieces_justificatives_path(@procedure))
|
||||
|
||||
= form_for [:admin, @procedure], remote: true do |f|
|
||||
#liste_piece_justificative
|
||||
-unless @types_de_piece_justificative.nil?
|
||||
= render partial: 'form', locals:{ types_de_piece_justificative: @types_de_piece_justificative, f: f }
|
||||
|
||||
#liste_delete_piece_justificative
|
||||
|
||||
#new_type_de_piece_justificative
|
||||
= render partial: 'form', locals:{ types_de_piece_justificative: [TypeDePieceJustificative.new], index: (@types_de_piece_justificative.nil? || @types_de_piece_justificative.last.nil? ? 0 : @procedure.types_de_piece_justificative.last.id+1), f: f }
|
||||
|
||||
%script{ type:'text/javascript' }
|
||||
="var types_de_piece_justificative_index = #{(@types_de_piece_justificative.nil? || @types_de_piece_justificative.last.nil? ? 0 : @procedure.types_de_piece_justificative.last.id+1)}"
|
12
app/views/admin/pieces_justificatives/show.html.haml
Normal file
12
app/views/admin/pieces_justificatives/show.html.haml
Normal file
|
@ -0,0 +1,12 @@
|
|||
%ul.nav.nav-tabs
|
||||
%li= link_to('Description', admin_procedure_path(@procedure))
|
||||
%li= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
|
||||
%li.active= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure))
|
||||
|
||||
= form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure) , remote: true do |f|
|
||||
#liste_piece_justificative
|
||||
= render partial: 'form', locals:{ types_de_piece_justificative: @procedure.types_de_piece_justificative, f: f }
|
||||
%hr
|
||||
|
||||
#new_type_de_piece_justificative
|
||||
= render partial: 'form', locals:{ types_de_piece_justificative: TypeDePieceJustificative.new, f: f }
|
|
@ -4,7 +4,7 @@
|
|||
%li
|
||||
= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
|
||||
%li
|
||||
= link_to('Pièces justificatives', edit_admin_procedure_pieces_justificatives_path(@procedure))
|
||||
= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
%li.active
|
||||
= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
|
||||
%li
|
||||
= link_to('Pièces justificatives', edit_admin_procedure_pieces_justificatives_path(@procedure))
|
||||
= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure))
|
||||
|
||||
#liste_champ
|
||||
= render partial: 'form'
|
|
@ -47,7 +47,7 @@ Rails.application.routes.draw do
|
|||
post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down
|
||||
end
|
||||
resources :types_de_champ, only: [:destroy]
|
||||
resource :pieces_justificatives, only: [:edit, :update]
|
||||
resource :pieces_justificatives, only: [:show, :update]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::PiecesJustificativesController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
subject { get :show, procedure_id: procedure_id }
|
||||
context 'when procedure is not found' do
|
||||
let(:procedure_id) { 9_999_999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
context 'when procedure does not belong to admin' do
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin_2) }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #update' do
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:libelle) { 'RIB' }
|
||||
let(:description) { "relevé d'identité bancaire" }
|
||||
let(:update_params) do
|
||||
{
|
||||
types_de_piece_justificative_attributes:
|
||||
{
|
||||
'0' =>
|
||||
{
|
||||
libelle: libelle,
|
||||
description: description
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
let(:request) { put :update, procedure_id: procedure_id, format: :js, procedure: update_params }
|
||||
subject { request }
|
||||
|
||||
it { is_expected.to render_template('show') }
|
||||
it { expect{ subject }.to change(TypeDePieceJustificative, :count).by(1) }
|
||||
it 'adds type de pj to procedure' do
|
||||
request
|
||||
procedure.reload
|
||||
pj = procedure.types_de_piece_justificative.first
|
||||
expect(pj.libelle).to eq(libelle)
|
||||
expect(pj.description).to eq(description)
|
||||
end
|
||||
|
||||
context 'when procedure is not found' do
|
||||
let(:procedure_id) { 9_999_999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
|
||||
context 'when libelle is blank' do
|
||||
let(:libelle) { '' }
|
||||
it { expect{ subject }.not_to change(TypeDePieceJustificative, :count) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,55 +1,36 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# feature 'add a new type de piece justificative', js: true do
|
||||
# let(:administrateur) { create(:administrateur) }
|
||||
feature 'add a new type de piece justificative', js: true do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
|
||||
# before do
|
||||
# login_as administrateur, scope: :administrateur
|
||||
# end
|
||||
|
||||
# context 'when create a new procedure' do
|
||||
# before do
|
||||
# visit new_admin_procedure_path
|
||||
# end
|
||||
|
||||
# scenario 'page have form to created new type de piece justificative' do
|
||||
# expect(page).to have_css('#type_de_piece_justificative_0')
|
||||
# expect(page).to have_css('input[name="procedure[new_type_de_piece_justificative[0]][libelle]"]')
|
||||
# expect(page).to have_css('textarea[name="procedure[new_type_de_piece_justificative[0]][description]"]')
|
||||
# expect(page).to have_css('input[name="procedure[new_type_de_piece_justificative[0]][_destroy]"]', visible: false)
|
||||
|
||||
# expect(page).to have_css('#new_type_de_piece_justificative #add_type_de_piece_justificative_button')
|
||||
# end
|
||||
|
||||
# context 'when user add a new piece justificative type' do
|
||||
# before do
|
||||
# page.find_by_id('procedure_new_type_de_piece_justificative_0__libelle').set 'Libelle de test'
|
||||
# page.find_by_id('procedure_new_type_de_piece_justificative_0__description').set 'Description de test'
|
||||
# page.click_on 'add_type_de_piece_justificative_procedure'
|
||||
# end
|
||||
|
||||
# scenario 'a new piece justificative type line is appeared with increment index id' do
|
||||
# expect(page).to have_css('#type_de_piece_justificative_1')
|
||||
# expect(page).to have_css('input[name="procedure[new_type_de_piece_justificative[1]][libelle]"]')
|
||||
# expect(page).to have_css('textarea[name="procedure[new_type_de_piece_justificative[1]][description]"]')
|
||||
# expect(page).to have_css('input[name="procedure[new_type_de_piece_justificative[1]][_destroy]"]', visible: false)
|
||||
# end
|
||||
|
||||
# scenario 'the first line is filled' do
|
||||
# expect(page.find_by_id('procedure_new_type_de_piece_justificative_0__libelle').value).to eq('Libelle de test')
|
||||
# expect(page.find_by_id('procedure_new_type_de_piece_justificative_0__description').value).to eq('Description de test')
|
||||
# end
|
||||
|
||||
# scenario 'the new line is empty' do
|
||||
# expect(page.find_by_id('procedure_new_type_de_piece_justificative_1__libelle').value).to eq('')
|
||||
# expect(page.find_by_id('procedure_new_type_de_piece_justificative_1__description').value).to eq('')
|
||||
# expect(page.find_by_id('procedure_new_type_de_piece_justificative_1___destroy', visible: false).value).to eq('false')
|
||||
# end
|
||||
|
||||
# scenario 'the button Ajouter is at side new line' do
|
||||
# expect(page).to have_css('#new_type_de_piece_justificative #type_de_piece_justificative_1 #add_type_de_piece_justificative_button')
|
||||
# expect(page).not_to have_css('#type_de_piece_justificative_0 #add_type_de_piece_justificative_button')
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
before do
|
||||
login_as administrateur, scope: :administrateur
|
||||
end
|
||||
context 'when there is no piece justificative' do
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
before do
|
||||
visit admin_procedure_pieces_justificatives_path(procedure)
|
||||
end
|
||||
scenario 'displays a form to add new type de piece justificative' do
|
||||
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle')
|
||||
end
|
||||
context 'when user fills field and submit' do
|
||||
let(:libelle) { 'ma piece' }
|
||||
let(:description) { 'ma description' }
|
||||
before do
|
||||
page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set(libelle)
|
||||
page.find_by_id('procedure_types_de_piece_justificative_attributes_0_description').set(description)
|
||||
page.click_on 'Ajouter la pièce'
|
||||
wait_for_ajax
|
||||
end
|
||||
subject do
|
||||
procedure.reload
|
||||
procedure.types_de_piece_justificative.first
|
||||
end
|
||||
scenario 'creates new type de piece' do
|
||||
expect(subject.libelle).to eq(libelle)
|
||||
expect(subject.description).to eq(description)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue