Merge pull request #7334 from betagouv/sentry/3254070939

bug(expert/avis#instruction): raise when instructeur was merged
This commit is contained in:
LeSim 2022-05-24 14:30:11 +02:00 committed by GitHub
commit 11d14345d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 38 deletions

View file

@ -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],

View file

@ -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

View file

@ -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) }

View file

@ -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