experts_procedure should not be optional

This commit is contained in:
Paul Chavard 2021-03-23 12:25:57 +01:00
parent 25c85dd0f9
commit 0b22788d60
18 changed files with 59 additions and 53 deletions

View file

@ -18,8 +18,8 @@ module CreateAvisConcern
create_results = Avis.create( create_results = Avis.create(
expert_emails.flat_map do |email| expert_emails.flat_map do |email|
expert = User.create_or_promote_to_expert(email, SecureRandom.hex).expert user = User.create_or_promote_to_expert(email, SecureRandom.hex)
experts_procedure = ExpertsProcedure.find_or_create_by(procedure: dossier.procedure, expert: expert) experts_procedure = user.valid? ? ExpertsProcedure.find_or_create_by(procedure: dossier.procedure, expert: user.expert) : nil
allowed_dossiers.map do |dossier| allowed_dossiers.map do |dossier|
{ {
email: email, email: email,
@ -54,7 +54,7 @@ module CreateAvisConcern
if failed.any? if failed.any?
flash.now.alert = failed flash.now.alert = failed
.filter { |avis| avis.errors.present? } .filter { |avis| avis.errors.present? }
.map { |avis| "#{avis.email} : #{avis.errors.full_messages.join(', ')}" } .map { |avis| "#{avis.email} : #{avis.errors.full_messages_for(:email).join(', ')}" }
# When an error occurs, return the avis back to the controller # When an error occurs, return the avis back to the controller
# to give the user a chance to correct and resubmit # to give the user a chance to correct and resubmit

View file

@ -22,7 +22,7 @@ class Avis < ApplicationRecord
belongs_to :dossier, inverse_of: :avis, touch: true, optional: false belongs_to :dossier, inverse_of: :avis, touch: true, optional: false
belongs_to :instructeur, optional: true belongs_to :instructeur, optional: true
belongs_to :experts_procedure, optional: true belongs_to :experts_procedure, optional: false
belongs_to :claimant, class_name: 'Instructeur', optional: false belongs_to :claimant, class_name: 'Instructeur', optional: false
has_one_attached :piece_justificative_file has_one_attached :piece_justificative_file

View file

@ -9,9 +9,9 @@ describe Experts::AvisController, type: :controller do
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let(:another_procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:another_procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) } let!(:avis_without_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) }
let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, answer: 'yop') } let!(:avis_with_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, answer: 'yop') }
before do before do
sign_in(expert.user) sign_in(expert.user)
@ -155,7 +155,7 @@ describe Experts::AvisController, type: :controller do
end end
describe '#expert_cannot_invite_another_expert' do describe '#expert_cannot_invite_another_expert' do
let!(:previous_avis) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, confidentiel: previous_avis_confidentiel) } let!(:previous_avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, confidentiel: previous_avis_confidentiel) }
let(:previous_avis_confidentiel) { false } let(:previous_avis_confidentiel) { false }
let(:asked_confidentiel) { false } let(:asked_confidentiel) { false }
let(:intro) { 'introduction' } let(:intro) { 'introduction' }
@ -175,7 +175,7 @@ describe Experts::AvisController, type: :controller do
end end
describe '#create_avis' do describe '#create_avis' do
let!(:previous_avis) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, confidentiel: previous_avis_confidentiel) } let!(:previous_avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, confidentiel: previous_avis_confidentiel) }
let(:emails) { ['a@b.com'] } let(:emails) { ['a@b.com'] }
let(:intro) { 'introduction' } let(:intro) { 'introduction' }
let(:created_avis) { Avis.last } let(:created_avis) { Avis.last }
@ -271,9 +271,9 @@ describe Experts::AvisController, type: :controller do
context 'when the expert also shares the linked dossiers' do context 'when the expert also shares the linked dossiers' do
context 'and the expert can access the linked dossiers' do context 'and the expert can access the linked dossiers' do
let(:created_avis) { Avis.create(dossier: dossier, claimant: claimant, email: "toto3@gmail.com") } let(:created_avis) { create(:avis, dossier: dossier, claimant: claimant, email: "toto3@gmail.com") }
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).map(&:value).compact) } let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).map(&:value).compact) }
let(:linked_avis) { Avis.create(dossier: linked_dossier, claimant: claimant) } let(:linked_avis) { create(:avis, dossier: linked_dossier, claimant: claimant) }
let(:invite_linked_dossiers) { true } let(:invite_linked_dossiers) { true }
it 'sends one avis for the main dossier' do it 'sends one avis for the main dossier' do
@ -304,7 +304,7 @@ describe Experts::AvisController, type: :controller do
let(:invited_email) { 'invited@avis.com' } let(:invited_email) { 'invited@avis.com' }
let(:claimant) { create(:instructeur) } let(:claimant) { create(:instructeur) }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:procedure) { dossier.procedure } let(:procedure) { dossier.procedure }
let!(:avis) { create(:avis, experts_procedure: experts_procedure, claimant: claimant, dossier: dossier) } let!(:avis) { create(:avis, experts_procedure: experts_procedure, claimant: claimant, dossier: dossier) }

