instead of call Avis table, we now call Experts Procedure table to see the experts list
This commit is contained in:
parent
85242e118b
commit
9b8d2f6fd3
6 changed files with 65 additions and 61 deletions
|
@ -186,7 +186,7 @@ module NewAdministrateur
|
||||||
end
|
end
|
||||||
|
|
||||||
def invited_expert_list
|
def invited_expert_list
|
||||||
@invited_expert_emails = Avis.invited_expert_emails(@procedure)
|
@invited_expert_emails = ExpertsProcedure.invited_expert_emails(@procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -67,16 +67,6 @@ class Avis < ApplicationRecord
|
||||||
Avis.find_by(id: avis_id)&.email == email
|
Avis.find_by(id: avis_id)&.email == email
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.invited_expert_emails(procedure)
|
|
||||||
Avis
|
|
||||||
.joins(dossier: :revision)
|
|
||||||
.left_joins(instructeur: :user)
|
|
||||||
.where(procedure_revisions: { procedure_id: procedure })
|
|
||||||
.map(&:email_to_display)
|
|
||||||
.uniq
|
|
||||||
.sort
|
|
||||||
end
|
|
||||||
|
|
||||||
def spreadsheet_columns
|
def spreadsheet_columns
|
||||||
[
|
[
|
||||||
['Dossier ID', dossier_id.to_s],
|
['Dossier ID', dossier_id.to_s],
|
||||||
|
|
|
@ -14,4 +14,15 @@ class ExpertsProcedure < ApplicationRecord
|
||||||
belongs_to :procedure
|
belongs_to :procedure
|
||||||
|
|
||||||
has_many :avis, dependent: :destroy
|
has_many :avis, dependent: :destroy
|
||||||
|
|
||||||
|
def email_to_display
|
||||||
|
expert&.email
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.invited_expert_emails(procedure)
|
||||||
|
joins(:expert)
|
||||||
|
.where(procedure: procedure)
|
||||||
|
.map(&:email_to_display)
|
||||||
|
.sort
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -217,46 +217,4 @@ RSpec.describe Avis, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#invited_expert_emails' do
|
|
||||||
let!(:procedure) { create(:procedure, :published) }
|
|
||||||
|
|
||||||
subject { Avis.invited_expert_emails(procedure) }
|
|
||||||
|
|
||||||
context 'when there is one dossier' do
|
|
||||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
||||||
|
|
||||||
context 'when a procedure has one avis and unknown instructeur' do
|
|
||||||
let!(:avis) { create(:avis, dossier: dossier, email: 'expert@expert.com') }
|
|
||||||
|
|
||||||
it { is_expected.to eq(['expert@expert.com']) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when a procedure has one avis and known instructeur' do
|
|
||||||
let!(:avis) { create(:avis, dossier: dossier, instructeur: create(:instructeur, email: 'expert@expert.com')) }
|
|
||||||
|
|
||||||
it { is_expected.to eq(['expert@expert.com']) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when a dossier has 2 avis from the same expert' do
|
|
||||||
let!(:avis) { create(:avis, dossier: dossier, email: 'expert@expert.com') }
|
|
||||||
let!(:avis2) { create(:avis, dossier: dossier, email: 'expert@expert.com') }
|
|
||||||
|
|
||||||
it { is_expected.to eq(['expert@expert.com']) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when there are two dossiers' do
|
|
||||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
||||||
let!(:dossier2) { create(:dossier, procedure: procedure) }
|
|
||||||
|
|
||||||
context 'and each one has an avis from 3 different experts' do
|
|
||||||
let!(:avis) { create(:avis, dossier: dossier, instructeur: create(:instructeur, email: '2_expert@expert.com')) }
|
|
||||||
let!(:unaffected_avis) { create(:avis, dossier: dossier2, email: '3_expert@expert.com') }
|
|
||||||
let!(:unaffected_avis2) { create(:avis, dossier: dossier2, email: '1_expert@expert.com') }
|
|
||||||
|
|
||||||
it { is_expected.to eq(['1_expert@expert.com', '2_expert@expert.com', '3_expert@expert.com']) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
42
spec/models/experts_procedure_spec.rb
Normal file
42
spec/models/experts_procedure_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
RSpec.describe ExpertsProcedure, type: :model do
|
||||||
|
describe '#invited_expert_emails' do
|
||||||
|
let!(:procedure) { create(:procedure, :published) }
|
||||||
|
let(:expert) { create(:expert) }
|
||||||
|
let(:expert2) { create(:expert) }
|
||||||
|
let(:expert3) { create(:expert) }
|
||||||
|
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) }
|
||||||
|
let(:experts_procedure2) { ExpertsProcedure.create(expert: expert2, procedure: procedure) }
|
||||||
|
let(:experts_procedure3) { ExpertsProcedure.create(expert: expert3, procedure: procedure) }
|
||||||
|
subject { ExpertsProcedure.invited_expert_emails(procedure) }
|
||||||
|
|
||||||
|
context 'when there is one dossier' do
|
||||||
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
|
||||||
|
context 'when a procedure has one avis and known instructeur' do
|
||||||
|
let!(:avis) { create(:avis, dossier: dossier, instructeur: create(:instructeur, email: expert.email), experts_procedure: experts_procedure) }
|
||||||
|
|
||||||
|
it { is_expected.to eq([expert.email]) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when a dossier has 2 avis from the same expert' do
|
||||||
|
let!(:avis) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
|
||||||
|
let!(:avis2) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
|
||||||
|
|
||||||
|
it { is_expected.to eq([expert.email]) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when there are two dossiers' do
|
||||||
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
let!(:dossier2) { create(:dossier, procedure: procedure) }
|
||||||
|
|
||||||
|
context 'and each one has an avis from 3 different experts' do
|
||||||
|
let!(:avis) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
|
||||||
|
let!(:avis2) { create(:avis, dossier: dossier2, experts_procedure: experts_procedure2) }
|
||||||
|
let!(:avis3) { create(:avis, dossier: dossier2, experts_procedure: experts_procedure3) }
|
||||||
|
|
||||||
|
it { is_expected.to eq([expert.email, expert2.email, expert3.email].sort) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -12,7 +12,7 @@ describe 'new_administrateur/procedures/invited_expert_list.html.haml', type: :v
|
||||||
context 'when the procedure has 0 avis' do
|
context 'when the procedure has 0 avis' do
|
||||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
before do
|
before do
|
||||||
@invited_expert_emails = Avis.invited_expert_emails(procedure)
|
@invited_expert_emails = ExpertsProcedure.invited_expert_emails(procedure)
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,18 +24,21 @@ describe 'new_administrateur/procedures/invited_expert_list.html.haml', type: :v
|
||||||
|
|
||||||
context 'when the procedure has 3 avis from 2 experts and 1 unasigned' do
|
context 'when the procedure has 3 avis from 2 experts and 1 unasigned' do
|
||||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
let!(:avis) { create(:avis, dossier: dossier, instructeur: create(:instructeur, email: '1_expert@expert.com')) }
|
let(:expert) { create(:expert) }
|
||||||
let!(:avis2) { create(:avis, dossier: dossier, instructeur: create(:instructeur, email: '2_expert@expert.com')) }
|
let(:expert2) { create(:expert) }
|
||||||
let!(:unasigned_avis) { create(:avis, dossier: dossier, email: 'expert@expert.com') }
|
let(:experts_procedure) { ExpertsProcedure.create(procedure: procedure, expert: expert) }
|
||||||
|
let(:experts_procedure2) { ExpertsProcedure.create(procedure: procedure, expert: expert2) }
|
||||||
|
let!(:avis) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
|
||||||
|
let!(:avis2) { create(:avis, dossier: dossier, experts_procedure: experts_procedure2) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@invited_expert_emails = Avis.invited_expert_emails(procedure)
|
@invited_expert_emails = ExpertsProcedure.invited_expert_emails(procedure)
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has 3 experts and match array' do
|
it 'has 2 experts and match array' do
|
||||||
expect(@invited_expert_emails.count).to eq(3)
|
expect(@invited_expert_emails.count).to eq(2)
|
||||||
expect(@invited_expert_emails).to eq(['1_expert@expert.com', '2_expert@expert.com', 'expert@expert.com'])
|
expect(@invited_expert_emails).to eq([expert.email, expert2.email])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue