Skip to content

Commit

Permalink
fix meeting sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Oct 16, 2023
1 parent 9076d66 commit c618da5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/services/som_energia/meetings/meeting_sort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/services/meeting_sort_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
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
[
past_meeting_2,
upcoming_meeting_2,
past_meeting_1,
upcoming_meeting_3,
upcoming_meeting_1
]
end
Expand All @@ -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,
Expand Down

0 comments on commit c618da5

Please sign in to comment.