summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-01-26 20:36:31 +0000
committerRobert Speicher <rspeicher@gmail.com>2017-01-27 14:14:22 -0500
commit0de388898e460a433d89d0fc42d5d4454396fe3e (patch)
treeaa907cd3783cfa7e5263b930a237443a239e9b40
parentba6641c754b8b5f2b9c9cbc882f020d867e5ec58 (diff)
downloadgitlab-ce-0de388898e460a433d89d0fc42d5d4454396fe3e.tar.gz
Merge branch '27044-fix-explore-sorting-on-trending' into 'master'
Fix /explore sorting (trending) Closes #27044 See merge request !8792
-rw-r--r--app/controllers/explore/projects_controller.rb1
-rw-r--r--changelogs/unreleased/27044-fix-explore-sorting-on-trending.yml4
-rw-r--r--spec/controllers/explore/projects_controller_spec.rb30
-rw-r--r--spec/factories/trending_project.rb6
4 files changed, 41 insertions, 0 deletions
diff --git a/app/controllers/explore/projects_controller.rb b/app/controllers/explore/projects_controller.rb
index a62c6211372..26e17a7553e 100644
--- a/app/controllers/explore/projects_controller.rb
+++ b/app/controllers/explore/projects_controller.rb
@@ -22,6 +22,7 @@ class Explore::ProjectsController < Explore::ApplicationController
def trending
@projects = filter_projects(Project.trending)
+ @projects = @projects.sort(@sort = params[:sort])
@projects = @projects.page(params[:page])
respond_to do |format|
diff --git a/changelogs/unreleased/27044-fix-explore-sorting-on-trending.yml b/changelogs/unreleased/27044-fix-explore-sorting-on-trending.yml
new file mode 100644
index 00000000000..0f0a8940f72
--- /dev/null
+++ b/changelogs/unreleased/27044-fix-explore-sorting-on-trending.yml
@@ -0,0 +1,4 @@
+---
+title: Fix /explore sorting
+merge_request:
+author:
diff --git a/spec/controllers/explore/projects_controller_spec.rb b/spec/controllers/explore/projects_controller_spec.rb
new file mode 100644
index 00000000000..6128091f543
--- /dev/null
+++ b/spec/controllers/explore/projects_controller_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe Explore::ProjectsController do
+ let(:user) { create(:user) }
+ let(:visibility) { :public }
+
+ describe 'GET #trending' do
+ let!(:project_1) { create(:project, visibility, ci_id: 1) }
+ let!(:project_2) { create(:project, visibility, ci_id: 2) }
+
+ let!(:trending_project_1) { create(:trending_project, project: project_1) }
+ let!(:trending_project_2) { create(:trending_project, project: project_2) }
+
+ before do
+ sign_in(user)
+ end
+
+ context 'sorting by update date' do
+ it 'sorts by last updated' do
+ get :trending, sort: 'updated_desc'
+ expect(assigns(:projects)).to eq [project_2, project_1]
+ end
+
+ it 'sorts by oldest updated' do
+ get :trending, sort: 'updated_asc'
+ expect(assigns(:projects)).to eq [project_1, project_2]
+ end
+ end
+ end
+end
diff --git a/spec/factories/trending_project.rb b/spec/factories/trending_project.rb
new file mode 100644
index 00000000000..246176611dc
--- /dev/null
+++ b/spec/factories/trending_project.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ # TrendingProject
+ factory :trending_project, class: 'TrendingProject' do
+ project
+ end
+end