Commit d8e07ea5 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'sort-move-projects' into 'master'

Sort move issue projects dropdown by star count

See merge request gitlab-org/gitlab!29766
parents 3e5a1f48 6d59a7a3
......@@ -28,7 +28,8 @@ module Autocomplete
.optionally_search(search, include_namespace: true)
.excluding_project(project_id)
.eager_load_namespace_and_owner
.sorted_by_name_asc_limited(LIMIT)
.sorted_by_stars_desc
.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end
end
end
......@@ -415,7 +415,6 @@ class Project < ApplicationRecord
scope :sorted_by_activity, -> { reorder(Arel.sql("GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC")) }
scope :sorted_by_stars_desc, -> { reorder(self.arel_table['star_count'].desc) }
scope :sorted_by_stars_asc, -> { reorder(self.arel_table['star_count'].asc) }
scope :sorted_by_name_asc_limited, ->(limit) { reorder(name: :asc).limit(limit) }
# Sometimes queries (e.g. using CTEs) require explicit disambiguation with table name
scope :projects_order_id_desc, -> { reorder(self.arel_table['id'].desc) }
......
---
title: Sort the project dropdown by star count when moving issues
merge_request: 29766
author:
type: changed
......@@ -62,19 +62,20 @@ describe Autocomplete::MoveToProjectFinder do
expect(finder.execute.to_a).to eq([other_reporter_project])
end
it 'returns a page of projects ordered by name' do
it 'returns a page of projects ordered by star count' do
stub_const('Autocomplete::MoveToProjectFinder::LIMIT', 2)
projects = create_list(:project, 3) do |project|
project.add_developer(user)
end
projects = [
create(:project, namespace: user.namespace, star_count: 1),
create(:project, namespace: user.namespace, star_count: 5),
create(:project, namespace: user.namespace)
]
finder = described_class.new(user, project_id: project.id)
page = finder.execute.to_a
expected_projects = projects.sort_by(&:name).first(2)
expect(page.length).to eq(2)
expect(page).to eq(expected_projects)
expect(page).to eq([projects[1], projects[0]])
end
end
......
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