Fix /explore sorting (trending)

Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/27044
This commit is contained in:
Eric Eastwood 2017-01-25 13:53:29 -06:00
parent 1fe80c2962
commit 6fbf24af27
4 changed files with 41 additions and 0 deletions

View file

@ -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|

View file

@ -0,0 +1,4 @@
---
title: Fix /explore sorting
merge_request:
author:

View file

@ -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

View file

@ -0,0 +1,6 @@
FactoryGirl.define do
# TrendingProject
factory :trending_project, class: 'TrendingProject' do
project
end
end