From b62088859774a0960d75717a0755e8aef90466d2 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 20 May 2021 16:15:59 +0200 Subject: [PATCH] show only dossier avis --- app/models/dossier.rb | 2 +- spec/models/dossier_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 0ed94a2bc..d457f2cf7 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -537,7 +537,7 @@ class Dossier < ApplicationRecord def avis_for_expert(expert) Avis .where(dossier_id: id, confidentiel: false) - .or(Avis.where(id: expert.avis)) + .or(Avis.where(id: expert.avis, dossier_id: id)) .order(created_at: :asc) end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 8ae36a3d7..90f76235f 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -363,6 +363,12 @@ describe Dossier do 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]) } end + + context 'when they are a advice published on another dossier' do + let!(:avis) { create(:avis, dossier: create(:dossier, procedure: procedure), claimant: instructeur, experts_procedure: experts_procedure, confidentiel: false, created_at: Time.zone.parse('9/01/2010')) } + + it { expect(dossier.avis_for_expert(expert_1)).to match([]) } + end end describe '#update_state_dates' do