diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index ece450a1a..c3f1e08f6 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -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 diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb index 1686f6fce..940807433 100644 --- a/spec/models/administrateur_spec.rb +++ b/spec/models/administrateur_spec.rb @@ -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) }