diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/finders/namespaces | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/finders/namespaces')
-rw-r--r-- | spec/finders/namespaces/projects_finder_spec.rb | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/spec/finders/namespaces/projects_finder_spec.rb b/spec/finders/namespaces/projects_finder_spec.rb new file mode 100644 index 00000000000..0f48aa6a9f4 --- /dev/null +++ b/spec/finders/namespaces/projects_finder_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Namespaces::ProjectsFinder do + let_it_be(:current_user) { create(:user) } + let_it_be(:namespace) { create(:group, :public) } + let_it_be(:subgroup) { create(:group, parent: namespace) } + let_it_be(:project_1) { create(:project, :public, group: namespace, path: 'project', name: 'Project') } + let_it_be(:project_2) { create(:project, :public, group: namespace, path: 'test-project', name: 'Test Project') } + let_it_be(:project_3) { create(:project, :public, path: 'sub-test-project', group: subgroup, name: 'Sub Test Project') } + let_it_be(:project_4) { create(:project, :public, path: 'test-project-2', group: namespace, name: 'Test Project 2') } + + let(:params) { {} } + + let(:finder) { described_class.new(namespace: namespace, params: params, current_user: current_user) } + + subject(:projects) { finder.execute } + + describe '#execute' do + context 'without a namespace' do + let(:namespace) { nil } + + it 'returns an empty array' do + expect(projects).to be_empty + end + end + + context 'with a namespace' do + it 'returns the project for the namespace' do + expect(projects).to contain_exactly(project_1, project_2, project_4) + end + + context 'when include_subgroups is provided' do + let(:params) { { include_subgroups: true } } + + it 'returns all projects for the namespace' do + expect(projects).to contain_exactly(project_1, project_2, project_3, project_4) + end + + context 'when ids are provided' do + let(:params) { { include_subgroups: true, ids: [project_3.id] } } + + it 'returns all projects for the ids' do + expect(projects).to contain_exactly(project_3) + end + end + end + + context 'when ids are provided' do + let(:params) { { ids: [project_1.id] } } + + it 'returns all projects for the ids' do + expect(projects).to contain_exactly(project_1) + end + end + + context 'when sort is similarity' do + let(:params) { { sort: :similarity, search: 'test' } } + + it 'returns projects by similarity' do + expect(projects).to contain_exactly(project_2, project_4) + end + end + + context 'when search parameter is missing' do + let(:params) { { sort: :similarity } } + + it 'returns all projects' do + expect(projects).to contain_exactly(project_1, project_2, project_4) + end + end + + context 'when sort parameter is missing' do + let(:params) { { search: 'test' } } + + it 'returns matching projects' do + expect(projects).to contain_exactly(project_2, project_4) + end + end + end + end +end |