Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Order sections by name without prefix, (#523)
- Loading branch information
1 parent
3aa05d3
commit f381f2d
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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_sac_cas | ||
|
||
module SacCas::Sheet::Group::NavLeft | ||
NAME_WITHOUT_PREFIX = "REPLACE(REPLACE(name, 'SAC ', ''), 'CAS ', '')".freeze | ||
|
||
private | ||
|
||
def sub_layers | ||
return super unless @entry.root? | ||
|
||
super.reorder(Arel.sql(NAME_WITHOUT_PREFIX)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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_sac_cas | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Sheet::Group::NavLeft' do | ||
let(:group) { groups(:root) } | ||
let(:sheet) { Sheet::Group.new(self, nil, group) } | ||
let(:nav) { Sheet::Group::NavLeft.new(sheet) } | ||
|
||
let(:request) { ActionController::TestRequest.create({}) } | ||
|
||
let(:html) { nav.render } | ||
subject(:dom) { Capybara::Node::Simple.new(html) } | ||
|
||
def can?(*_args) | ||
true | ||
end | ||
|
||
describe 'ordering of sections' do | ||
let(:links) { dom.all('li').map(&:text) } | ||
let(:sections) { links[links.index('Sektionen')+1..] } | ||
let(:bluemlisalp) { groups(:bluemlisalp) } | ||
let(:matterhorn) { groups(:matterhorn) } | ||
|
||
it 'orders sections by name' do | ||
expect(sections).to eq ['SAC Blüemlisalp', 'SAC Matterhorn'] | ||
end | ||
|
||
it 'ignores cas prefix' do | ||
matterhorn.update!(name: 'CAS Matterhorn') | ||
expect(sections).to eq ['SAC Blüemlisalp', 'CAS Matterhorn'] | ||
end | ||
|
||
it 'ignores sac prefix' do | ||
bluemlisalp.update!(name: 'CAS Blüemlisalp') | ||
matterhorn.update!(name: 'SAC Altels') | ||
expect(sections).to eq ['SAC Altels', 'CAS Blüemlisalp'] | ||
end | ||
end | ||
end |