From 64cb231b0126369e3abe0a1cbecc693391d44f92 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Tue, 23 Oct 2018 18:48:05 +0200 Subject: [PATCH] [#2675] Fix notification sort order --- app/models/procedure_presentation.rb | 2 +- spec/models/procedure_presentation_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 03b75eefe..34ddbdf42 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -78,7 +78,7 @@ class ProcedurePresentation < ApplicationRecord case table when 'notifications' - dossiers_id_with_notification = gestionnaire.notifications_for_procedure(procedure) + dossiers_id_with_notification = gestionnaire.dossiers_id_with_notifications(dossiers) if order == 'desc' return dossiers_id_with_notification + (dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification) diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index d4951f386..3881f7616 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -238,6 +238,7 @@ describe ProcedurePresentation do before do notified_dossier.champs.first.touch(time: DateTime.new(2018, 9, 20)) create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: DateTime.new(2018, 9, 10)) + notified_dossier.touch(time: DateTime.new(2018, 9, 20)) recent_dossier.touch(time: DateTime.new(2018, 9, 25)) older_dossier.touch(time: DateTime.new(2018, 5, 13)) end @@ -253,6 +254,13 @@ describe ProcedurePresentation do it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) } end + + context 'with a dossier terminé' do + let!(:notified_dossier) { create(:dossier, :accepte, procedure: procedure) } + let(:order) { 'desc' } + + it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) } + end end context 'for self table' do