View file

@ -5,12 +5,12 @@ describe Instructeurs::AvisController, type: :controller do
let(:now) { Time.zone.parse('01/02/2345') } let(:now) { Time.zone.parse('01/02/2345') }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:claimant) { create(:instructeur) } let(:claimant) { create(:instructeur) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let!(:avis) { Avis.create(dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) }
let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) } let!(:avis_without_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) }
before { sign_in(instructeur.user) } before { sign_in(instructeur.user) }

View file

@ -435,7 +435,7 @@ describe Instructeurs::DossiersController, type: :controller do
describe "#create_avis" do describe "#create_avis" do
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: dossier.procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
let(:invite_linked_dossiers) { false } let(:invite_linked_dossiers) { false }
let(:saved_avis) { dossier.avis.first } let(:saved_avis) { dossier.avis.first }
let!(:old_avis_count) { Avis.count } let!(:old_avis_count) { Avis.count }
@ -556,7 +556,7 @@ describe Instructeurs::DossiersController, type: :controller do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:procedure) { create(:procedure, :published, instructeurs: instructeurs) } let(:procedure) { create(:procedure, :published, instructeurs: instructeurs) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:dossier) do let(:dossier) do
create(:dossier, create(:dossier,
:accepte, :accepte,

View file

@ -3,7 +3,7 @@ describe InvitesController, type: :controller do
let(:email) { 'plop@octo.com' } let(:email) { 'plop@octo.com' }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
describe '#POST create' do describe '#POST create' do
let(:invite) { Invite.last } let(:invite) { Invite.last }
@ -26,7 +26,7 @@ describe InvitesController, type: :controller do
end end
context 'when instructeur is invited for avis on dossier' do context 'when instructeur is invited for avis on dossier' do
before { Avis.create(experts_procedure: experts_procedure, claimant: create(:instructeur), dossier: dossier) } before { create(:avis, experts_procedure: experts_procedure, claimant: create(:instructeur), dossier: dossier) }
it_behaves_like "he can not create invitation" it_behaves_like "he can not create invitation"
end end

View file

@ -536,14 +536,14 @@ describe NewAdministrateur::ProceduresController, type: :controller do
describe 'PUT #update_allow_decision_access' do describe 'PUT #update_allow_decision_access' do
let!(:procedure) { create :procedure, :with_service, administrateur: admin } let!(:procedure) { create :procedure, :with_service, administrateur: admin }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:expert_procedure) { ExpertsProcedure.create(procedure: procedure, expert: expert) } let(:expert_procedure) { create(:experts_procedure, procedure: procedure, expert: expert) }
subject do subject do
put :update_allow_decision_access, params: { procedure_id: procedure.id, experts_procedure: { allow_decision_access: !expert_procedure.allow_decision_access }, expert_procedure: expert_procedure }, format: :js put :update_allow_decision_access, params: { procedure_id: procedure.id, experts_procedure: { allow_decision_access: !expert_procedure.allow_decision_access }, expert_procedure: expert_procedure }, format: :js
end end
context 'when the experts_procedure is true' do context 'when the experts_procedure is true' do
let(:expert_procedure) { ExpertsProcedure.create(procedure: procedure, expert: expert, allow_decision_access: true) } let(:expert_procedure) { create(:experts_procedure, procedure: procedure, expert: expert, allow_decision_access: true) }
before do before do
subject subject

View file

@ -9,6 +9,10 @@ FactoryBot.define do
association :dossier association :dossier
association :claimant, factory: :instructeur association :claimant, factory: :instructeur
after(:build) do |avis, _evaluator|
avis.experts_procedure ||= build(:experts_procedure, procedure: avis.dossier.procedure)
end
trait :with_instructeur do trait :with_instructeur do
email { nil } email { nil }
instructeur { association :instructeur, email: generate(:expert_email) } instructeur { association :instructeur, email: generate(:expert_email) }

View file

@ -0,0 +1,6 @@
FactoryBot.define do
factory :experts_procedure do
association :expert
association :procedure
end
end

View file

@ -6,7 +6,7 @@ feature 'Inviting an expert:' do
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) } let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) } let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }

View file

