Skip to content

Commit

Permalink
Remove NULLS LAST from sort mappings (#156)
Browse files Browse the repository at this point in the history
* Remove NULLS LAST from sort mappings

* Add specs
  • Loading branch information
njaeggi authored Nov 25, 2024
1 parent e2d12cb commit 68810a5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/jubla/event/participations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module Jubla::Event::ParticipationsController
# and aliases the table name for the second association (states)
prepended do
sort_mappings_with_indifferent_access
.merge!(originating_state: "originating_states_people.name NULLS LAST",
originating_flock: "groups.name NULLS LAST")
.merge!(originating_state: "originating_states_people.name",
originating_flock: "groups.name")
end

def list_entries
Expand Down
58 changes: 58 additions & 0 deletions spec/regressions/event/participations_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) 2012-2014, Jungwacht Blauring Schweiz. This file is part of
# hitobito_jubla and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_jubla.

require 'spec_helper'

describe Event::ParticipationsController, type: :controller do
let(:event) do
event = Fabricate(:jubla_course, kind: Event::Kind.where(short_name: 'SLK').first)
event.dates.create!(start_at: 10.days.ago, finish_at: 5.days.ago)
event
end
let(:group) { event.groups.first }
let(:participant_1) do
participation = Fabricate(:event_participation, event: event)
Fabricate(Event::Course::Role::Participant.name.to_sym, participation: participation)
participation
end
let(:participant_2) do
participation = Fabricate(:event_participation, event: event)
Fabricate(Event::Course::Role::Participant.name.to_sym, participation: participation)
participation
end

before { sign_in(people(:top_leader)) }

before do
participant_1
participant_2
end

describe 'GET index' do
it "should be able to sort by originating_state asc" do
get :index, params: { group_id: group.id, event_id: event.id, sort: :originating_state, sort_dir: :asc }
expect(response).to have_http_status(:ok)
expect(assigns(:participations)).to match_array([participant_1, participant_2])
end

it "should be able to sort by originating_state desc" do
get :index, params: { group_id: group.id, event_id: event.id, sort: :originating_state, sort_dir: :desc }
expect(response).to have_http_status(:ok)
expect(assigns(:participations)).to match_array([participant_2, participant_1])
end

it "should be able to sort by originating_flock asc" do
get :index, params: { group_id: group.id, event_id: event.id, sort: :originating_flock, sort_dir: :asc }
expect(response).to have_http_status(:ok)
expect(assigns(:participations)).to match_array([participant_1, participant_2])
end

it "should be able to sort by originating_flock desc" do
get :index, params: { group_id: group.id, event_id: event.id, sort: :originating_flock, sort_dir: :desc }
expect(response).to have_http_status(:ok)
expect(assigns(:participations)).to match_array([participant_2, participant_1])
end
end
end

0 comments on commit 68810a5

Please sign in to comment.