From ec8ccad465681f99609911feccb04397ea69b80c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 12 Oct 2021 11:03:34 +0200 Subject: [PATCH 1/2] typo --- spec/models/expert_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/expert_spec.rb b/spec/models/expert_spec.rb index 5b3ebf607..8d40cdda8 100644 --- a/spec/models/expert_spec.rb +++ b/spec/models/expert_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Expert, type: :model do end it 'transfers the access to the new expert' do - expect(procedure.reload.experts). to match_array(new_expert) + expect(procedure.reload.experts).to match_array(new_expert) end end From 7c65571fca93b4e6030e9bf7a137dd6eeb895432 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 12 Oct 2021 11:04:06 +0200 Subject: [PATCH 2/2] add case when the old_expert or old_instructeur is nil --- app/models/expert.rb | 2 ++ app/models/instructeur.rb | 2 ++ spec/models/expert_spec.rb | 6 ++++++ spec/models/instructeur_spec.rb | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/app/models/expert.rb b/app/models/expert.rb index 01042c840..4574a474f 100644 --- a/app/models/expert.rb +++ b/app/models/expert.rb @@ -38,6 +38,8 @@ class Expert < ApplicationRecord end def merge(old_expert) + return if old_expert.nil? + procedure_with_new, procedure_without_new = old_expert .procedures .partition { |p| p.experts.exists?(id) } diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index e9b4c5985..0a3da5b33 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -252,6 +252,8 @@ class Instructeur < ApplicationRecord end def merge(old_instructeur) + return if old_instructeur.nil? + old_instructeur .assign_to .where.not(groupe_instructeur_id: assign_to.pluck(:groupe_instructeur_id)) diff --git a/spec/models/expert_spec.rb b/spec/models/expert_spec.rb index 8d40cdda8..3a27f23aa 100644 --- a/spec/models/expert_spec.rb +++ b/spec/models/expert_spec.rb @@ -19,6 +19,12 @@ RSpec.describe Expert, type: :model do subject { new_expert.merge(old_expert) } + context 'when the old expert does not exist' do + let(:old_expert) { nil } + + it { expect { subject }.not_to raise_error } + end + context 'when an old expert access a procedure' do let(:procedure) { create(:procedure) } diff --git a/spec/models/instructeur_spec.rb b/spec/models/instructeur_spec.rb index a9ffc2c4a..768feef92 100644 --- a/spec/models/instructeur_spec.rb +++ b/spec/models/instructeur_spec.rb @@ -743,6 +743,12 @@ describe Instructeur, type: :model do subject { new_instructeur.merge(old_instructeur) } + context 'when the old instructeur does not exist' do + let(:old_instructeur) { nil } + + it { expect { subject }.not_to raise_error } + end + context 'when an procedure is assigned to the old instructeur' do let(:procedure) { create(:procedure) }