Merge pull request #7334 from betagouv/sentry/3254070939
bug(expert/avis#instruction): raise when instructeur was merged
This commit is contained in:
commit
11d14345d1
4 changed files with 16 additions and 38 deletions
|
@ -60,14 +60,6 @@ class Avis < ApplicationRecord
|
|||
expert&.email
|
||||
end
|
||||
|
||||
def self.link_avis_to_instructeur(instructeur)
|
||||
Avis.where(email: instructeur.email).update_all(email: nil, instructeur_id: instructeur.id)
|
||||
end
|
||||
|
||||
def self.avis_exists_and_email_belongs_to_avis?(avis_id, email)
|
||||
Avis.find_by(id: avis_id)&.email == email
|
||||
end
|
||||
|
||||
def spreadsheet_columns
|
||||
[
|
||||
['Dossier ID', dossier_id.to_s],
|
||||
|
|
|
@ -302,9 +302,12 @@ class Instructeur < ApplicationRecord
|
|||
admin_with_new_instructeur.each do |admin|
|
||||
admin.instructeurs.delete(old_instructeur)
|
||||
end
|
||||
|
||||
old_instructeur.commentaires.update_all(instructeur_id: id)
|
||||
old_instructeur.bulk_messages.update_all(instructeur_id: id)
|
||||
|
||||
Avis
|
||||
.where(claimant_id: old_instructeur.id, claimant_type: Instructeur.name)
|
||||
.update_all(claimant_id: id)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -45,35 +45,6 @@ RSpec.describe Avis, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.avis_exists_and_email_belongs_to_avis?' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||
|
||||
subject { Avis.avis_exists_and_email_belongs_to_avis?(avis_id, email) }
|
||||
|
||||
context 'when the avis is unknown' do
|
||||
let(:avis_id) { 666 }
|
||||
let(:email) { 'unknown@mystery.com' }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context 'when the avis is known' do
|
||||
let(:avis_id) { avis.id }
|
||||
|
||||
context 'when the email belongs to the invitation' do
|
||||
let(:email) { invited_email }
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when the email is unknown' do
|
||||
let(:email) { 'unknown@mystery.com' }
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "email sanitization" do
|
||||
let(:expert) { create(:expert) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
|
|
@ -828,6 +828,18 @@ describe Instructeur, type: :model do
|
|||
expect(administrateur.reload.instructeurs).to match_array(new_instructeur)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when old instructeur has avis' do
|
||||
let(:avis) { create(:avis, claimant: old_instructeur) }
|
||||
before do
|
||||
avis
|
||||
subject
|
||||
end
|
||||
it 'reassign avis to new_instructeur' do
|
||||
avis.reload
|
||||
expect(avis.claimant).to eq(new_instructeur)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue