2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe Dashboard::ProjectsController do
|
2019-04-09 11:38:58 -04:00
|
|
|
include ExternalAuthorizationServiceHelpers
|
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
context 'user not logged in' do
|
|
|
|
it_behaves_like 'authenticates sessionless user', :index, :atom
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user logged in' do
|
2020-02-07 07:09:13 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:project2) { create(:project) }
|
|
|
|
|
|
|
|
before_all do
|
|
|
|
project.add_developer(user)
|
|
|
|
project2.add_developer(user)
|
|
|
|
end
|
2019-07-04 05:29:06 -04:00
|
|
|
|
2019-04-09 11:38:58 -04:00
|
|
|
before do
|
2019-07-04 05:29:06 -04:00
|
|
|
sign_in(user)
|
2019-04-09 11:38:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'external authorization' do
|
|
|
|
it 'works when the external authorization service is enabled' do
|
|
|
|
enable_external_authorization_service_check
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-04-09 11:38:58 -04:00
|
|
|
end
|
|
|
|
end
|
2019-07-04 05:29:06 -04:00
|
|
|
|
|
|
|
it 'orders the projects by last activity by default' do
|
|
|
|
project.update!(last_repository_updated_at: 3.days.ago, last_activity_at: 3.days.ago)
|
|
|
|
project2.update!(last_repository_updated_at: 10.days.ago, last_activity_at: 10.days.ago)
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(assigns(:projects)).to eq([project, project2])
|
|
|
|
end
|
2019-08-21 06:13:45 -04:00
|
|
|
|
|
|
|
context 'project sorting' do
|
|
|
|
it_behaves_like 'set sort order from user preference' do
|
|
|
|
let(:sorting_param) { 'created_asc' }
|
|
|
|
end
|
|
|
|
end
|
2020-02-07 07:09:13 -05:00
|
|
|
|
|
|
|
context 'with search and sort parameters' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
shared_examples 'search and sort parameters' do |sort|
|
|
|
|
it 'returns a single project with no ambiguous column errors' do
|
|
|
|
get :index, params: { name: project2.name, sort: sort }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:projects)).to eq([project2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w[latest_activity_desc latest_activity_asc stars_desc stars_asc created_desc].each do |sort|
|
|
|
|
it_behaves_like 'search and sort parameters', sort
|
|
|
|
end
|
|
|
|
end
|
2019-04-09 11:38:58 -04:00
|
|
|
end
|
|
|
|
end
|
2019-03-18 20:01:49 -04:00
|
|
|
|
|
|
|
context 'json requests' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects.json' do
|
|
|
|
before do
|
|
|
|
get :index, format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /starred.json' do
|
2020-04-21 11:21:10 -04:00
|
|
|
subject { get :starred, format: :json }
|
|
|
|
|
|
|
|
let(:projects) { create_list(:project, 2, creator: user) }
|
|
|
|
|
2019-03-18 20:01:49 -04:00
|
|
|
before do
|
2020-04-21 11:21:10 -04:00
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
|
|
|
|
|
|
|
|
projects.each do |project|
|
|
|
|
project.add_developer(user)
|
|
|
|
create(:users_star_project, project_id: project.id, user_id: user.id)
|
|
|
|
end
|
2020-03-10 17:09:21 -04:00
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'returns success' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'paginates the records' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(assigns(:projects).count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'atom requests' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
context 'project pagination' do
|
|
|
|
let(:projects) { create_list(:project, 2, creator: user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
|
|
|
|
|
|
|
|
projects.each do |project|
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not paginate projects, even if normally restricted by pagination' do
|
|
|
|
get :index, format: :atom
|
|
|
|
|
|
|
|
expect(assigns(:events).count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2019-03-18 20:01:49 -04:00
|
|
|
end
|
|
|
|
end
|
2018-11-28 14:06:02 -05:00
|
|
|
end
|