fix(merge): transfers hidden procedures
This commit is contained in:
parent
f391207919
commit
1760ccbc01
2 changed files with 7 additions and 4 deletions
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue