Merge branch '45065-users-projects-json-sort' into 'master'

UsersController#projects.json sort order

Closes #45065

See merge request gitlab-org/gitlab-ce!18227
This commit is contained in:
Rémy Coutable 2018-05-21 08:27:36 +00:00
commit cf7f3606d3
4 changed files with 17 additions and 10 deletions

View File

@ -13,7 +13,7 @@ class PersonalProjectsFinder < UnionFinder
def execute(current_user = nil)
segments = all_projects(current_user)
find_union(segments, Project).includes(:namespace).order_id_desc
find_union(segments, Project).includes(:namespace).order_updated_desc
end
private

View File

@ -0,0 +1,5 @@
---
title: Order UsersController#projects.json by updated_at
merge_request: 18227
author: Takuya Noguchi
type: other

View File

@ -27,8 +27,8 @@ describe 'Users > User browses projects on user page', :js do
end
it 'paginates projects', :js do
project = create(:project, namespace: user.namespace)
project2 = create(:project, namespace: user.namespace)
project = create(:project, namespace: user.namespace, updated_at: 2.minutes.since)
project2 = create(:project, namespace: user.namespace, updated_at: 1.minute.since)
allow(Project).to receive(:default_per_page).and_return(1)
sign_in(user)
@ -41,11 +41,11 @@ describe 'Users > User browses projects on user page', :js do
wait_for_requests
expect(page).to have_content(project2.name)
expect(page).to have_content(project.name)
click_link('Next')
expect(page).to have_content(project.name)
expect(page).to have_content(project2.name)
end
context 'when not signed in' do

View File

@ -4,14 +4,16 @@ describe PersonalProjectsFinder do
let(:source_user) { create(:user) }
let(:current_user) { create(:user) }
let(:finder) { described_class.new(source_user) }
let!(:public_project) { create(:project, :public, namespace: source_user.namespace) }
let!(:public_project) do
create(:project, :public, namespace: source_user.namespace, updated_at: 1.hour.ago)
end
let!(:private_project) do
create(:project, :private, namespace: source_user.namespace, path: 'mepmep')
create(:project, :private, namespace: source_user.namespace, updated_at: 3.hours.ago, path: 'mepmep')
end
let!(:internal_project) do
create(:project, :internal, namespace: source_user.namespace, path: 'C')
create(:project, :internal, namespace: source_user.namespace, updated_at: 2.hours.ago, path: 'C')
end
before do
@ -28,7 +30,7 @@ describe PersonalProjectsFinder do
subject { finder.execute(current_user) }
context 'normal user' do
it { is_expected.to eq([internal_project, private_project, public_project]) }
it { is_expected.to eq([public_project, internal_project, private_project]) }
end
context 'external' do
@ -36,7 +38,7 @@ describe PersonalProjectsFinder do
current_user.update_attributes(external: true)
end
it { is_expected.to eq([private_project, public_project]) }
it { is_expected.to eq([public_project, private_project]) }
end
end
end