fix(ineligibilite_rules): prevent admin to enable ineligibilite rules without rules
This commit is contained in:
parent
d7f953f08c
commit
24d7b0b014
6 changed files with 33 additions and 9 deletions
|
@ -2,7 +2,7 @@
|
|||
= render Procedure::PendingRepublishComponent.new(procedure: @draft_revision.procedure, render_if: pending_changes?)
|
||||
= render Conditions::ConditionsErrorsComponent.new(conditions: condition_per_row, source_tdcs: @source_tdcs)
|
||||
.fr-fieldset
|
||||
= form_for(@draft_revision, url: change_admin_procedure_ineligibilite_rules_path(@draft_revision.procedure_id), html: { id: 'ineligibilite_form', class: 'width-100' }) do |f|
|
||||
= form_for(@draft_revision, url: change_admin_procedure_ineligibilite_rules_path(@draft_revision.procedure_id), html: { id: 'ineligibilite_form', class: 'width-100', novalidate: true }) do |f|
|
||||
.fr-fieldset__element
|
||||
.fr-toggle.fr-toggle--label-left
|
||||
= f.check_box :ineligibilite_enabled, class: 'fr-toggle__input', data: @opt
|
||||
|
|
|
@ -6,7 +6,9 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def change
|
||||
if draft_revision.update(procedure_revision_params)
|
||||
draft_revision.assign_attributes(procedure_revision_params)
|
||||
|
||||
if draft_revision.validate(:ineligibilite_rules_editor) && draft_revision.save
|
||||
redirect_to edit_admin_procedure_ineligibilite_rules_path(@procedure)
|
||||
else
|
||||
flash[:alert] = draft_revision.errors.full_messages
|
||||
|
|
|
@ -563,7 +563,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_passer_en_construction?
|
||||
return true if !revision.ineligibilite_enabled
|
||||
return true if !revision.ineligibilite_enabled || !revision.ineligibilite_rules
|
||||
|
||||
!revision.ineligibilite_rules.compute(champs_for_revision(scope: :public))
|
||||
end
|
||||
|
|
|
@ -28,6 +28,10 @@ class ProcedureRevision < ApplicationRecord
|
|||
presence: true,
|
||||
if: -> { ineligibilite_enabled? },
|
||||
on: [:ineligibilite_rules_editor, :publication]
|
||||
validates :ineligibilite_rules,
|
||||
presence: true,
|
||||
if: -> { ineligibilite_enabled? },
|
||||
on: [:ineligibilite_rules_editor, :publication]
|
||||
|
||||
serialize :ineligibilite_rules, LogicSerializer
|
||||
|
||||
|
|
|
@ -3,5 +3,6 @@ fr:
|
|||
attributes:
|
||||
procedure_revision:
|
||||
ineligibilite_message: Message d’inéligibilité
|
||||
ineligibilite_rules: Les conditions d’inéligibilité
|
||||
hints:
|
||||
ineligibilite_message: "Ce message sera affiché à l’usager si son dossier est bloqué et lui expliquera la raison de son inéligibilité."
|
||||
|
|
|
@ -220,12 +220,29 @@ describe Administrateurs::IneligibiliteRulesController, type: :controller do
|
|||
}
|
||||
end
|
||||
before { sign_in(admin.user) }
|
||||
it 'works' do
|
||||
patch :change, params: params
|
||||
draft_revision = procedure.reload.draft_revision
|
||||
expect(draft_revision.ineligibilite_message).to eq('panpan')
|
||||
expect(draft_revision.ineligibilite_enabled).to eq(true)
|
||||
expect(response).to redirect_to(edit_admin_procedure_ineligibilite_rules_path(procedure))
|
||||
|
||||
context 'when ineligibilite rules is empty' do
|
||||
it 'fails gracefull without ineligibilite rules' do
|
||||
patch :change, params: params
|
||||
draft_revision = procedure.reload.draft_revision
|
||||
expect(draft_revision.ineligibilite_enabled).to eq(false)
|
||||
expect(flash[:alert]).to include("Le champ « Les conditions d’inéligibilité » doit être rempli")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ineligibilite rules is present' do
|
||||
let(:types_de_champ_public) { [{ type: :drop_down_list, stable_id: 1, options: ['opt'] }] }
|
||||
before do
|
||||
procedure.draft_revision.update(ineligibilite_rules: ds_eq(champ_value(1), constant('opt')))
|
||||
end
|
||||
|
||||
it 'works' do
|
||||
patch :change, params: params
|
||||
draft_revision = procedure.reload.draft_revision
|
||||
expect(draft_revision.ineligibilite_message).to eq('panpan')
|
||||
expect(draft_revision.ineligibilite_enabled).to eq(true)
|
||||
expect(response).to redirect_to(edit_admin_procedure_ineligibilite_rules_path(procedure))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue