2017-07-24 06:54:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Admin::ProjectsFinder do
|
|
|
|
describe '#execute' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
|
|
|
|
let!(:private_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :private, name: 'A', path: 'A')
|
2017-07-24 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:internal_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :internal, group: group, name: 'B', path: 'B')
|
2017-07-24 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:public_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :public, group: group, name: 'C', path: 'C')
|
2017-07-24 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:shared_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, :private, name: 'D', path: 'D')
|
2017-07-24 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:params) { {} }
|
|
|
|
let(:current_user) { user }
|
|
|
|
let(:project_ids_relation) { nil }
|
|
|
|
let(:finder) { described_class.new(params: params, current_user: current_user) }
|
|
|
|
|
|
|
|
subject { finder.execute.to_a }
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
2017-07-24 11:20:52 -04:00
|
|
|
it { is_expected.to match_array([shared_project, public_project, internal_project, private_project]) }
|
2017-07-24 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a user' do
|
2017-07-24 11:20:52 -04:00
|
|
|
it { is_expected.to match_array([shared_project, public_project, internal_project, private_project]) }
|
2017-07-24 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter by namespace_id' do
|
|
|
|
let(:namespace) { create(:namespace) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project_in_namespace) { create(:project, namespace: namespace) }
|
2017-07-24 06:54:16 -04:00
|
|
|
let(:params) { { namespace_id: namespace.id } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([project_in_namespace]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter by visibility_level' do
|
|
|
|
before do
|
|
|
|
private_project.add_master(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'private' do
|
|
|
|
let(:params) { { visibility_level: Gitlab::VisibilityLevel::PRIVATE } }
|
|
|
|
|
2017-07-24 11:20:52 -04:00
|
|
|
it { is_expected.to match_array([shared_project, private_project]) }
|
2017-07-24 06:54:16 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
context 'filter by push' do
|
|
|
|
let(:pushed_event) { create(:event, :pushed) }
|
|
|
|
let!(:project_with_push) { pushed_event.project }
|
|
|
|
let(:params) { { with_push: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([project_with_push]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter by abandoned' do
|
|
|
|
before do
|
|
|
|
private_project.update(last_activity_at: Time.zone.now - 6.months - 1.minute)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:params) { { abandoned: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([private_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter by last_repository_check_failed' do
|
|
|
|
before do
|
|
|
|
private_project.update(last_repository_check_failed: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:params) { { last_repository_check_failed: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([private_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter by archived' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:archived_project) { create(:project, :public, :archived, name: 'E', path: 'E') }
|
2017-07-24 06:54:16 -04:00
|
|
|
|
|
|
|
context 'archived=false' do
|
|
|
|
let(:params) { { archived: false } }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([shared_project, public_project, internal_project, private_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'archived=true' do
|
|
|
|
let(:params) { { archived: true } }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([archived_project, shared_project, public_project, internal_project, private_project]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter by personal' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:personal_project) { create(:project, namespace: user.namespace) }
|
2017-07-24 06:54:16 -04:00
|
|
|
let(:params) { { personal: true } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([personal_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter by name' do
|
|
|
|
let(:params) { { name: 'C' } }
|
|
|
|
|
2017-07-24 11:20:52 -04:00
|
|
|
it { is_expected.to match_array([shared_project, public_project, private_project]) }
|
2017-07-24 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'sorting' do
|
|
|
|
let(:params) { { sort: 'name_asc' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([private_project, internal_project, public_project, shared_project]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|