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
b11c218a
Commit
b11c218a
authored
May 17, 2018
by
Harish Ved
Committed by
Rémy Coutable
May 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: Use case in-sensitive ordering by name for groups
parent
47555ef8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
149 additions
and
2 deletions
+149
-2
app/models/concerns/sortable.rb
app/models/concerns/sortable.rb
+2
-2
changelogs/unreleased/use-case-insensitive-ordering-for-dashboard-filters.yml
...d/use-case-insensitive-ordering-for-dashboard-filters.yml
+5
-0
db/migrate/20180504195842_project_name_lower_index.rb
db/migrate/20180504195842_project_name_lower_index.rb
+32
-0
lib/tasks/migrate/setup_postgresql.rake
lib/tasks/migrate/setup_postgresql.rake
+2
-0
spec/models/concerns/sortable_spec.rb
spec/models/concerns/sortable_spec.rb
+108
-0
No files found.
app/models/concerns/sortable.rb
View file @
b11c218a
...
...
@@ -12,8 +12,8 @@ module Sortable
scope
:order_created_asc
,
->
{
reorder
(
created_at: :asc
)
}
scope
:order_updated_desc
,
->
{
reorder
(
updated_at: :desc
)
}
scope
:order_updated_asc
,
->
{
reorder
(
updated_at: :asc
)
}
scope
:order_name_asc
,
->
{
reorder
(
name: :asc
)
}
scope
:order_name_desc
,
->
{
reorder
(
name: :desc
)
}
scope
:order_name_asc
,
->
{
reorder
(
"lower(name) asc"
)
}
scope
:order_name_desc
,
->
{
reorder
(
"lower(name) desc"
)
}
end
module
ClassMethods
...
...
changelogs/unreleased/use-case-insensitive-ordering-for-dashboard-filters.yml
0 → 100644
View file @
b11c218a
---
title
:
"
Use
case
in-sensitive
ordering
by
name
for
dashboard"
merge_request
:
18553
author
:
"
@vedharish"
type
:
fixed
db/migrate/20180504195842_project_name_lower_index.rb
0 → 100644
View file @
b11c218a
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
ProjectNameLowerIndex
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
INDEX_NAME
=
'index_projects_on_lower_name'
disable_ddl_transaction!
def
up
return
unless
Gitlab
::
Database
.
postgresql?
disable_statement_timeout
execute
"CREATE INDEX CONCURRENTLY
#{
INDEX_NAME
}
ON projects (LOWER(name))"
end
def
down
return
unless
Gitlab
::
Database
.
postgresql?
disable_statement_timeout
if
supports_drop_index_concurrently?
execute
"DROP INDEX CONCURRENTLY IF EXISTS
#{
INDEX_NAME
}
"
else
execute
"DROP INDEX IF EXISTS
#{
INDEX_NAME
}
"
end
end
end
lib/tasks/migrate/setup_postgresql.rake
View file @
b11c218a
...
...
@@ -8,6 +8,7 @@ task setup_postgresql: :environment do
require
Rails
.
root
.
join
(
'db/migrate/20170503185032_index_redirect_routes_path_for_like'
)
require
Rails
.
root
.
join
(
'db/migrate/20171220191323_add_index_on_namespaces_lower_name.rb'
)
require
Rails
.
root
.
join
(
'db/migrate/20180215181245_users_name_lower_index.rb'
)
require
Rails
.
root
.
join
(
'db/migrate/20180504195842_project_name_lower_index.rb'
)
require
Rails
.
root
.
join
(
'db/post_migrate/20180306164012_add_path_index_to_redirect_routes.rb'
)
NamespacesProjectsPathLowerIndexes
.
new
.
up
...
...
@@ -18,5 +19,6 @@ task setup_postgresql: :environment do
IndexRedirectRoutesPathForLike
.
new
.
up
AddIndexOnNamespacesLowerName
.
new
.
up
UsersNameLowerIndex
.
new
.
up
ProjectNameLowerIndex
.
new
.
up
AddPathIndexToRedirectRoutes
.
new
.
up
end
spec/models/concerns/sortable_spec.rb
0 → 100644
View file @
b11c218a
require
'spec_helper'
describe
Sortable
do
describe
'.order_by'
do
let
(
:relation
)
{
Group
.
all
}
describe
'ordering by id'
do
it
'ascending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
id: :asc
)
relation
.
order_by
(
'id_asc'
)
end
it
'descending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
id: :desc
)
relation
.
order_by
(
'id_desc'
)
end
end
describe
'ordering by created day'
do
it
'ascending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
created_at: :asc
)
relation
.
order_by
(
'created_asc'
)
end
it
'descending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
created_at: :desc
)
relation
.
order_by
(
'created_desc'
)
end
it
'order by "date"'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
created_at: :desc
)
relation
.
order_by
(
'created_date'
)
end
end
describe
'ordering by name'
do
it
'ascending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
"lower(name) asc"
)
relation
.
order_by
(
'name_asc'
)
end
it
'descending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
"lower(name) desc"
)
relation
.
order_by
(
'name_desc'
)
end
end
describe
'ordering by Updated Time'
do
it
'ascending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
updated_at: :asc
)
relation
.
order_by
(
'updated_asc'
)
end
it
'descending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
updated_at: :desc
)
relation
.
order_by
(
'updated_desc'
)
end
end
it
'does not call reorder in case of unrecognized ordering'
do
expect
(
relation
).
not_to
receive
(
:reorder
)
relation
.
order_by
(
'random_ordering'
)
end
end
describe
'sorting groups'
do
def
ordered_group_names
(
order
)
Group
.
all
.
order_by
(
order
).
map
(
&
:name
)
end
let!
(
:ref_time
)
{
Time
.
parse
(
'2018-05-01 00:00:00'
)
}
let!
(
:group1
)
{
create
(
:group
,
name:
'aa'
,
id:
1
,
created_at:
ref_time
-
15
.
seconds
,
updated_at:
ref_time
)
}
let!
(
:group2
)
{
create
(
:group
,
name:
'AAA'
,
id:
2
,
created_at:
ref_time
-
10
.
seconds
,
updated_at:
ref_time
-
5
.
seconds
)
}
let!
(
:group3
)
{
create
(
:group
,
name:
'BB'
,
id:
3
,
created_at:
ref_time
-
5
.
seconds
,
updated_at:
ref_time
-
10
.
seconds
)
}
let!
(
:group4
)
{
create
(
:group
,
name:
'bbb'
,
id:
4
,
created_at:
ref_time
,
updated_at:
ref_time
-
15
.
seconds
)
}
it
'sorts groups by id'
do
expect
(
ordered_group_names
(
'id_asc'
)).
to
eq
(
%w(aa AAA BB bbb)
)
expect
(
ordered_group_names
(
'id_desc'
)).
to
eq
(
%w(bbb BB AAA aa)
)
end
it
'sorts groups by name via case-insentitive comparision'
do
expect
(
ordered_group_names
(
'name_asc'
)).
to
eq
(
%w(aa AAA BB bbb)
)
expect
(
ordered_group_names
(
'name_desc'
)).
to
eq
(
%w(bbb BB AAA aa)
)
end
it
'sorts groups by created_at'
do
expect
(
ordered_group_names
(
'created_asc'
)).
to
eq
(
%w(aa AAA BB bbb)
)
expect
(
ordered_group_names
(
'created_desc'
)).
to
eq
(
%w(bbb BB AAA aa)
)
expect
(
ordered_group_names
(
'created_date'
)).
to
eq
(
%w(bbb BB AAA aa)
)
end
it
'sorts groups by updated_at'
do
expect
(
ordered_group_names
(
'updated_asc'
)).
to
eq
(
%w(bbb BB AAA aa)
)
expect
(
ordered_group_names
(
'updated_desc'
)).
to
eq
(
%w(aa AAA BB bbb)
)
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