Merge pull request #6535 from betagouv/fix_merge
Corrige une erreur lors de la fusion de compte dans le manager
This commit is contained in:
commit
8179c609e0
4 changed files with 17 additions and 1 deletions
|
@ -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) }
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
@ -28,7 +34,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
|
||||
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue