Add verification on user dossier description for champs mandatory
This commit is contained in:
parent
494f80afff
commit
bd61a459fb
7 changed files with 63 additions and 27 deletions
|
@ -4,8 +4,7 @@ class Users::DescriptionController < UsersController
|
|||
end
|
||||
|
||||
def show
|
||||
@dossier = current_user_dossier
|
||||
@dossier = @dossier.decorate
|
||||
@dossier = current_user_dossier.decorate
|
||||
|
||||
@procedure = @dossier.procedure
|
||||
@champs = @dossier.ordered_champs
|
||||
|
@ -24,10 +23,10 @@ class Users::DescriptionController < UsersController
|
|||
def create
|
||||
@dossier = current_user_dossier
|
||||
@procedure = @dossier.procedure
|
||||
@champs = @dossier.ordered_champs
|
||||
|
||||
unless @dossier.update_attributes(create_params)
|
||||
@dossier = @dossier.decorate
|
||||
@procedure = @dossier.procedure
|
||||
|
||||
flash.now.alert = @dossier.errors.full_messages.join('<br />').html_safe
|
||||
return render 'show'
|
||||
|
@ -47,6 +46,12 @@ class Users::DescriptionController < UsersController
|
|||
unless params[:champs].nil?
|
||||
@dossier.champs.each do |champ|
|
||||
champ.value = params[:champs]["'#{champ.id}'"]
|
||||
|
||||
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
|
||||
flash.now.alert = "Le champ #{champ.libelle} doit être rempli."
|
||||
return render 'show'
|
||||
end
|
||||
|
||||
champ.save
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
class Champ < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
belongs_to :type_de_champ
|
||||
delegate :libelle, :type_champ, :order_place, to: :type_de_champ
|
||||
|
||||
delegate :libelle, :type_champ, :order_place, :mandatory, to: :type_de_champ
|
||||
|
||||
def mandatory?
|
||||
mandatory
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,11 +26,15 @@
|
|||
-if champ.type_champ == 'checkbox'
|
||||
%h4{style:'margin-left:15px;'}
|
||||
= champ.libelle
|
||||
- if champ.mandatory?
|
||||
= '*'
|
||||
%input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''}
|
||||
%input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')}
|
||||
-else
|
||||
%h4
|
||||
= champ.libelle
|
||||
- if champ.mandatory?
|
||||
= '*'
|
||||
|
||||
-if champ.type_champ == 'textarea'
|
||||
%textarea.form-control{name:"champs['#{champ.id}']",
|
||||
|
@ -62,7 +66,7 @@
|
|||
- if @procedure.cerfa_flag
|
||||
%tr
|
||||
%th{class:'col-lg-6'}
|
||||
='Formulaire (.pdf / .doc / .docx / .xls / .xlsx)'
|
||||
='Formulaire'
|
||||
|
||||
%td{class:'col-lg-5'}
|
||||
-if @dossier.cerfa_available?
|
||||
|
|
|
@ -37,6 +37,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
let(:description) { 'titi' }
|
||||
let(:order_place) { '' }
|
||||
let(:types_de_champ_id) { '' }
|
||||
let(:mandatory) { 'on' }
|
||||
|
||||
let(:procedure_params) do
|
||||
{ types_de_champ_attributes:
|
||||
|
@ -46,7 +47,8 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
type_champ: type_champ,
|
||||
description: description,
|
||||
order_place: order_place,
|
||||
id: types_de_champ_id
|
||||
id: types_de_champ_id,
|
||||
mandatory: mandatory
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +69,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
it { expect(subject.libelle).to eq('mon libelle') }
|
||||
it { expect(subject.type_champ).to eq('text') }
|
||||
it { expect(subject.description).to eq('titi') }
|
||||
# it { expect(subject.order_place).to eq('0') }
|
||||
it { expect(subject.mandatory).to be_truthy }
|
||||
end
|
||||
|
||||
context 'when type_de_champ already exist' do
|
||||
|
@ -78,6 +80,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
let(:type_champ) { 'text' }
|
||||
let(:description) { 'citrouille' }
|
||||
let(:order_place) { '0' }
|
||||
let(:mandatory) { 'on' }
|
||||
before do
|
||||
request
|
||||
procedure.reload
|
||||
|
@ -86,7 +89,8 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
it { expect(subject.libelle).to eq('toto') }
|
||||
it { expect(subject.type_champ).to eq('text') }
|
||||
it { expect(subject.description).to eq('citrouille') }
|
||||
# it { expect(subject.order_place).to eq(0) }
|
||||
it { expect(subject.order_place).to eq(0) }
|
||||
it { expect(subject.order_place).to be_truthy }
|
||||
end
|
||||
end
|
||||
context 'when procedure is not found' do
|
||||
|
|
|
@ -4,7 +4,7 @@ describe Users::DescriptionController, type: :controller do
|
|||
let(:user) { create(:user) }
|
||||
|
||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: true) }
|
||||
let!(:dossier) { create(:dossier, procedure: procedure, user: user) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
|
||||
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:bad_dossier_id) { Dossier.count + 10000 }
|
||||
|
@ -103,9 +103,9 @@ describe Users::DescriptionController, type: :controller do
|
|||
context 'Attribut(s) manquant(s)' do
|
||||
subject {
|
||||
post :create,
|
||||
dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description
|
||||
dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description
|
||||
}
|
||||
before { subject }
|
||||
|
||||
|
@ -126,9 +126,9 @@ describe Users::DescriptionController, type: :controller do
|
|||
context 'Sauvegarde du CERFA PDF' do
|
||||
before do
|
||||
post :create, dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
cerfa_pdf: cerfa_pdf
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
cerfa_pdf: cerfa_pdf
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
@ -166,9 +166,9 @@ describe Users::DescriptionController, type: :controller do
|
|||
let!(:procedure) { create(:procedure) }
|
||||
before do
|
||||
post :create, dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
cerfa_pdf: cerfa_pdf
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
cerfa_pdf: cerfa_pdf
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
@ -178,7 +178,7 @@ describe Users::DescriptionController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'Sauvegarde des champs' do
|
||||
describe 'Sauvegarde des champs' do
|
||||
let(:champs_dossier) { dossier.champs }
|
||||
let(:dossier_champs_first) { 'test value' }
|
||||
|
||||
|
@ -194,22 +194,31 @@ describe Users::DescriptionController, type: :controller do
|
|||
end
|
||||
|
||||
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
|
||||
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
||||
|
||||
context 'when champs value is empty' do
|
||||
let(:dossier_champs_first) { 'test value' }
|
||||
let(:dossier_champs_first) { '' }
|
||||
|
||||
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
|
||||
it { expect(response).to redirect_to users_dossier_recapitulatif_path }
|
||||
|
||||
context 'when champs is mandatory' do
|
||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ_mandatory, cerfa_flag: true) }
|
||||
|
||||
it { expect(response).not_to redirect_to users_dossier_recapitulatif_path }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'Sauvegarde des pièces justificatives' do
|
||||
let(:all_pj_type){ dossier.procedure.type_de_piece_justificative_ids }
|
||||
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
||||
before do
|
||||
post :create, {dossier_id: dossier_id,
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
||||
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
||||
nom_projet: nom_projet,
|
||||
description: description,
|
||||
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
||||
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
|
|
@ -27,6 +27,14 @@ FactoryGirl.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :with_type_de_champ_mandatory do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
type_de_champ = create(:type_de_champ, mandatory: true)
|
||||
|
||||
procedure.types_de_champ << type_de_champ
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_two_type_de_piece_justificative do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
rib = create(:type_de_piece_justificative, :rib)
|
||||
|
|
|
@ -4,5 +4,6 @@ FactoryGirl.define do
|
|||
description 'description de votre projet'
|
||||
type_champ 'textarea'
|
||||
order_place 1
|
||||
mandatory false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue