2019-10-16 05:07:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-02-25 07:36:36 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-01-08 10:10:26 -05:00
|
|
|
RSpec.describe ProjectsFinder do
|
2019-11-06 13:06:29 -05:00
|
|
|
include AdminModeHelper
|
|
|
|
|
2015-11-18 06:21:06 -05:00
|
|
|
describe '#execute' do
|
2020-03-23 08:09:47 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:group) { create(:group, :public) }
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2020-03-23 08:09:47 -04:00
|
|
|
let_it_be(:private_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :private, name: 'A', path: 'A')
|
2015-11-20 09:48:05 -05:00
|
|
|
end
|
|
|
|
|
2020-03-23 08:09:47 -04:00
|
|
|
let_it_be(:internal_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :internal, group: group, name: 'B', path: 'B')
|
2015-11-20 09:48:05 -05:00
|
|
|
end
|
|
|
|
|
2020-03-23 08:09:47 -04:00
|
|
|
let_it_be(:public_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :public, group: group, name: 'C', path: 'C')
|
2015-11-20 09:48:05 -05:00
|
|
|
end
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2020-03-23 08:09:47 -04:00
|
|
|
let_it_be(:shared_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :private, name: 'D', path: 'D')
|
2016-03-12 08:45:14 -05:00
|
|
|
end
|
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
let(:params) { {} }
|
|
|
|
let(:current_user) { user }
|
|
|
|
let(:project_ids_relation) { nil }
|
2020-01-27 16:08:47 -05:00
|
|
|
let(:use_cte) { true }
|
|
|
|
let(:finder) { described_class.new(params: params.merge(use_cte: use_cte), current_user: current_user, project_ids_relation: project_ids_relation) }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
|
|
|
subject { finder.execute }
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
shared_examples 'ProjectFinder#execute examples' do
|
|
|
|
describe 'without a user' do
|
|
|
|
let(:current_user) { nil }
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([public_project]) }
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with a user' do
|
|
|
|
describe 'without private projects' do
|
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
2016-03-12 08:45:14 -05:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with private projects' do
|
|
|
|
before do
|
|
|
|
private_project.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project, internal_project, private_project]) }
|
|
|
|
end
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|
2016-08-12 11:30:44 -04:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with project_ids_relation' do
|
|
|
|
let(:project_ids_relation) { Project.where(id: internal_project.id) }
|
2016-08-12 11:30:44 -04:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([internal_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with id_after' do
|
|
|
|
context 'only returns projects with a project id greater than given' do
|
|
|
|
let(:params) { { id_after: internal_project.id }}
|
2019-11-15 01:06:13 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
2019-11-15 01:06:13 -05:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with id_before' do
|
|
|
|
context 'only returns projects with a project id less than given' do
|
|
|
|
let(:params) { { id_before: public_project.id }}
|
2019-11-15 01:06:13 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([internal_project]) }
|
|
|
|
end
|
2019-11-15 01:06:13 -05:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with both id_before and id_after' do
|
|
|
|
context 'only returns projects with a project id less than given' do
|
|
|
|
let!(:projects) { create_list(:project, 5, :public) }
|
|
|
|
let(:params) { { id_after: projects.first.id, id_before: projects.last.id }}
|
2019-11-15 01:06:13 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to contain_exactly(*projects[1..-2]) }
|
|
|
|
end
|
2019-11-15 01:06:13 -05:00
|
|
|
end
|
|
|
|
|
2020-04-07 17:09:46 -04:00
|
|
|
describe 'regression: Combination of id_before/id_after and joins requires fully qualified column names' do
|
|
|
|
context 'only returns projects with a project id less than given and matching search' do
|
|
|
|
subject { finder.execute.joins(:route) }
|
|
|
|
|
|
|
|
let(:params) { { id_before: public_project.id }}
|
|
|
|
|
|
|
|
it { is_expected.to eq([internal_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'only returns projects with a project id greater than given and matching search' do
|
|
|
|
subject { finder.execute.joins(:route) }
|
|
|
|
|
|
|
|
let(:params) { { id_after: internal_project.id }}
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by visibility_level' do
|
|
|
|
before do
|
|
|
|
private_project.add_maintainer(user)
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
context 'private' do
|
|
|
|
let(:params) { { visibility_level: Gitlab::VisibilityLevel::PRIVATE } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([private_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
context 'internal' do
|
|
|
|
let(:params) { { visibility_level: Gitlab::VisibilityLevel::INTERNAL } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([internal_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'public' do
|
|
|
|
let(:params) { { visibility_level: Gitlab::VisibilityLevel::PUBLIC } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
2021-04-06 11:09:23 -04:00
|
|
|
|
|
|
|
context 'as string' do
|
|
|
|
let(:params) { { visibility_level: Gitlab::VisibilityLevel::INTERNAL.to_s } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([internal_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
|
|
|
|
2021-05-25 14:10:42 -04:00
|
|
|
describe 'filter by tags (deprecated)' do
|
2020-01-27 16:08:47 -05:00
|
|
|
before do
|
2021-08-24 11:10:36 -04:00
|
|
|
public_project.reload
|
2021-05-25 14:10:42 -04:00
|
|
|
public_project.topic_list = 'foo'
|
2020-01-27 16:08:47 -05:00
|
|
|
public_project.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:params) { { tag: 'foo' } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
2021-05-25 14:10:42 -04:00
|
|
|
describe 'filter by topics' do
|
|
|
|
before do
|
2021-08-24 11:10:36 -04:00
|
|
|
public_project.reload
|
2021-06-03 23:10:08 -04:00
|
|
|
public_project.topic_list = 'foo, bar'
|
2021-05-25 14:10:42 -04:00
|
|
|
public_project.save!
|
|
|
|
end
|
|
|
|
|
2021-06-03 23:10:08 -04:00
|
|
|
context 'single topic' do
|
|
|
|
let(:params) { { topic: 'foo' } }
|
2021-05-25 14:10:42 -04:00
|
|
|
|
2021-06-03 23:10:08 -04:00
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'multiple topics' do
|
|
|
|
let(:params) { { topic: 'bar, foo' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'one topic matches, other one does not' do
|
|
|
|
let(:params) { { topic: 'foo, xyz' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no matching topic' do
|
|
|
|
let(:params) { { topic: 'xyz' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([]) }
|
|
|
|
end
|
2021-05-25 14:10:42 -04:00
|
|
|
end
|
|
|
|
|
2022-07-04 20:09:38 -04:00
|
|
|
describe 'filter by topic_id' do
|
|
|
|
let_it_be(:topic1) { create(:topic) }
|
|
|
|
let_it_be(:topic2) { create(:topic) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
public_project.reload
|
|
|
|
public_project.topics << topic1
|
|
|
|
public_project.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'topic with assigned projects' do
|
|
|
|
let(:params) { { topic_id: topic1.id } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'topic without assigned projects' do
|
|
|
|
let(:params) { { topic_id: topic2.id } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'non-existing topic' do
|
|
|
|
let(:params) { { topic_id: non_existing_record_id } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by personal' do
|
|
|
|
let!(:personal_project) { create(:project, namespace: user.namespace) }
|
|
|
|
let(:params) { { personal: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([personal_project]) }
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by search' do
|
|
|
|
let(:params) { { search: 'C' } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2021-09-15 14:11:29 -04:00
|
|
|
context 'with anonymous user' do
|
|
|
|
let(:public_project_2) { create(:project, :public, group: group, name: 'E', path: 'E') }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
let(:params) { { search: 'C' } }
|
|
|
|
|
2021-09-15 20:11:46 -04:00
|
|
|
context 'with disable_anonymous_project_search feature flag enabled' do
|
2021-09-15 14:11:29 -04:00
|
|
|
before do
|
2021-09-15 20:11:46 -04:00
|
|
|
stub_feature_flags(disable_anonymous_project_search: true)
|
2021-09-15 14:11:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not perform search' do
|
|
|
|
is_expected.to eq([public_project_2, public_project])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-15 20:11:46 -04:00
|
|
|
context 'with disable_anonymous_project_search feature flag disabled' do
|
2021-09-15 14:11:29 -04:00
|
|
|
before do
|
2021-09-15 20:11:46 -04:00
|
|
|
stub_feature_flags(disable_anonymous_project_search: false)
|
2021-09-15 14:11:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds one public project' do
|
|
|
|
is_expected.to eq([public_project])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by name for backward compatibility' do
|
|
|
|
let(:params) { { name: 'C' } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
describe 'filter by search with minimum search length' do
|
|
|
|
context 'when search term is shorter than minimum length' do
|
|
|
|
let(:params) { { search: 'C', minimum_search_length: 3 } }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when search term is longer than minimum length' do
|
|
|
|
let(:project) { create(:project, :public, group: group, name: 'test_project') }
|
|
|
|
let(:params) { { search: 'test', minimum_search_length: 3 } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when minimum length is invalid' do
|
|
|
|
let(:params) { { search: 'C', minimum_search_length: 'x' } }
|
|
|
|
|
|
|
|
it 'ignores the minimum length param' do
|
|
|
|
is_expected.to eq([public_project])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-23 08:09:47 -04:00
|
|
|
describe 'filter by group name' do
|
|
|
|
let(:params) { { name: group.name, search_namespaces: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project, internal_project]) }
|
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by archived' do
|
|
|
|
let!(:archived_project) { create(:project, :public, :archived, name: 'E', path: 'E') }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
context 'non_archived=true' do
|
|
|
|
let(:params) { { non_archived: true } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
context 'non_archived=false' do
|
|
|
|
let(:params) { { non_archived: false } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to match_array([public_project, internal_project, archived_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by archived only' do
|
|
|
|
let(:params) { { archived: 'only' } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([archived_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by archived for backward compatibility' do
|
|
|
|
let(:params) { { archived: false } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by trending' do
|
|
|
|
let!(:trending_project) { create(:trending_project, project: public_project) }
|
|
|
|
let(:params) { { trending: true } }
|
2017-08-11 05:09:17 -04:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([public_project]) }
|
2017-08-11 05:09:17 -04:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by owned' do
|
|
|
|
let(:params) { { owned: true } }
|
|
|
|
let!(:owned_project) { create(:project, :private, namespace: current_user.namespace) }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([owned_project]) }
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by non_public' do
|
|
|
|
let(:params) { { non_public: true } }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
before do
|
|
|
|
private_project.add_developer(current_user)
|
|
|
|
end
|
2017-05-26 10:31:37 -04:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([private_project]) }
|
|
|
|
end
|
2017-05-26 10:31:37 -04:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by starred' do
|
|
|
|
let(:params) { { starred: true } }
|
2019-12-17 13:07:48 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
before do
|
|
|
|
current_user.toggle_star(public_project)
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to eq([public_project]) }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it 'returns only projects the user has access to' do
|
|
|
|
current_user.toggle_star(private_project)
|
2019-12-17 13:07:48 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
is_expected.to eq([public_project])
|
|
|
|
expect(subject.count).to eq(1)
|
|
|
|
expect(subject.limit(1000).count).to eq(1)
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'filter by without_deleted' do
|
2020-08-31 17:10:19 -04:00
|
|
|
let_it_be(:pending_delete_project) { create(:project, :public, pending_delete: true) }
|
2017-05-23 16:38:12 -04:00
|
|
|
|
2020-08-31 17:10:19 -04:00
|
|
|
let(:params) { { without_deleted: without_deleted } }
|
|
|
|
|
|
|
|
shared_examples 'returns all projects' do
|
|
|
|
it { expect(subject).to include(public_project, internal_project, pending_delete_project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when without_deleted is true' do
|
|
|
|
let(:without_deleted) { true }
|
|
|
|
|
|
|
|
it 'returns projects that are not pending_delete' do
|
|
|
|
expect(subject).not_to include(pending_delete_project)
|
|
|
|
expect(subject).to include(public_project, internal_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when without_deleted is false' do
|
|
|
|
let(:without_deleted) { false }
|
|
|
|
|
|
|
|
it_behaves_like 'returns all projects'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when without_deleted is nil' do
|
|
|
|
let(:without_deleted) { nil }
|
|
|
|
|
|
|
|
it_behaves_like 'returns all projects'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when without_deleted is not present' do
|
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
it_behaves_like 'returns all projects'
|
|
|
|
end
|
2020-01-27 16:08:47 -05:00
|
|
|
end
|
2017-05-23 16:38:12 -04:00
|
|
|
|
2020-04-01 05:07:45 -04:00
|
|
|
describe 'filter by last_activity_after' do
|
|
|
|
let(:params) { { last_activity_after: 60.minutes.ago } }
|
|
|
|
|
|
|
|
before do
|
2020-08-04 17:09:56 -04:00
|
|
|
internal_project.update!(last_activity_at: Time.now)
|
|
|
|
public_project.update!(last_activity_at: 61.minutes.ago)
|
2020-04-01 05:07:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array([internal_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filter by last_activity_before' do
|
|
|
|
let(:params) { { last_activity_before: 60.minutes.ago } }
|
|
|
|
|
|
|
|
before do
|
2020-08-04 17:09:56 -04:00
|
|
|
internal_project.update!(last_activity_at: Time.now)
|
|
|
|
public_project.update!(last_activity_at: 61.minutes.ago)
|
2020-04-01 05:07:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project]) }
|
|
|
|
end
|
|
|
|
|
2020-06-19 17:08:32 -04:00
|
|
|
describe 'filter by repository_storage' do
|
|
|
|
let(:params) { { repository_storage: 'nfs-05' } }
|
|
|
|
let!(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update_columns(repository_storage: 'nfs-05')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array([project]) }
|
|
|
|
end
|
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'sorting' do
|
2021-07-01 11:07:40 -04:00
|
|
|
let_it_be(:more_projects) do
|
|
|
|
[
|
|
|
|
create(:project, :internal, group: group, name: 'projA', path: 'projA'),
|
|
|
|
create(:project, :internal, group: group, name: 'projABC', path: 'projABC'),
|
|
|
|
create(:project, :internal, group: group, name: 'projAB', path: 'projAB')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2020-10-06 20:08:24 -04:00
|
|
|
context 'when sorting by a field' do
|
|
|
|
let(:params) { { sort: 'name_asc' } }
|
|
|
|
|
2021-07-01 11:07:40 -04:00
|
|
|
it { is_expected.to eq(([internal_project, public_project] + more_projects).sort_by { |p| p[:name] }) }
|
2020-10-06 20:08:24 -04:00
|
|
|
end
|
2020-01-27 16:08:47 -05:00
|
|
|
|
2020-10-06 20:08:24 -04:00
|
|
|
context 'when sorting by similarity' do
|
|
|
|
let(:params) { { sort: 'similarity', search: 'pro' } }
|
|
|
|
|
2021-07-01 11:07:40 -04:00
|
|
|
it { is_expected.to eq([more_projects[0], more_projects[2], more_projects[1]]) }
|
|
|
|
end
|
2020-10-06 20:08:24 -04:00
|
|
|
|
2021-07-01 11:07:40 -04:00
|
|
|
context 'when no sort is provided' do
|
|
|
|
it { is_expected.to eq(([internal_project, public_project] + more_projects).sort_by { |p| p[:id] }.reverse) }
|
2020-10-06 20:08:24 -04:00
|
|
|
end
|
2017-05-23 16:38:12 -04:00
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with admin user' do
|
|
|
|
let(:user) { create(:admin) }
|
2018-09-12 16:52:30 -04:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
context 'admin mode enabled' do
|
|
|
|
before do
|
|
|
|
enable_admin_mode!(current_user)
|
|
|
|
end
|
2018-09-12 16:52:30 -04:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it { is_expected.to match_array([public_project, internal_project, private_project, shared_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
context 'admin mode disabled' do
|
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
|
|
|
end
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
2019-11-06 13:06:29 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'without CTE flag enabled' do
|
|
|
|
let(:use_cte) { false }
|
2019-11-06 13:06:29 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it_behaves_like 'ProjectFinder#execute examples'
|
|
|
|
end
|
2019-11-06 13:06:29 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
describe 'with CTE flag enabled' do
|
|
|
|
let(:use_cte) { true }
|
2019-11-06 13:06:29 -05:00
|
|
|
|
2020-01-27 16:08:47 -05:00
|
|
|
it_behaves_like 'ProjectFinder#execute examples'
|
2019-11-06 13:06:29 -05:00
|
|
|
end
|
2014-02-25 07:36:36 -05:00
|
|
|
end
|
|
|
|
end
|