@ -48,7 +48,7 @@ feature 'Inviting an expert:' do
end end
context 'when experts submitted their answer' do context 'when experts submitted their answer' do
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let!(:answered_avis) { create(:avis, :with_answer, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } let!(:answered_avis) { create(:avis, :with_answer, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) }
scenario 'I can read the expert answer' do scenario 'I can read the expert answer' do

View file

@ -3,8 +3,8 @@ RSpec.describe AvisMailer, type: :mailer do
let(:claimant) { create(:instructeur) } let(:claimant) { create(:instructeur) }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: dossier.procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
let(:avis) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') } let(:avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') }
subject { described_class.avis_invitation(avis) } subject { described_class.avis_invitation(avis) }

View file

@ -5,7 +5,7 @@ RSpec.describe Avis, type: :model do
let(:invited_email) { 'invited@avis.com' } let(:invited_email) { 'invited@avis.com' }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
subject { avis.email_to_display } subject { avis.email_to_display }
@ -31,7 +31,7 @@ RSpec.describe Avis, type: :model do
describe "an avis is linked to an expert_procedure" do describe "an avis is linked to an expert_procedure" do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:experts_procedure) { ExpertsProcedure.create(procedure: procedure, expert: expert) } let(:experts_procedure) { create(:experts_procedure, procedure: procedure, expert: expert) }
context 'an avis is linked to an experts_procedure' do context 'an avis is linked to an experts_procedure' do
let!(:avis) { create(:avis, email: nil, experts_procedure: experts_procedure) } let!(:avis) { create(:avis, email: nil, experts_procedure: experts_procedure) }
@ -77,8 +77,8 @@ RSpec.describe Avis, type: :model do
describe "email sanitization" do describe "email sanitization" do
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let!(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let!(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
subject { Avis.create(claimant: claimant, email: email, experts_procedure: experts_procedure, dossier: create(:dossier)) } subject { create(:avis, claimant: claimant, email: email, experts_procedure: experts_procedure, dossier: create(:dossier)) }
context "when there is no email" do context "when there is no email" do
let(:email) { nil } let(:email) { nil }
@ -147,7 +147,7 @@ RSpec.describe Avis, type: :model do
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
let(:claimant_expert) { create(:instructeur) } let(:claimant_expert) { create(:instructeur) }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:another_expert) { create(:expert) } let(:another_expert) { create(:expert) }
context "when avis claimed by an expert" do context "when avis claimed by an expert" do
@ -164,8 +164,8 @@ RSpec.describe Avis, type: :model do
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:expert_2) { create(:expert) } let(:expert_2) { create(:expert) }
let!(:procedure) { create(:procedure, :published, instructeurs: instructeurs) } let!(:procedure) { create(:procedure, :published, instructeurs: instructeurs) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:experts_procedure_2) { ExpertsProcedure.create(expert: expert_2, procedure: procedure) } let(:experts_procedure_2) { create(:experts_procedure, expert: expert_2, procedure: procedure) }
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) }
let(:another_avis) { create(:avis, dossier: dossier, claimant: expert, experts_procedure: experts_procedure_2) } let(:another_avis) { create(:avis, dossier: dossier, claimant: expert, experts_procedure: experts_procedure_2) }
let(:another_instructeur) { create(:instructeur) } let(:another_instructeur) { create(:instructeur) }

View file

