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
3d3b46f3
Commit
3d3b46f3
authored
Apr 04, 2018
by
blackst0ne
Committed by
Sean McGivern
Apr 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Rails5] Rename `sort` methods to `sort_by_attribute`
parent
e9ea5208
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
35 additions
and
35 deletions
+35
-35
app/controllers/admin/groups_controller.rb
app/controllers/admin/groups_controller.rb
+1
-1
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+1
-1
app/controllers/concerns/group_tree.rb
app/controllers/concerns/group_tree.rb
+1
-1
app/controllers/groups/group_members_controller.rb
app/controllers/groups/group_members_controller.rb
+1
-1
app/controllers/projects/milestones_controller.rb
app/controllers/projects/milestones_controller.rb
+1
-1
app/controllers/projects/project_members_controller.rb
app/controllers/projects/project_members_controller.rb
+1
-1
app/finders/admin/projects_finder.rb
app/finders/admin/projects_finder.rb
+1
-1
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+1
-1
app/finders/projects_finder.rb
app/finders/projects_finder.rb
+1
-1
app/finders/todos_finder.rb
app/finders/todos_finder.rb
+1
-1
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+1
-1
app/models/concerns/milestoneish.rb
app/models/concerns/milestoneish.rb
+2
-2
app/models/group.rb
app/models/group.rb
+1
-1
app/models/issue.rb
app/models/issue.rb
+1
-1
app/models/member.rb
app/models/member.rb
+1
-1
app/models/milestone.rb
app/models/milestone.rb
+1
-1
app/models/project.rb
app/models/project.rb
+1
-1
app/models/todo.rb
app/models/todo.rb
+1
-1
app/models/user.rb
app/models/user.rb
+1
-1
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+4
-4
spec/models/user_spec.rb
spec/models/user_spec.rb
+6
-6
spec/requests/projects/cycle_analytics_events_spec.rb
spec/requests/projects/cycle_analytics_events_spec.rb
+5
-5
No files found.
app/controllers/admin/groups_controller.rb
View file @
3d3b46f3
...
...
@@ -5,7 +5,7 @@ class Admin::GroupsController < Admin::ApplicationController
def
index
@groups
=
Group
.
with_statistics
.
with_route
@groups
=
@groups
.
sort
(
@sort
=
params
[
:sort
])
@groups
=
@groups
.
sort
_by_attribute
(
@sort
=
params
[
:sort
])
@groups
=
@groups
.
search
(
params
[
:name
])
if
params
[
:name
].
present?
@groups
=
@groups
.
page
(
params
[
:page
])
end
...
...
app/controllers/admin/users_controller.rb
View file @
3d3b46f3
...
...
@@ -4,7 +4,7 @@ class Admin::UsersController < Admin::ApplicationController
def
index
@users
=
User
.
order_name_asc
.
filter
(
params
[
:filter
])
@users
=
@users
.
search_with_secondary_emails
(
params
[
:search_query
])
if
params
[
:search_query
].
present?
@users
=
@users
.
sort
(
@sort
=
params
[
:sort
])
@users
=
@users
.
sort
_by_attribute
(
@sort
=
params
[
:sort
])
@users
=
@users
.
page
(
params
[
:page
])
end
...
...
app/controllers/concerns/group_tree.rb
View file @
3d3b46f3
...
...
@@ -14,7 +14,7 @@ module GroupTree
end
@groups
=
@groups
.
with_selects_for_list
(
archived:
params
[
:archived
])
.
sort
(
@sort
=
params
[
:sort
])
.
sort
_by_attribute
(
@sort
=
params
[
:sort
])
.
page
(
params
[
:page
])
respond_to
do
|
format
|
...
...
app/controllers/groups/group_members_controller.rb
View file @
3d3b46f3
...
...
@@ -17,7 +17,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
@members
=
GroupMembersFinder
.
new
(
@group
).
execute
@members
=
@members
.
non_invite
unless
can?
(
current_user
,
:admin_group
,
@group
)
@members
=
@members
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@members
=
@members
.
sort
(
@sort
)
@members
=
@members
.
sort
_by_attribute
(
@sort
)
@members
=
@members
.
page
(
params
[
:page
]).
per
(
50
)
@members
=
present_members
(
@members
.
includes
(
:user
))
...
...
app/controllers/projects/milestones_controller.rb
View file @
3d3b46f3
...
...
@@ -14,7 +14,7 @@ class Projects::MilestonesController < Projects::ApplicationController
def
index
@sort
=
params
[
:sort
]
||
'due_date_asc'
@milestones
=
milestones
.
sort
(
@sort
)
@milestones
=
milestones
.
sort
_by_attribute
(
@sort
)
respond_to
do
|
format
|
format
.
html
do
...
...
app/controllers/projects/project_members_controller.rb
View file @
3d3b46f3
...
...
@@ -21,7 +21,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
@group_links
=
@group_links
.
where
(
group_id:
@project
.
invited_groups
.
search
(
params
[
:search
]).
select
(
:id
))
end
@project_members
=
present_members
(
@project_members
.
sort
(
@sort
).
page
(
params
[
:page
]))
@project_members
=
present_members
(
@project_members
.
sort
_by_attribute
(
@sort
).
page
(
params
[
:page
]))
@requesters
=
present_members
(
AccessRequestsFinder
.
new
(
@project
).
execute
(
current_user
))
@project_member
=
@project
.
project_members
.
new
end
...
...
app/finders/admin/projects_finder.rb
View file @
3d3b46f3
...
...
@@ -62,6 +62,6 @@ class Admin::ProjectsFinder
def
sort
(
items
)
sort
=
params
.
fetch
(
:sort
)
{
'latest_activity_desc'
}
items
.
sort
(
sort
)
items
.
sort
_by_attribute
(
sort
)
end
end
app/finders/issuable_finder.rb
View file @
3d3b46f3
...
...
@@ -337,7 +337,7 @@ class IssuableFinder
def
sort
(
items
)
# Ensure we always have an explicit sort order (instead of inheriting
# multiple orders when combining ActiveRecord::Relation objects).
params
[
:sort
]
?
items
.
sort
(
params
[
:sort
],
excluded_labels:
label_names
)
:
items
.
reorder
(
id: :desc
)
params
[
:sort
]
?
items
.
sort
_by_attribute
(
params
[
:sort
],
excluded_labels:
label_names
)
:
items
.
reorder
(
id: :desc
)
end
def
by_assignee
(
items
)
...
...
app/finders/projects_finder.rb
View file @
3d3b46f3
...
...
@@ -124,7 +124,7 @@ class ProjectsFinder < UnionFinder
end
def
sort
(
items
)
params
[
:sort
].
present?
?
items
.
sort
(
params
[
:sort
])
:
items
.
order_id_desc
params
[
:sort
].
present?
?
items
.
sort
_by_attribute
(
params
[
:sort
])
:
items
.
order_id_desc
end
def
by_archived
(
projects
)
...
...
app/finders/todos_finder.rb
View file @
3d3b46f3
...
...
@@ -119,7 +119,7 @@ class TodosFinder
end
def
sort
(
items
)
params
[
:sort
]
?
items
.
sort
(
params
[
:sort
])
:
items
.
order_id_desc
params
[
:sort
]
?
items
.
sort
_by_attribute
(
params
[
:sort
])
:
items
.
order_id_desc
end
def
by_action
(
items
)
...
...
app/models/concerns/issuable.rb
View file @
3d3b46f3
...
...
@@ -137,7 +137,7 @@ module Issuable
fuzzy_search
(
query
,
[
:title
,
:description
])
end
def
sort
(
method
,
excluded_labels:
[])
def
sort
_by_attribute
(
method
,
excluded_labels:
[])
sorted
=
case
method
.
to_s
when
'downvotes_desc'
then
order_downvotes_desc
...
...
app/models/concerns/milestoneish.rb
View file @
3d3b46f3
...
...
@@ -45,11 +45,11 @@ module Milestoneish
end
def
sorted_issues
(
user
)
issues_visible_to_user
(
user
).
preload_associations
.
sort
(
'label_priority'
)
issues_visible_to_user
(
user
).
preload_associations
.
sort
_by_attribute
(
'label_priority'
)
end
def
sorted_merge_requests
merge_requests
.
sort
(
'label_priority'
)
merge_requests
.
sort
_by_attribute
(
'label_priority'
)
end
def
upcoming?
...
...
app/models/group.rb
View file @
3d3b46f3
...
...
@@ -53,7 +53,7 @@ class Group < Namespace
Gitlab
::
Database
.
postgresql?
end
def
sort
(
method
)
def
sort
_by_attribute
(
method
)
if
method
==
'storage_size_desc'
# storage_size is a virtual column so we need to
# pass a string to avoid AR adding the table name
...
...
app/models/issue.rb
View file @
3d3b46f3
...
...
@@ -116,7 +116,7 @@ class Issue < ActiveRecord::Base
'project_id'
end
def
self
.
sort
(
method
,
excluded_labels:
[])
def
self
.
sort
_by_attribute
(
method
,
excluded_labels:
[])
case
method
.
to_s
when
'due_date'
then
order_due_date_asc
when
'due_date_asc'
then
order_due_date_asc
...
...
app/models/member.rb
View file @
3d3b46f3
...
...
@@ -96,7 +96,7 @@ class Member < ActiveRecord::Base
joins
(
:user
).
merge
(
User
.
search
(
query
))
end
def
sort
(
method
)
def
sort
_by_attribute
(
method
)
case
method
.
to_s
when
'access_level_asc'
then
reorder
(
access_level: :asc
)
when
'access_level_desc'
then
reorder
(
access_level: :desc
)
...
...
app/models/milestone.rb
View file @
3d3b46f3
...
...
@@ -138,7 +138,7 @@ class Milestone < ActiveRecord::Base
User
.
joins
(
assigned_issues: :milestone
).
where
(
"milestones.id = ?"
,
id
).
uniq
end
def
self
.
sort
(
method
)
def
self
.
sort
_by_attribute
(
method
)
case
method
.
to_s
when
'due_date_asc'
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'due_date'
,
'ASC'
))
...
...
app/models/project.rb
View file @
3d3b46f3
...
...
@@ -436,7 +436,7 @@ class Project < ActiveRecord::Base
Gitlab
::
VisibilityLevel
.
options
end
def
sort
(
method
)
def
sort
_by_attribute
(
method
)
case
method
.
to_s
when
'storage_size_desc'
# storage_size is a joined column so we need to
...
...
app/models/todo.rb
View file @
3d3b46f3
...
...
@@ -50,7 +50,7 @@ class Todo < ActiveRecord::Base
# Priority sorting isn't displayed in the dropdown, because we don't show
# milestones, but still show something if the user has a URL with that
# selected.
def
sort
(
method
)
def
sort
_by_attribute
(
method
)
sorted
=
case
method
.
to_s
when
'priority'
,
'label_priority'
then
order_by_labels_priority
...
...
app/models/user.rb
View file @
3d3b46f3
...
...
@@ -256,7 +256,7 @@ class User < ActiveRecord::Base
end
end
def
sort
(
method
)
def
sort
_by_attribute
(
method
)
order_method
=
method
||
'id_desc'
case
order_method
.
to_s
...
...
spec/models/concerns/issuable_spec.rb
View file @
3d3b46f3
...
...
@@ -176,7 +176,7 @@ describe Issuable do
end
end
describe
"#sort"
do
describe
"#sort
_by_attribute
"
do
let
(
:project
)
{
create
(
:project
)
}
context
"by milestone due date"
do
...
...
@@ -193,12 +193,12 @@ describe Issuable do
let!
(
:issue3
)
{
create
(
:issue
,
project:
project
)
}
it
"sorts desc"
do
issues
=
project
.
issues
.
sort
(
'milestone_due_desc'
)
issues
=
project
.
issues
.
sort
_by_attribute
(
'milestone_due_desc'
)
expect
(
issues
).
to
match_array
([
issue2
,
issue1
,
issue
,
issue3
])
end
it
"sorts asc"
do
issues
=
project
.
issues
.
sort
(
'milestone_due_asc'
)
issues
=
project
.
issues
.
sort
_by_attribute
(
'milestone_due_asc'
)
expect
(
issues
).
to
match_array
([
issue1
,
issue2
,
issue
,
issue3
])
end
end
...
...
@@ -210,7 +210,7 @@ describe Issuable do
it
'has no duplicates across pages'
do
sorted_issue_ids
=
1
.
upto
(
10
).
map
do
|
i
|
project
.
issues
.
sort
(
'milestone_due_desc'
).
page
(
i
).
per
(
1
).
first
.
id
project
.
issues
.
sort
_by_attribute
(
'milestone_due_desc'
).
page
(
i
).
per
(
1
).
first
.
id
end
expect
(
sorted_issue_ids
).
to
eq
(
sorted_issue_ids
.
uniq
)
...
...
spec/models/user_spec.rb
View file @
3d3b46f3
...
...
@@ -1451,7 +1451,7 @@ describe User do
end
end
describe
'#sort'
do
describe
'#sort
_by_attribute
'
do
before
do
described_class
.
delete_all
@user
=
create
:user
,
created_at:
Date
.
today
,
current_sign_in_at:
Date
.
today
,
name:
'Alpha'
...
...
@@ -1460,7 +1460,7 @@ describe User do
end
context
'when sort by recent_sign_in'
do
let
(
:users
)
{
described_class
.
sort
(
'recent_sign_in'
)
}
let
(
:users
)
{
described_class
.
sort
_by_attribute
(
'recent_sign_in'
)
}
it
'sorts users by recent sign-in time'
do
expect
(
users
.
first
).
to
eq
(
@user
)
...
...
@@ -1473,7 +1473,7 @@ describe User do
end
context
'when sort by oldest_sign_in'
do
let
(
:users
)
{
described_class
.
sort
(
'oldest_sign_in'
)
}
let
(
:users
)
{
described_class
.
sort
_by_attribute
(
'oldest_sign_in'
)
}
it
'sorts users by the oldest sign-in time'
do
expect
(
users
.
first
).
to
eq
(
@user1
)
...
...
@@ -1486,15 +1486,15 @@ describe User do
end
it
'sorts users in descending order by their creation time'
do
expect
(
described_class
.
sort
(
'created_desc'
).
first
).
to
eq
(
@user
)
expect
(
described_class
.
sort
_by_attribute
(
'created_desc'
).
first
).
to
eq
(
@user
)
end
it
'sorts users in ascending order by their creation time'
do
expect
(
described_class
.
sort
(
'created_asc'
).
first
).
to
eq
(
@user2
)
expect
(
described_class
.
sort
_by_attribute
(
'created_asc'
).
first
).
to
eq
(
@user2
)
end
it
'sorts users by id in descending order when nil is passed'
do
expect
(
described_class
.
sort
(
nil
).
first
).
to
eq
(
@user2
)
expect
(
described_class
.
sort
_by_attribute
(
nil
).
first
).
to
eq
(
@user2
)
end
end
...
...
spec/requests/projects/cycle_analytics_events_spec.rb
View file @
3d3b46f3
...
...
@@ -23,7 +23,7 @@ describe 'cycle analytics events' do
it
'lists the issue events'
do
get
project_cycle_analytics_issue_path
(
project
,
format: :json
)
first_issue_iid
=
project
.
issues
.
sort
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
first_issue_iid
=
project
.
issues
.
sort
_by_attribute
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'events'
]).
not_to
be_empty
expect
(
json_response
[
'events'
].
first
[
'iid'
]).
to
eq
(
first_issue_iid
)
...
...
@@ -32,7 +32,7 @@ describe 'cycle analytics events' do
it
'lists the plan events'
do
get
project_cycle_analytics_plan_path
(
project
,
format: :json
)
first_mr_short_sha
=
project
.
merge_requests
.
sort
(
:created_asc
).
first
.
commits
.
first
.
short_id
first_mr_short_sha
=
project
.
merge_requests
.
sort
_by_attribute
(
:created_asc
).
first
.
commits
.
first
.
short_id
expect
(
json_response
[
'events'
]).
not_to
be_empty
expect
(
json_response
[
'events'
].
first
[
'short_sha'
]).
to
eq
(
first_mr_short_sha
)
...
...
@@ -43,7 +43,7 @@ describe 'cycle analytics events' do
expect
(
json_response
[
'events'
]).
not_to
be_empty
first_mr_iid
=
project
.
merge_requests
.
sort
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
first_mr_iid
=
project
.
merge_requests
.
sort
_by_attribute
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'events'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
end
...
...
@@ -58,7 +58,7 @@ describe 'cycle analytics events' do
it
'lists the review events'
do
get
project_cycle_analytics_review_path
(
project
,
format: :json
)
first_mr_iid
=
project
.
merge_requests
.
sort
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
first_mr_iid
=
project
.
merge_requests
.
sort
_by_attribute
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'events'
]).
not_to
be_empty
expect
(
json_response
[
'events'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
...
...
@@ -74,7 +74,7 @@ describe 'cycle analytics events' do
it
'lists the production events'
do
get
project_cycle_analytics_production_path
(
project
,
format: :json
)
first_issue_iid
=
project
.
issues
.
sort
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
first_issue_iid
=
project
.
issues
.
sort
_by_attribute
(
:created_desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'events'
]).
not_to
be_empty
expect
(
json_response
[
'events'
].
first
[
'iid'
]).
to
eq
(
first_issue_iid
)
...
...
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