From 0b22788d600f661d97e78703ea543325693a2127 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 23 Mar 2021 12:25:57 +0100 Subject: [PATCH] experts_procedure should not be optional --- .../concerns/create_avis_concern.rb | 6 +++--- app/models/avis.rb | 2 +- .../experts/avis_controller_spec.rb | 16 ++++++++-------- .../instructeurs/avis_controller_spec.rb | 6 +++--- .../instructeurs/dossiers_controller_spec.rb | 4 ++-- spec/controllers/invites_controller_spec.rb | 4 ++-- .../procedures_controller_spec.rb | 4 ++-- spec/factories/avis.rb | 4 ++++ spec/factories/experts_procedure.rb | 6 ++++++ spec/features/experts/expert_spec.rb | 2 +- spec/features/instructeurs/expert_spec.rb | 2 +- spec/mailers/avis_mailer_spec.rb | 4 ++-- spec/models/avis_spec.rb | 14 +++++++------- spec/models/dossier_spec.rb | 18 +++++++++--------- spec/models/experts_procedure_spec.rb | 6 +++--- .../experts/avis/instruction.html.haml.spec.rb | 2 +- .../shared/avis/list.html.haml_spec.rb | 2 +- .../invited_expert_list.html.haml_spec.rb | 10 +++------- 18 files changed, 59 insertions(+), 53 deletions(-) create mode 100644 spec/factories/experts_procedure.rb diff --git a/app/controllers/concerns/create_avis_concern.rb b/app/controllers/concerns/create_avis_concern.rb index 3b42ca786..a76c03f01 100644 --- a/app/controllers/concerns/create_avis_concern.rb +++ b/app/controllers/concerns/create_avis_concern.rb @@ -18,8 +18,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) + user = User.create_or_promote_to_expert(email, SecureRandom.hex) + experts_procedure = user.valid? ? ExpertsProcedure.find_or_create_by(procedure: dossier.procedure, expert: user.expert) : nil allowed_dossiers.map do |dossier| { email: email, @@ -54,7 +54,7 @@ module CreateAvisConcern if failed.any? flash.now.alert = failed .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 # to give the user a chance to correct and resubmit diff --git a/app/models/avis.rb b/app/models/avis.rb index b2e67b1bc..bbb9e462c 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -22,7 +22,7 @@ class Avis < ApplicationRecord belongs_to :dossier, inverse_of: :avis, touch: true, optional: false 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 has_one_attached :piece_justificative_file diff --git a/spec/controllers/experts/avis_controller_spec.rb b/spec/controllers/experts/avis_controller_spec.rb index 493d5ddc5..3ce7d7e2d 100644 --- a/spec/controllers/experts/avis_controller_spec.rb +++ b/spec/controllers/experts/avis_controller_spec.rb @@ -9,9 +9,9 @@ describe Experts::AvisController, type: :controller do let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:another_procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } - let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } - let!(:avis_without_answer) { Avis.create(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(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) } + let!(:avis_without_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) } + let!(:avis_with_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, answer: 'yop') } before do sign_in(expert.user) @@ -155,7 +155,7 @@ describe Experts::AvisController, type: :controller do end 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(:asked_confidentiel) { false } let(:intro) { 'introduction' } @@ -175,7 +175,7 @@ describe Experts::AvisController, type: :controller do end 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(:intro) { 'introduction' } 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 '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_avis) { Avis.create(dossier: linked_dossier, claimant: claimant) } + let(:linked_avis) { create(:avis, dossier: linked_dossier, claimant: claimant) } let(:invite_linked_dossiers) { true } 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(:claimant) { create(:instructeur) } 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(:procedure) { dossier.procedure } let!(:avis) { create(:avis, experts_procedure: experts_procedure, claimant: claimant, dossier: dossier) } diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 7b5b5b7e2..fe4d55b77 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -5,12 +5,12 @@ describe Instructeurs::AvisController, type: :controller do let(:now) { Time.zone.parse('01/02/2345') } let(:expert) { create(:expert) } 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(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } - let!(:avis) { Avis.create(dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } - let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) } + let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } + let!(:avis_without_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) } before { sign_in(instructeur.user) } diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index fdd5beb3f..82b08ad2d 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -435,7 +435,7 @@ describe Instructeurs::DossiersController, type: :controller do describe "#create_avis" do 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(:saved_avis) { dossier.avis.first } let!(:old_avis_count) { Avis.count } @@ -556,7 +556,7 @@ describe Instructeurs::DossiersController, type: :controller do let(:instructeur) { create(:instructeur) } let(:expert) { create(:expert) } 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 create(:dossier, :accepte, diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index fd6416238..34ee7ef18 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -3,7 +3,7 @@ describe InvitesController, type: :controller do let(:email) { 'plop@octo.com' } let(:expert) { create(:expert) } 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 let(:invite) { Invite.last } @@ -26,7 +26,7 @@ describe InvitesController, type: :controller do end 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" end diff --git a/spec/controllers/new_administrateur/procedures_controller_spec.rb b/spec/controllers/new_administrateur/procedures_controller_spec.rb index 5aa38b7ac..9dfaf588a 100644 --- a/spec/controllers/new_administrateur/procedures_controller_spec.rb +++ b/spec/controllers/new_administrateur/procedures_controller_spec.rb @@ -536,14 +536,14 @@ describe NewAdministrateur::ProceduresController, type: :controller do describe 'PUT #update_allow_decision_access' do let!(:procedure) { create :procedure, :with_service, administrateur: admin } 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 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 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 subject diff --git a/spec/factories/avis.rb b/spec/factories/avis.rb index 45dacf38f..21e5ee81b 100644 --- a/spec/factories/avis.rb +++ b/spec/factories/avis.rb @@ -9,6 +9,10 @@ FactoryBot.define do association :dossier association :claimant, factory: :instructeur + after(:build) do |avis, _evaluator| + avis.experts_procedure ||= build(:experts_procedure, procedure: avis.dossier.procedure) + end + trait :with_instructeur do email { nil } instructeur { association :instructeur, email: generate(:expert_email) } diff --git a/spec/factories/experts_procedure.rb b/spec/factories/experts_procedure.rb new file mode 100644 index 000000000..719c9707d --- /dev/null +++ b/spec/factories/experts_procedure.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :experts_procedure do + association :expert + association :procedure + end +end diff --git a/spec/features/experts/expert_spec.rb b/spec/features/experts/expert_spec.rb index b128099fd..df81c2bd5 100644 --- a/spec/features/experts/expert_spec.rb +++ b/spec/features/experts/expert_spec.rb @@ -6,7 +6,7 @@ feature 'Inviting an expert:' do let(:expert) { create(:expert) } let(:instructeur) { create(: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(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) } diff --git a/spec/features/instructeurs/expert_spec.rb b/spec/features/instructeurs/expert_spec.rb index 1005af334..439e5d583 100644 --- a/spec/features/instructeurs/expert_spec.rb +++ b/spec/features/instructeurs/expert_spec.rb @@ -48,7 +48,7 @@ feature 'Inviting an expert:' do end 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) } scenario 'I can read the expert answer' do diff --git a/spec/mailers/avis_mailer_spec.rb b/spec/mailers/avis_mailer_spec.rb index 6ea8aba97..247606c45 100644 --- a/spec/mailers/avis_mailer_spec.rb +++ b/spec/mailers/avis_mailer_spec.rb @@ -3,8 +3,8 @@ RSpec.describe AvisMailer, type: :mailer do let(:claimant) { create(:instructeur) } let(:expert) { create(:expert) } let(:dossier) { create(:dossier) } - let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: dossier.procedure) } - let(:avis) { Avis.create(dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') } + let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) } + let(:avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') } subject { described_class.avis_invitation(avis) } diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb index e0803f0f4..cb58e186e 100644 --- a/spec/models/avis_spec.rb +++ b/spec/models/avis_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Avis, type: :model do let(:invited_email) { 'invited@avis.com' } let(:expert) { create(:expert) } 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 } @@ -31,7 +31,7 @@ RSpec.describe Avis, type: :model do 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) } + let(:experts_procedure) { create(:experts_procedure, procedure: procedure, expert: expert) } context 'an avis is linked to an experts_procedure' do let!(:avis) { create(:avis, email: nil, experts_procedure: experts_procedure) } @@ -77,8 +77,8 @@ RSpec.describe Avis, type: :model do describe "email sanitization" do let(:expert) { create(:expert) } let(:procedure) { create(:procedure) } - let!(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } - subject { Avis.create(claimant: claimant, email: email, experts_procedure: experts_procedure, dossier: create(:dossier)) } + let!(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) } + subject { create(:avis, claimant: claimant, email: email, experts_procedure: experts_procedure, dossier: create(:dossier)) } context "when there is no email" do let(:email) { nil } @@ -147,7 +147,7 @@ RSpec.describe Avis, type: :model do let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } let(:claimant_expert) { create(:instructeur) } 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) } context "when avis claimed by an expert" do @@ -164,8 +164,8 @@ RSpec.describe Avis, type: :model do let(:expert) { create(:expert) } let(:expert_2) { create(:expert) } let!(:procedure) { create(:procedure, :published, instructeurs: instructeurs) } - let(:experts_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) } - let(:experts_procedure_2) { ExpertsProcedure.create(expert: expert_2, procedure: procedure) } + let(:experts_procedure) { create(:experts_procedure, expert: expert, 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(:another_avis) { create(:avis, dossier: dossier, claimant: expert, experts_procedure: experts_procedure_2) } let(:another_instructeur) { create(:instructeur) } diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 179158d6d..d904cf131 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -307,13 +307,13 @@ describe Dossier do let!(:instructeur) { create(:instructeur) } let!(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } 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_2) { ExpertsProcedure.create(expert: expert_2, procedure: procedure) } + let!(:experts_procedure) { create(:experts_procedure, expert: expert_1, procedure: procedure) } + let!(:experts_procedure_2) { create(:experts_procedure, expert: expert_2, procedure: procedure) } let!(:expert_1) { create(:expert) } let!(:expert_2) { create(:expert) } 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_expert(expert_1)).to match([avis]) } @@ -321,7 +321,7 @@ describe Dossier do end 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_expert(expert_1)).to match([avis]) } @@ -329,7 +329,7 @@ describe Dossier do end 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_expert(expert_1)).to match([avis]) } @@ -337,7 +337,7 @@ describe Dossier do end 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_expert(expert_1)).not_to match([avis]) } @@ -345,9 +345,9 @@ describe Dossier do end 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_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_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_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) { 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) { 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_expert(expert_1)).to match([avis_2, avis_1, avis_3]) } diff --git a/spec/models/experts_procedure_spec.rb b/spec/models/experts_procedure_spec.rb index 4b4f6791f..1cb71b762 100644 --- a/spec/models/experts_procedure_spec.rb +++ b/spec/models/experts_procedure_spec.rb @@ -5,9 +5,9 @@ RSpec.describe ExpertsProcedure, type: :model do 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) } + let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) } + let(:experts_procedure2) { create(:experts_procedure, expert: expert2, procedure: procedure) } + let(:experts_procedure3) { create(:experts_procedure, expert: expert3, procedure: procedure) } subject { procedure.experts_procedures } context 'when there is one dossier' do diff --git a/spec/views/experts/avis/instruction.html.haml.spec.rb b/spec/views/experts/avis/instruction.html.haml.spec.rb index fbc72358d..150c45661 100644 --- a/spec/views/experts/avis/instruction.html.haml.spec.rb +++ b/spec/views/experts/avis/instruction.html.haml.spec.rb @@ -3,7 +3,7 @@ describe 'experts/avis/instruction.html.haml', type: :view do let(:claimant) { create(:instructeur) } let(:procedure) { create(: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 assign(:avis, avis) diff --git a/spec/views/instructeur/shared/avis/list.html.haml_spec.rb b/spec/views/instructeur/shared/avis/list.html.haml_spec.rb index 1b4b5fe17..4ebc6bb6f 100644 --- a/spec/views/instructeur/shared/avis/list.html.haml_spec.rb +++ b/spec/views/instructeur/shared/avis/list.html.haml_spec.rb @@ -6,7 +6,7 @@ describe 'instructeurs/shared/avis/_list.html.haml', type: :view do let(:instructeur) { create(:instructeur) } let(:expert) { create(:expert) } 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(:seen_at) { avis.first.created_at + 1.hour } diff --git a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb b/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb index 6f962b01e..c21d87f40 100644 --- a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb +++ b/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb @@ -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 let!(:dossier) { create(:dossier, procedure: procedure) } - let(:expert) { create(:expert) } - let(:expert2) { create(:expert) } - 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) } + let!(:avis) { create(:avis, dossier: dossier) } + let!(:avis2) { create(:avis, dossier: dossier) } before do @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 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