@ -307,13 +307,13 @@ describe Dossier do
let!(:instructeur) { create(:instructeur) } let!(:instructeur) { create(:instructeur) }
let!(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let!(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let!(:dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction)) } let!(:dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction)) }
let!(:experts_procedure) { ExpertsProcedure.create(expert: expert_1, procedure: procedure) } let!(:experts_procedure) { create(:experts_procedure, expert: expert_1, procedure: procedure) }
let!(:experts_procedure_2) { ExpertsProcedure.create(expert: expert_2, procedure: procedure) } let!(:experts_procedure_2) { create(:experts_procedure, expert: expert_2, procedure: procedure) }
let!(:expert_1) { create(:expert) } let!(:expert_1) { create(:expert) }
let!(:expert_2) { create(:expert) } let!(:expert_2) { create(:expert) }
context 'when there is a public advice asked from the dossiers instructeur' do context 'when there is a public advice asked from the dossiers instructeur' do
let!(:avis) { Avis.create(dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: false) } let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: false) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) } it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) }
it { expect(dossier.avis_for_expert(expert_1)).to match([avis]) } it { expect(dossier.avis_for_expert(expert_1)).to match([avis]) }
@ -321,7 +321,7 @@ describe Dossier do
end end
context 'when there is a private advice asked from the dossiers instructeur' do context 'when there is a private advice asked from the dossiers instructeur' do
let!(:avis) { Avis.create(dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) } let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) } it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) }
it { expect(dossier.avis_for_expert(expert_1)).to match([avis]) } it { expect(dossier.avis_for_expert(expert_1)).to match([avis]) }
@ -329,7 +329,7 @@ describe Dossier do
end end
context 'when there is a public advice asked from one expert to another' do context 'when there is a public advice asked from one expert to another' do
let!(:avis) { Avis.create(dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: false) } let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: false) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) } it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) }
it { expect(dossier.avis_for_expert(expert_1)).to match([avis]) } it { expect(dossier.avis_for_expert(expert_1)).to match([avis]) }
@ -337,7 +337,7 @@ describe Dossier do
end end
context 'when there is a private advice asked from one expert to another' do context 'when there is a private advice asked from one expert to another' do
let!(:avis) { Avis.create(dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: true) } let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: true) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) } it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) }
it { expect(dossier.avis_for_expert(expert_1)).not_to match([avis]) } it { expect(dossier.avis_for_expert(expert_1)).not_to match([avis]) }
@ -345,9 +345,9 @@ describe Dossier do
end end
context 'when they are a lot of advice' do context 'when they are a lot of advice' do
let!(:avis_1) { Avis.create(dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('10/01/2010'), tmp_expert_migrated: true) } let!(:avis_1) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('10/01/2010'), tmp_expert_migrated: true) }
let!(:avis_2) { Avis.create(dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('9/01/2010'), tmp_expert_migrated: true) } let!(:avis_2) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('9/01/2010'), tmp_expert_migrated: true) }
let!(:avis_3) { Avis.create(dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('11/01/2010'), tmp_expert_migrated: true) } let!(:avis_3) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('11/01/2010'), tmp_expert_migrated: true) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis_2, avis_1, avis_3]) } it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis_2, avis_1, avis_3]) }
it { expect(dossier.avis_for_expert(expert_1)).to match([avis_2, avis_1, avis_3]) } it { expect(dossier.avis_for_expert(expert_1)).to match([avis_2, avis_1, avis_3]) }

View file

@ -5,9 +5,9 @@ RSpec.describe ExpertsProcedure, type: :model do
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let(:expert2) { create(:expert) } let(:expert2) { create(:expert) }
let(:expert3) { create(:expert) } let(:expert3) { create(:expert) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:experts_procedure2) { ExpertsProcedure.create(expert: expert2, procedure: procedure) } let(:experts_procedure2) { create(:experts_procedure, expert: expert2, procedure: procedure) }
let(:experts_procedure3) { ExpertsProcedure.create(expert: expert3, procedure: procedure) } let(:experts_procedure3) { create(:experts_procedure, expert: expert3, procedure: procedure) }
subject { procedure.experts_procedures } subject { procedure.experts_procedures }
context 'when there is one dossier' do context 'when there is one dossier' do

View file

@ -3,7 +3,7 @@ describe 'experts/avis/instruction.html.haml', type: :view do
let(:claimant) { create(:instructeur) } let(:claimant) { create(:instructeur) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let!(:avis) { create(:avis, confidentiel: confidentiel, claimant: claimant, experts_procedure: experts_procedure) } let!(:avis) { create(:avis, confidentiel: confidentiel, claimant: claimant, experts_procedure: experts_procedure) }
let!(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } let!(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
before do before do
assign(:avis, avis) assign(:avis, avis)

View file

@ -6,7 +6,7 @@ describe 'instructeurs/shared/avis/_list.html.haml', type: :view do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:expert) { create(:expert) } let(:expert) { create(:expert) }
let!(:dossier) { create(:dossier) } let!(:dossier) { create(:dossier) }
let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: dossier.procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
let(:avis) { [create(:avis, claimant: instructeur, experts_procedure: experts_procedure)] } let(:avis) { [create(:avis, claimant: instructeur, experts_procedure: experts_procedure)] }
let(:seen_at) { avis.first.created_at + 1.hour } let(:seen_at) { avis.first.created_at + 1.hour }

View file

@ -24,12 +24,8 @@ 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(:expert) { create(:expert) } let!(:avis) { create(:avis, dossier: dossier) }
let(:expert2) { create(:expert) } let!(:avis2) { create(:avis, dossier: dossier) }
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_experts = procedure.experts_procedures @invited_experts = procedure.experts_procedures
@ -38,7 +34,7 @@ describe 'new_administrateur/procedures/invited_expert_list.html.haml', type: :v
it 'has 2 experts and match array' do it 'has 2 experts and match array' do
expect(@invited_experts.count).to eq(2) expect(@invited_experts.count).to eq(2)
expect(@invited_experts).to match_array([experts_procedure, experts_procedure2]) expect(@invited_experts).to match_array([avis.experts_procedure, avis2.experts_procedure])
end end
end end
end end