merge admin api tokens

This commit is contained in:
Christophe Robillard 2023-06-28 13:37:33 +02:00
parent 8898d44961
commit faecefe405
2 changed files with 14 additions and 0 deletions

View file

@ -139,6 +139,10 @@ class Administrateur < ApplicationRecord
i.administrateurs << self
i.administrateurs.delete(old_admin)
end
old_admin.api_tokens.each do |token|
self.api_tokens << token
end
end
def zones

View file

@ -166,6 +166,16 @@ describe Administrateur, type: :model do
end
end
context 'when the old admin has an api token' do
let(:old_admin) { create(:administrateur, :with_api_token) }
it 'transferts the api token' do
subject
expect(new_admin.api_tokens.count).to eq 1
expect(new_admin.api_tokens.first).to eq old_admin.api_tokens.first
end
end
context 'when both admins share an instructeur' do
let(:instructeur) { create(:instructeur) }