2014-02-25 07:36:36 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-02-25 12:21:53 -05:00
|
|
|
describe ProjectsFinder do
|
2015-11-18 06:21:06 -05:00
|
|
|
describe '#execute' do
|
|
|
|
let(:user) { create(:user) }
|
2016-03-21 19:09:20 -04:00
|
|
|
let(:group) { create(:group, :public) }
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2015-11-20 09:48:05 -05:00
|
|
|
let!(: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
|
|
|
|
|
|
|
|
let!(: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
|
|
|
|
|
|
|
|
let!(: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
|
|
|
|
2016-03-12 08:45:14 -05:00
|
|
|
let!(: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 }
|
|
|
|
let(:finder) { described_class.new(params: params, current_user: current_user, project_ids_relation: project_ids_relation) }
|
|
|
|
|
|
|
|
subject { finder.execute }
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2016-08-12 11:14:39 -04:00
|
|
|
describe 'without a user' do
|
2017-03-03 05:35:04 -05:00
|
|
|
let(:current_user) { nil }
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2016-08-12 11:14:39 -04:00
|
|
|
it { is_expected.to eq([public_project]) }
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|
|
|
|
|
2016-08-12 11:14:39 -04:00
|
|
|
describe 'with a user' do
|
|
|
|
describe 'without private projects' do
|
2017-03-03 05:35:04 -05:00
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|
2014-02-25 07:36:36 -05:00
|
|
|
|
2016-08-12 11:14:39 -04:00
|
|
|
describe 'with private projects' do
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
private_project.add_maintainer(user)
|
2016-03-12 08:45:14 -05:00
|
|
|
end
|
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
it { is_expected.to match_array([public_project, internal_project, private_project]) }
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 11:30:44 -04:00
|
|
|
|
|
|
|
describe 'with project_ids_relation' do
|
|
|
|
let(:project_ids_relation) { Project.where(id: internal_project.id) }
|
|
|
|
|
|
|
|
it { is_expected.to eq([internal_project]) }
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
|
|
|
|
describe 'filter by visibility_level' do
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
private_project.add_maintainer(user)
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'private' do
|
|
|
|
let(:params) { { visibility_level: Gitlab::VisibilityLevel::PRIVATE } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([private_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'internal' do
|
|
|
|
let(:params) { { visibility_level: Gitlab::VisibilityLevel::INTERNAL } }
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filter by tags' do
|
|
|
|
before do
|
|
|
|
public_project.tag_list.add('foo')
|
|
|
|
public_project.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:params) { { tag: 'foo' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filter by personal' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:personal_project) { create(:project, namespace: user.namespace) }
|
2017-03-03 05:35:04 -05:00
|
|
|
let(:params) { { personal: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([personal_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filter by search' do
|
|
|
|
let(:params) { { search: 'C' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filter by name for backward compatibility' do
|
|
|
|
let(:params) { { name: 'C' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filter by archived' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:archived_project) { create(:project, :public, :archived, name: 'E', path: 'E') }
|
2017-03-03 05:35:04 -05:00
|
|
|
|
|
|
|
context 'non_archived=true' do
|
|
|
|
let(:params) { { non_archived: true } }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'non_archived=false' do
|
|
|
|
let(:params) { { non_archived: false } }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project, internal_project, archived_project]) }
|
|
|
|
end
|
|
|
|
|
2017-08-11 05:09:17 -04:00
|
|
|
describe 'filter by archived only' do
|
|
|
|
let(:params) { { archived: 'only' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([archived_project]) }
|
|
|
|
end
|
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
describe 'filter by archived for backward compatibility' do
|
|
|
|
let(:params) { { archived: false } }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filter by trending' do
|
|
|
|
let!(:trending_project) { create(:trending_project, project: public_project) }
|
|
|
|
let(:params) { { trending: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
2017-05-26 10:31:37 -04:00
|
|
|
describe 'filter by owned' do
|
|
|
|
let(:params) { { owned: true } }
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:owned_project) { create(:project, :private, namespace: current_user.namespace) }
|
2017-05-26 10:31:37 -04:00
|
|
|
|
|
|
|
it { is_expected.to eq([owned_project]) }
|
|
|
|
end
|
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
describe 'filter by non_public' do
|
|
|
|
let(:params) { { non_public: true } }
|
|
|
|
before do
|
|
|
|
private_project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq([private_project]) }
|
|
|
|
end
|
|
|
|
|
2017-05-23 16:38:12 -04:00
|
|
|
describe 'filter by starred' do
|
2017-03-03 05:35:04 -05:00
|
|
|
let(:params) { { starred: true } }
|
|
|
|
before do
|
|
|
|
current_user.toggle_star(public_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
2017-05-23 16:38:12 -04:00
|
|
|
|
|
|
|
it 'returns only projects the user has access to' do
|
|
|
|
current_user.toggle_star(private_project)
|
|
|
|
|
|
|
|
is_expected.to eq([public_project])
|
|
|
|
end
|
2017-03-03 05:35:04 -05:00
|
|
|
end
|
|
|
|
|
2018-09-12 16:52:30 -04:00
|
|
|
describe 'filter by without_deleted' do
|
|
|
|
let(:params) { { without_deleted: true } }
|
|
|
|
let!(:pending_delete_project) { create(:project, :public, pending_delete: true) }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project, internal_project]) }
|
|
|
|
end
|
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
describe 'sorting' do
|
|
|
|
let(:params) { { sort: 'name_asc' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([internal_project, public_project]) }
|
|
|
|
end
|
2014-02-25 07:36:36 -05:00
|
|
|
end
|
|
|
|
end
|