2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe Dashboard::ProjectsController, :aggregate_failures, feature_category: :projects do
|
2019-07-07 11:18:12 +05:30
|
|
|
include ExternalAuthorizationServiceHelpers
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe '#index' do
|
|
|
|
context 'user logged in' do
|
2021-03-08 18:12:59 +05:30
|
|
|
let_it_be(:project) { create(:project, name: 'Project 1') }
|
|
|
|
let_it_be(:project2) { create(:project, name: 'Project Two') }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:projects) { [project, project2] }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
before_all do
|
|
|
|
project.add_developer(user)
|
|
|
|
project2.add_developer(user)
|
2023-05-27 22:25:52 +05:30
|
|
|
user.toggle_star(project2)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
before do
|
2019-09-30 21:07:59 +05:30
|
|
|
sign_in(user)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'external authorization' do
|
|
|
|
it 'works when the external authorization service is enabled' do
|
|
|
|
enable_external_authorization_service_check
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it 'orders the projects by name by default' do
|
2019-09-30 21:07:59 +05:30
|
|
|
get :index
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(assigns(:projects)).to eq(projects)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'assigns the correct total_user_projects_count' do
|
|
|
|
get :index
|
|
|
|
total_user_projects_count = assigns(:total_user_projects_count)
|
|
|
|
|
|
|
|
expect(total_user_projects_count.count).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the correct total_starred_projects_count' do
|
|
|
|
get :index
|
|
|
|
total_starred_projects_count = assigns(:total_starred_projects_count)
|
|
|
|
|
|
|
|
expect(total_starred_projects_count.count).to eq(1)
|
|
|
|
expect(total_starred_projects_count).to include(project2)
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'project sorting' do
|
|
|
|
it_behaves_like 'set sort order from user preference' do
|
|
|
|
let(:sorting_param) { 'created_asc' }
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
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
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context 'with archived project' do
|
|
|
|
let_it_be(:archived_project) do
|
|
|
|
project2.tap { |p| p.update!(archived: true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not display archived project' do
|
|
|
|
get :index
|
|
|
|
projects_result = assigns(:projects)
|
|
|
|
|
|
|
|
expect(projects_result).not_to include(archived_project)
|
|
|
|
expect(projects_result).to include(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'excludes archived project from total_user_projects_count' do
|
|
|
|
get :index
|
|
|
|
total_user_projects_count = assigns(:total_user_projects_count)
|
|
|
|
|
|
|
|
expect(total_user_projects_count.count).to eq(1)
|
|
|
|
expect(total_user_projects_count).not_to include(archived_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'excludes archived project from total_starred_projects_count' do
|
|
|
|
get :index
|
|
|
|
total_starred_projects_count = assigns(:total_starred_projects_count)
|
|
|
|
|
|
|
|
expect(total_starred_projects_count.count).to eq(0)
|
|
|
|
expect(total_starred_projects_count).not_to include(archived_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'with deleted project' do
|
|
|
|
let!(:pending_delete_project) do
|
|
|
|
project.tap { |p| p.update!(pending_delete: true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not display deleted project' do
|
|
|
|
get :index
|
|
|
|
projects_result = assigns(:projects)
|
|
|
|
|
|
|
|
expect(projects_result).not_to include(pending_delete_project)
|
|
|
|
expect(projects_result).to include(project2)
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'json requests' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
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-05-24 23:13:21 +05:30
|
|
|
subject { get :starred, format: :json }
|
|
|
|
|
|
|
|
let(:projects) { create_list(:project, 2, creator: user) }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:aimed_for_deletion_project) { create_list(:project, 2, :archived, creator: user, marked_for_deletion_at: 3.days.ago) }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
before do
|
2020-05-24 23:13:21 +05:30
|
|
|
projects.each do |project|
|
|
|
|
project.add_developer(user)
|
|
|
|
create(:users_star_project, project_id: project.id, user_id: user.id)
|
|
|
|
end
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
aimed_for_deletion_project.each do |project|
|
|
|
|
project.add_developer(user)
|
|
|
|
create(:users_star_project, project_id: project.id, user_id: user.id)
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it 'returns success' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context "pagination" do
|
|
|
|
before do
|
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'paginates the records' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(assigns(:projects).count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include projects aimed for deletion' do
|
2020-05-24 23:13:21 +05:30
|
|
|
subject
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(assigns(:projects).count).to eq(2)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'atom requests' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
2020-07-28 23:09:34 +05:30
|
|
|
let_it_be(:projects) { create_list(:project, 2, creator: user) }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'project pagination' do
|
2020-05-24 23:13:21 +05:30
|
|
|
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
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe 'rendering' do
|
|
|
|
include DesignManagementTestHelpers
|
|
|
|
render_views
|
|
|
|
|
|
|
|
let(:project) { projects.first }
|
|
|
|
let!(:design_event) { create(:design_event, project: project) }
|
|
|
|
let!(:wiki_page_event) { create(:wiki_page_event, project: project) }
|
|
|
|
let!(:issue_event) { create(:closed_issue_event, project: project) }
|
2021-09-04 01:27:46 +05:30
|
|
|
let!(:push_event) do
|
|
|
|
create(:push_event, project: project).tap do |event|
|
|
|
|
create(:push_event_payload, event: event, ref_count: 2, ref: nil, ref_type: :tag, commit_count: 0, action: :pushed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:design) { design_event.design }
|
|
|
|
let(:wiki_page) { wiki_page_event.wiki_page }
|
|
|
|
let(:issue) { issue_event.issue }
|
|
|
|
|
|
|
|
before do
|
|
|
|
enable_design_management
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it 'renders all kinds of event without error' do
|
2020-07-28 23:09:34 +05:30
|
|
|
get :index, format: :atom
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(assigns(:events)).to include(design_event, wiki_page_event, issue_event, push_event)
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(response).to render_template('dashboard/projects/index')
|
|
|
|
expect(response.body).to include(
|
2021-09-04 01:27:46 +05:30
|
|
|
"pushed to project",
|
2021-10-27 15:23:28 +05:30
|
|
|
"added design #{design.to_reference}",
|
2020-07-28 23:09:34 +05:30
|
|
|
"created wiki page #{wiki_page.title}",
|
|
|
|
"joined project #{project.full_name}",
|
|
|
|
"closed issue #{issue.to_reference}"
|
|
|
|
)
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
context 'with deleted project' do
|
|
|
|
let(:pending_deleted_project) { projects.last.tap { |p| p.update!(pending_delete: true) } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
pending_deleted_project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not display deleted project' do
|
|
|
|
get :index, format: :atom
|
|
|
|
|
|
|
|
expect(response.body).not_to include(pending_deleted_project.full_name)
|
|
|
|
expect(response.body).to include(project.full_name)
|
|
|
|
end
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2018-11-29 20:51:05 +05:30
|
|
|
end
|