From c618da58a3bc8d7ea347dc674718fa5e7aaf9f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Mon, 16 Oct 2023 14:05:08 +0200 Subject: [PATCH] fix meeting sorter --- app/services/som_energia/meetings/meeting_sort.rb | 2 +- spec/services/meeting_sort_spec.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/services/som_energia/meetings/meeting_sort.rb b/app/services/som_energia/meetings/meeting_sort.rb index 11b59135..e4347a11 100644 --- a/app/services/som_energia/meetings/meeting_sort.rb +++ b/app/services/som_energia/meetings/meeting_sort.rb @@ -20,7 +20,7 @@ def meetings end def new_order - Arel.sql("POSITION(id::text IN '#{sorted_ids.join(",")}')") + Arel.sql("array_position(ARRAY[#{sorted_ids.join(",")}], id::int)") end def sorted_ids diff --git a/spec/services/meeting_sort_spec.rb b/spec/services/meeting_sort_spec.rb index b3536b31..252973c0 100644 --- a/spec/services/meeting_sort_spec.rb +++ b/spec/services/meeting_sort_spec.rb @@ -5,8 +5,9 @@ module SomEnergia::Meetings describe MeetingSort do let(:component) { create(:component, manifest_name: "meetings") } - let(:upcoming_meeting_1) { create(:meeting, :upcoming, component: component, start_time: 1.year.from_now) } + let(:upcoming_meeting_1) { create(:meeting, :upcoming, id: past_meeting_1.id * 10, component: component, start_time: 1.year.from_now) } let(:upcoming_meeting_2) { create(:meeting, :upcoming, component: component, start_time: 2.years.from_now) } + let(:upcoming_meeting_3) { create(:meeting, :upcoming, id: past_meeting_2.id * 10, component: component, start_time: 1.day.ago, end_time: 1.day.from_now) } let(:past_meeting_1) { create(:meeting, :past, component: component, start_time: 1.year.ago) } let(:past_meeting_2) { create(:meeting, :past, component: component, start_time: 2.years.ago) } let(:meetings) do @@ -14,6 +15,7 @@ module SomEnergia::Meetings past_meeting_2, upcoming_meeting_2, past_meeting_1, + upcoming_meeting_3, upcoming_meeting_1 ] end @@ -25,6 +27,7 @@ module SomEnergia::Meetings let(:expected_ids) { expected_meetings.map(&:id) } let(:expected_meetings) do [ + upcoming_meeting_3, upcoming_meeting_1, upcoming_meeting_2, past_meeting_1,