Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
294a7899
Commit
294a7899
authored
Feb 06, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort boards by ascending id
as well as case-insensitive name, to ensure we get a consistent ordering
parent
9da4a6d5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
11 deletions
+22
-11
app/models/board.rb
app/models/board.rb
+4
-1
changelogs/unreleased/bw-fix-board-sorting.yml
changelogs/unreleased/bw-fix-board-sorting.yml
+5
-0
spec/models/board_spec.rb
spec/models/board_spec.rb
+13
-10
No files found.
app/models/board.rb
View file @
294a7899
...
...
@@ -11,7 +11,10 @@ class Board < ApplicationRecord
validates
:group
,
presence:
true
,
unless: :project
scope
:with_associations
,
->
{
preload
(
:destroyable_lists
)
}
scope
:order_by_name_asc
,
->
{
order
(
arel_table
[
:name
].
lower
.
asc
)
}
# Sort by case-insensitive name, then ascending ids. This ensures that we will always
# get the same list/first board no matter how many other boards are named the same
scope
:order_by_name_asc
,
->
{
order
(
arel_table
[
:name
].
lower
.
asc
).
order
(
id: :asc
)
}
scope
:first_board
,
->
{
where
(
id:
self
.
order_by_name_asc
.
limit
(
1
).
select
(
:id
))
}
def
project_needed?
...
...
changelogs/unreleased/bw-fix-board-sorting.yml
0 → 100644
View file @
294a7899
---
title
:
Ensure board lists are sorted consistently
merge_request
:
24637
author
:
type
:
fixed
spec/models/board_spec.rb
View file @
294a7899
...
...
@@ -16,26 +16,29 @@ describe Board do
end
describe
'#order_by_name_asc'
do
let!
(
:second_board
)
{
create
(
:board
,
name:
'Secondary board'
,
project:
project
)
}
let!
(
:first_board
)
{
create
(
:board
,
name:
'First board'
,
project:
project
)
}
let!
(
:board_B
)
{
create
(
:board
,
project:
project
,
name:
'B'
)
}
let!
(
:board_C
)
{
create
(
:board
,
project:
project
,
name:
'C'
)
}
let!
(
:board_a
)
{
create
(
:board
,
project:
project
,
name:
'a'
)
}
let!
(
:board_A
)
{
create
(
:board
,
project:
project
,
name:
'A'
)
}
it
'returns in
alphabetical order
'
do
expect
(
project
.
boards
.
order_by_name_asc
).
to
eq
[
first_board
,
second_board
]
it
'returns in
case-insensitive alphabetical order and then by ascending id
'
do
expect
(
project
.
boards
.
order_by_name_asc
).
to
eq
[
board_a
,
board_A
,
board_B
,
board_C
]
end
end
describe
'#first_board'
do
let!
(
:other_board
)
{
create
(
:board
,
name:
'Other board'
,
project:
other_project
)
}
let!
(
:second_board
)
{
create
(
:board
,
name:
'Secondary board'
,
project:
project
)
}
let!
(
:first_board
)
{
create
(
:board
,
name:
'First board'
,
project:
project
)
}
let!
(
:board_B
)
{
create
(
:board
,
project:
project
,
name:
'B'
)
}
let!
(
:board_C
)
{
create
(
:board
,
project:
project
,
name:
'C'
)
}
let!
(
:board_a
)
{
create
(
:board
,
project:
project
,
name:
'a'
)
}
let!
(
:board_A
)
{
create
(
:board
,
project:
project
,
name:
'A'
)
}
it
'return the first alphabetical board as a relation'
do
expect
(
project
.
boards
.
first_board
).
to
eq
[
first_board
]
it
'return the first
case-insensitive
alphabetical board as a relation'
do
expect
(
project
.
boards
.
first_board
).
to
eq
[
board_a
]
end
# BoardsActions#board expects this behavior
it
'raises an error when find is done on a non-existent record'
do
expect
{
project
.
boards
.
first_board
.
find
(
second_board
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
project
.
boards
.
first_board
.
find
(
board_A
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment