From d09c47f5ce7e3e999545a286919dcec702835964 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 13 Oct 2022 16:44:20 +0200 Subject: [PATCH] =?UTF-8?q?correctif(usager.fusion):=20leve=20une=20erreur?= =?UTF-8?q?=20quand=20on=20essaie=20de=20fusionner=20un=20compte=20sur=20l?= =?UTF-8?q?ui=20m=C3=AAme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 1 + spec/models/user_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index e27b0be18..3081b0f95 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -214,6 +214,7 @@ class User < ApplicationRecord end def merge(old_user) + raise "Merging same user, no way" if old_user.id == self.id transaction do old_user.dossiers.update_all(user_id: id) old_user.invites.update_all(user_id: id) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a9715c397..75447ae94 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -423,7 +423,11 @@ describe User, type: :model do let(:targeted_user) { create(:user) } subject { targeted_user.merge(old_user) } - + context 'merge myself' do + it 'fails' do + expect { old_user.merge(old_user) }.to raise_error 'Merging same user, no way' + end + end context 'and the old account has some stuff' do let!(:dossier) { create(:dossier, user: old_user) } let!(:hidden_dossier) { create(:dossier, user: old_user, hidden_by_user_at: 1.hour.ago) }