From faecefe40568677e40b5a9b597ce1f83d81f20b7 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 28 Jun 2023 13:37:33 +0200 Subject: [PATCH] merge admin api tokens --- app/models/administrateur.rb | 4 ++++ spec/models/administrateur_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) 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) }