[#2604] Introduce errors when retrieving ProcedurePresentation

This commit is contained in:
Frederic Merizen 2018-10-23 11:39:54 +02:00
parent 84cac7a5c2
commit 7baa239095
5 changed files with 21 additions and 9 deletions

View file

@ -212,7 +212,11 @@ module NewGestionnaire
end
def get_procedure_presentation
current_gestionnaire.procedure_presentation_for_procedure_id(params[:procedure_id])
procedure_presentation, errors = current_gestionnaire.procedure_presentation_and_errors_for_procedure_id(params[:procedure_id])
if errors.present?
flash[:alert] = "Votre affichage a dû être réinitialisé en raison du problème suivant : " + errors.full_messages.join(', ')
end
procedure_presentation
end
def displayed_fields_values

View file

@ -3,7 +3,7 @@ class AssignTo < ApplicationRecord
belongs_to :gestionnaire
has_one :procedure_presentation, dependent: :destroy
def procedure_presentation_or_default
procedure_presentation || build_procedure_presentation
def procedure_presentation_or_default_and_errors
[procedure_presentation || build_procedure_presentation, nil]
end
end

View file

@ -81,8 +81,8 @@ class Gestionnaire < ApplicationRecord
end
end
def procedure_presentation_for_procedure_id(procedure_id)
assign_to.find_by(procedure_id: procedure_id).procedure_presentation_or_default
def procedure_presentation_and_errors_for_procedure_id(procedure_id)
assign_to.find_by(procedure_id: procedure_id).procedure_presentation_or_default_and_errors
end
def notifications_for_dossier(dossier)

View file

@ -1,18 +1,22 @@
describe AssignTo, type: :model do
describe '#procedure_presentation_or_default' do
describe '#procedure_presentation_or_default_and_errors' do
let(:procedure) { create(:procedure) }
let(:assign_to) { AssignTo.create(procedure: procedure) }
let(:procedure_presentation_or_default) { assign_to.procedure_presentation_or_default }
let(:procedure_presentation_and_errors) { assign_to.procedure_presentation_or_default_and_errors }
let(:procedure_presentation_or_default) { procedure_presentation_and_errors.first }
let(:errors) { procedure_presentation_and_errors.second }
context "without a procedure_presentation" do
it { expect(procedure_presentation_or_default).not_to be_persisted }
it { expect(errors).to be_nil }
end
context "with a procedure_presentation" do
let!(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to) }
it { expect(procedure_presentation_or_default).to eq(procedure_presentation) }
it { expect(errors).to be_nil }
end
end
end

View file

@ -197,20 +197,24 @@ describe Gestionnaire, type: :model do
end
end
describe "procedure_presentation_for_procedure_id" do
let(:procedure_presentation) { gestionnaire.procedure_presentation_for_procedure_id(procedure_id) }
describe "procedure_presentation_and_errors_for_procedure_id" do
let(:procedure_presentation_and_errors) { gestionnaire.procedure_presentation_and_errors_for_procedure_id(procedure_id) }
let(:procedure_presentation) { procedure_presentation_and_errors.first }
let(:errors) { procedure_presentation_and_errors.second }
context 'with explicit presentation' do
let(:procedure_id) { procedure.id }
let!(:pp) { ProcedurePresentation.create(assign_to: procedure_assign) }
it { expect(procedure_presentation).to eq(pp) }
it { expect(errors).to be_nil }
end
context 'with default presentation' do
let(:procedure_id) { procedure_2.id }
it { expect(procedure_presentation).not_to be_persisted }
it { expect(errors).to be_nil }
end
end