Link avis to an expert
This commit is contained in:
parent
b683c2023b
commit
2987139dd6
2 changed files with 21 additions and 1 deletions
|
@ -19,6 +19,8 @@ module CreateAvisConcern
|
|||
|
||||
create_results = Avis.create(
|
||||
expert_emails.flat_map do |email|
|
||||
expert = User.create_or_promote_to_expert(email, SecureRandom.hex).expert
|
||||
experts_procedure = ExpertsProcedure.find_or_create_by(procedure: dossier.procedure, expert: expert)
|
||||
allowed_dossiers.map do |dossier|
|
||||
{
|
||||
email: email,
|
||||
|
@ -26,7 +28,8 @@ module CreateAvisConcern
|
|||
introduction_file: create_avis_params[:introduction_file],
|
||||
claimant: current_instructeur,
|
||||
dossier: dossier,
|
||||
confidentiel: confidentiel
|
||||
confidentiel: confidentiel,
|
||||
experts_procedure: experts_procedure
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,6 +56,23 @@ RSpec.describe Avis, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "an avis is linked to an expert_procedure" do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:expert) { create(:expert) }
|
||||
let(:experts_procedure) { ExpertsProcedure.create(procedure: procedure, expert: expert) }
|
||||
|
||||
context 'an avis is linked to an experts_procedure' do
|
||||
let!(:avis) { create(:avis, email: nil, experts_procedure: experts_procedure) }
|
||||
|
||||
before do
|
||||
avis.reload
|
||||
end
|
||||
|
||||
it { expect(avis.email).to be_nil }
|
||||
it { expect(avis.experts_procedure).to eq(experts_procedure) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.avis_exists_and_email_belongs_to_avis?' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
|
|
Loading…
Reference in a new issue