Commit 1cd4804e authored by blackst0ne's avatar blackst0ne Committed by Sean McGivern
Browse files

[Rails5] Rename `sort` methods to `sort_by_attribute`

parent 2cbbf4538ba8
......@@ -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
......
......@@ -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
......
......@@ -14,7 +14,7 @@ def render_group_tree(groups)
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|
......
......@@ -17,7 +17,7 @@ def index
@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))
......
......@@ -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
......
......@@ -21,7 +21,7 @@ def index
@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
......
......@@ -62,6 +62,6 @@ def by_name(items)
def sort(items)
sort = params.fetch(:sort) { 'latest_activity_desc' }
items.sort(sort)
items.sort_by_attribute(sort)
end
end
......@@ -337,7 +337,7 @@ def by_iids(items)
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)
......
......@@ -124,7 +124,7 @@ def by_search(items)
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)
......
......@@ -119,7 +119,7 @@ def type
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)
......
......@@ -137,7 +137,7 @@ def full_search(query)
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
......
......@@ -45,11 +45,11 @@ def issues_visible_to_user(user)
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?
......
......@@ -53,7 +53,7 @@ def supports_nested_groups?
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
......
......@@ -116,7 +116,7 @@ def self.project_foreign_key
'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
......
......@@ -96,7 +96,7 @@ def search(query)
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)
......
......@@ -138,7 +138,7 @@ def participants
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'))
......
......@@ -436,7 +436,7 @@ def visibility_levels
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
......
......@@ -50,7 +50,7 @@ class << self
# 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
......
......@@ -256,7 +256,7 @@ def find_for_database_authentication(warden_conditions)
end
end
def sort(method)
def sort_by_attribute(method)
order_method = method || 'id_desc'
case order_method.to_s
......
......@@ -176,7 +176,7 @@
end
end
describe "#sort" do
describe "#sort_by_attribute" do
let(:project) { create(:project) }
context "by milestone due date" do
......@@ -193,12 +193,12 @@
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 @@
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment