diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/finders/autocomplete/routes_finder_spec.rb | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/finders/autocomplete/routes_finder_spec.rb')
-rw-r--r-- | spec/finders/autocomplete/routes_finder_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/finders/autocomplete/routes_finder_spec.rb b/spec/finders/autocomplete/routes_finder_spec.rb new file mode 100644 index 00000000000..c5b040a5640 --- /dev/null +++ b/spec/finders/autocomplete/routes_finder_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Autocomplete::RoutesFinder do + describe '#execute' do + let_it_be(:user) { create(:user, username: 'user_path') } + let_it_be(:admin) { create(:admin) } + let_it_be(:group) { create(:group, path: 'path1') } + let_it_be(:group2) { create(:group, path: 'path2') } + let_it_be(:group3) { create(:group, path: 'not-matching') } + let_it_be(:project) { create(:project, path: 'path3', namespace: user.namespace) } + let_it_be(:project2) { create(:project, path: 'path4') } + let_it_be(:project_namespace) { create(:project_namespace, parent: group, path: 'path5') } + + let(:current_user) { user } + let(:search) { 'path' } + + before do + group.add_owner(user) + end + + context 'for NamespacesOnly' do + subject { Autocomplete::RoutesFinder::NamespacesOnly.new(current_user, search: search).execute } + + let(:user_route) { Route.find_by_path(user.username) } + + it 'finds only user namespace and groups matching the search excluding project namespaces' do + is_expected.to match_array([group.route, user_route]) + end + + context 'when user is admin' do + let(:current_user) { admin } + + it 'finds all namespaces matching the search excluding project namespaces' do + is_expected.to match_array([group.route, group2.route, user_route]) + end + end + end + + context 'for ProjectsOnly' do + subject { Autocomplete::RoutesFinder::ProjectsOnly.new(current_user, search: 'path').execute } + + it 'finds only matching projects the user has access to' do + is_expected.to match_array([project.route]) + end + + context 'when user is admin' do + let(:current_user) { admin } + + it 'finds all projects matching the search' do + is_expected.to match_array([project.route, project2.route]) + end + end + end + end +end |