From 84214f4bd4aded317ee5afa31df48f1a9acbc976 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 23 Mar 2021 09:55:37 +0100 Subject: [PATCH 1/3] Do not export non exportable champs on draft procedures --- app/models/procedure.rb | 2 +- spec/factories/procedure.rb | 6 ++++++ spec/models/dossier_spec.rb | 41 +++++++++++++++++++++++-------------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 37c97e980..aef21aef0 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -93,7 +93,7 @@ class Procedure < ApplicationRecord def types_de_champ_for_export if brouillon? - draft_types_de_champ + draft_types_de_champ.reject(&:exclude_from_export?) else all_types_de_champ .uniq diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 516c3e927..a966e222a 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -193,6 +193,12 @@ FactoryBot.define do end end + trait :with_explication do + after(:build) do |procedure, _evaluator| + build(:type_de_champ_explication, procedure: procedure) + end + end + trait :published do after(:build) do |procedure, _evaluator| procedure.path = generate(:published_path) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index fabbe9366..8def1471c 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1345,29 +1345,40 @@ describe Dossier do end describe "champs_for_export" do - let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no) } + let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no, :with_explication) } let(:text_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } } let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } } let(:datetime_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } } + let(:explication_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:explication) } } let(:dossier) { create(:dossier, procedure: procedure) } let(:dossier_second_revision) { create(:dossier, procedure: procedure) } - before do - procedure.publish! - dossier - procedure.draft_revision.remove_type_de_champ(text_type_de_champ.stable_id) - procedure.draft_revision.add_type_de_champ(type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: 'New text field') - procedure.draft_revision.find_or_clone_type_de_champ(yes_no_type_de_champ.stable_id).update(libelle: 'Updated yes/no') - procedure.update(published_revision: procedure.draft_revision, draft_revision: procedure.create_new_revision) - dossier.reload - procedure.reload + context "when procedure published" do + before do + procedure.publish! + dossier + procedure.draft_revision.remove_type_de_champ(text_type_de_champ.stable_id) + procedure.draft_revision.add_type_de_champ(type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: 'New text field') + procedure.draft_revision.find_or_clone_type_de_champ(yes_no_type_de_champ.stable_id).update(libelle: 'Updated yes/no') + procedure.update(published_revision: procedure.draft_revision, draft_revision: procedure.create_new_revision) + dossier.reload + procedure.reload + end + + it "should have champs from all revisions" do + expect(dossier.types_de_champ.map(&:libelle)).to eq([text_type_de_champ.libelle, datetime_type_de_champ.libelle, "Yes/no", explication_type_de_champ.libelle]) + expect(dossier_second_revision.types_de_champ.map(&:libelle)).to eq([datetime_type_de_champ.libelle, "Updated yes/no", explication_type_de_champ.libelle, "New text field"]) + expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export).map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, "Updated yes/no", "New text field"]) + expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export)).to eq(dossier_second_revision.champs_for_export(dossier_second_revision.procedure.types_de_champ_for_export)) + end end - it "should have champs from all revisions" do - expect(dossier.types_de_champ.map(&:libelle)).to eq([text_type_de_champ.libelle, datetime_type_de_champ.libelle, "Yes/no"]) - expect(dossier_second_revision.types_de_champ.map(&:libelle)).to eq([datetime_type_de_champ.libelle, "Updated yes/no", "New text field"]) - expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export).map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, "Updated yes/no", "New text field"]) - expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export)).to eq(dossier_second_revision.champs_for_export(dossier_second_revision.procedure.types_de_champ_for_export)) + context "when procedure brouillon" do + let(:procedure) { create(:procedure, :with_type_de_champ, :with_explication) } + + it "should not contain explication type de champ" do + expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export).map { |(libelle)| libelle }).to eq([text_type_de_champ.libelle]) + end end end From 224c7ec6c331ee135f45038dce3d9ecea458f262 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 23 Mar 2021 10:51:55 +0100 Subject: [PATCH 2/3] Update spec/models/dossier_spec.rb Co-authored-by: Pierre de La Morinerie --- spec/models/dossier_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 8def1471c..179158d6d 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1376,7 +1376,7 @@ describe Dossier do context "when procedure brouillon" do let(:procedure) { create(:procedure, :with_type_de_champ, :with_explication) } - it "should not contain explication type de champ" do + it "should not contain non-exportable types de champ" do expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export).map { |(libelle)| libelle }).to eq([text_type_de_champ.libelle]) end end From 0b22788d600f661d97e78703ea543325693a2127 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 23 Mar 2021 12:25:57 +0100 Subject: [PATCH 3/3] 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