merge expert
This commit is contained in:
parent
136f29524e
commit
a480b31eb5
3 changed files with 25 additions and 1 deletions
|
@ -23,7 +23,11 @@ module Manager
|
|||
preexisting_user.instructeur.merge(user.instructeur)
|
||||
end
|
||||
|
||||
user.expert&.update(user: preexisting_user)
|
||||
if preexisting_user.expert.nil?
|
||||
user.expert&.update(user: preexisting_user)
|
||||
else
|
||||
preexisting_user.expert.merge(user.expert)
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to edit_manager_user_path(user)
|
||||
|
|
|
@ -11,6 +11,7 @@ class Expert < ApplicationRecord
|
|||
has_many :experts_procedures
|
||||
has_many :avis, through: :experts_procedures
|
||||
has_many :dossiers, through: :avis
|
||||
has_many :commentaires
|
||||
|
||||
default_scope { eager_load(:user) }
|
||||
|
||||
|
@ -34,4 +35,9 @@ class Expert < ApplicationRecord
|
|||
@avis_summary = { unanswered: result.unanswered, total: result.total }
|
||||
end
|
||||
end
|
||||
|
||||
def merge(old_expert)
|
||||
old_expert.experts_procedures.update_all(expert_id: id)
|
||||
old_expert.commentaires.update_all(expert_id: id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,6 +97,20 @@ describe Manager::UsersController, type: :controller do
|
|||
expect(preexisting_user.instructeur.bulk_messages).to match([bulk_message])
|
||||
end
|
||||
end
|
||||
|
||||
context 'and the source expert has some avis and commentaires' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: user.expert, procedure: dossier.procedure) }
|
||||
let!(:avis) { create(:avis, dossier: dossier, claimant: create(:instructeur), experts_procedure: experts_procedure) }
|
||||
let!(:commentaire) { create(:commentaire, expert: expert, dossier: dossier) }
|
||||
|
||||
it 'transfers the avis' do
|
||||
subject
|
||||
|
||||
expect(preexisting_user.expert.avis).to match([avis])
|
||||
expect(preexisting_user.expert.commentaires).to match([commentaire])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue