Merge pull request #8013 from demarches-simplifiees/fix_admin_merge_with_hidden_procedures

fix(merge): transfere les procédures cachées
This commit is contained in:
LeSim 2022-11-07 14:25:20 +01:00 committed by GitHub
commit 7a1d115853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -110,7 +110,9 @@ class Administrateur < ApplicationRecord
def merge(old_admin)
return if old_admin.nil?
procedures_with_new_admin, procedures_without_new_admin = old_admin.procedures
procedures_with_new_admin, procedures_without_new_admin = old_admin
.procedures
.with_discarded
.partition { |p| p.administrateurs.exists?(id) }
procedures_with_new_admin.each do |p|

View file

@ -91,16 +91,17 @@ describe Administrateur, type: :model do
context 'when the old admin has a procedure' do
let(:procedure) { create(:procedure) }
let(:discarded_procedure) { create(:procedure, :discarded) }
before do
old_admin.procedures << procedure
old_admin.procedures << procedure << discarded_procedure
subject
[new_admin, old_admin].map(&:reload)
end
it 'transfers the procedure' do
expect(new_admin.procedures).to match_array(procedure)
expect(old_admin.procedures).to be_empty
expect(new_admin.procedures.with_discarded).to match_array([procedure, discarded_procedure])
expect(old_admin.procedures.with_discarded).to be_empty
end
end