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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
e8edf620
Commit
e8edf620
authored
Jun 25, 2018
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sorting by name on explore projects page
parent
45453c27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
app/models/concerns/sortable.rb
app/models/concerns/sortable.rb
+2
-2
spec/models/concerns/sortable_spec.rb
spec/models/concerns/sortable_spec.rb
+14
-4
No files found.
app/models/concerns/sortable.rb
View file @
e8edf620
...
@@ -12,8 +12,8 @@ module Sortable
...
@@ -12,8 +12,8 @@ module Sortable
scope
:order_created_asc
,
->
{
reorder
(
created_at: :asc
)
}
scope
:order_created_asc
,
->
{
reorder
(
created_at: :asc
)
}
scope
:order_updated_desc
,
->
{
reorder
(
updated_at: :desc
)
}
scope
:order_updated_desc
,
->
{
reorder
(
updated_at: :desc
)
}
scope
:order_updated_asc
,
->
{
reorder
(
updated_at: :asc
)
}
scope
:order_updated_asc
,
->
{
reorder
(
updated_at: :asc
)
}
scope
:order_name_asc
,
->
{
reorder
(
"lower(name) asc"
)
}
scope
:order_name_asc
,
->
{
reorder
(
Arel
::
Nodes
::
Ascending
.
new
(
arel_table
[
:name
].
lower
)
)
}
scope
:order_name_desc
,
->
{
reorder
(
"lower(name) desc"
)
}
scope
:order_name_desc
,
->
{
reorder
(
Arel
::
Nodes
::
Descending
.
new
(
arel_table
[
:name
].
lower
)
)
}
end
end
module
ClassMethods
module
ClassMethods
...
...
spec/models/concerns/sortable_spec.rb
View file @
e8edf620
...
@@ -40,15 +40,25 @@ describe Sortable do
...
@@ -40,15 +40,25 @@ describe Sortable do
describe
'ordering by name'
do
describe
'ordering by name'
do
it
'ascending'
do
it
'ascending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
"lower(name) asc"
)
expect
(
relation
).
to
receive
(
:reorder
).
once
.
and_call_original
relation
.
order_by
(
'name_asc'
)
table
=
Regexp
.
escape
(
ActiveRecord
::
Base
.
connection
.
quote_table_name
(
:namespaces
))
column
=
Regexp
.
escape
(
ActiveRecord
::
Base
.
connection
.
quote_column_name
(
:name
))
sql
=
relation
.
order_by
(
'name_asc'
).
to_sql
expect
(
sql
).
to
match
/.+ORDER BY LOWER\(
#{
table
}
.
#{
column
}
\) ASC\z/
end
end
it
'descending'
do
it
'descending'
do
expect
(
relation
).
to
receive
(
:reorder
).
with
(
"lower(name) desc"
)
expect
(
relation
).
to
receive
(
:reorder
).
once
.
and_call_original
table
=
Regexp
.
escape
(
ActiveRecord
::
Base
.
connection
.
quote_table_name
(
:namespaces
))
column
=
Regexp
.
escape
(
ActiveRecord
::
Base
.
connection
.
quote_column_name
(
:name
))
sql
=
relation
.
order_by
(
'name_desc'
).
to_sql
relation
.
order_by
(
'name_desc'
)
expect
(
sql
).
to
match
/.+ORDER BY LOWER\(
#{
table
}
.
#{
column
}
\) DESC\z/
end
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