diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/models/namespace_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/models/namespace_spec.rb')
-rw-r--r-- | spec/models/namespace_spec.rb | 95 |
1 files changed, 51 insertions, 44 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 91b18f346c6..85f9005052e 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -147,30 +147,45 @@ RSpec.describe Namespace do end describe '.search' do - let(:namespace) { create(:namespace) } + let_it_be(:first_namespace) { build(:namespace, name: 'my first namespace', path: 'old-path').tap(&:save!) } + let_it_be(:parent_namespace) { build(:namespace, name: 'my parent namespace', path: 'parent-path').tap(&:save!) } + let_it_be(:second_namespace) { build(:namespace, name: 'my second namespace', path: 'new-path', parent: parent_namespace).tap(&:save!) } + let_it_be(:project_with_same_path) { create(:project, id: second_namespace.id, path: first_namespace.path) } it 'returns namespaces with a matching name' do - expect(described_class.search(namespace.name)).to eq([namespace]) + expect(described_class.search('my first namespace')).to eq([first_namespace]) end it 'returns namespaces with a partially matching name' do - expect(described_class.search(namespace.name[0..2])).to eq([namespace]) + expect(described_class.search('first')).to eq([first_namespace]) end it 'returns namespaces with a matching name regardless of the casing' do - expect(described_class.search(namespace.name.upcase)).to eq([namespace]) + expect(described_class.search('MY FIRST NAMESPACE')).to eq([first_namespace]) end it 'returns namespaces with a matching path' do - expect(described_class.search(namespace.path)).to eq([namespace]) + expect(described_class.search('old-path')).to eq([first_namespace]) end it 'returns namespaces with a partially matching path' do - expect(described_class.search(namespace.path[0..2])).to eq([namespace]) + expect(described_class.search('old')).to eq([first_namespace]) end it 'returns namespaces with a matching path regardless of the casing' do - expect(described_class.search(namespace.path.upcase)).to eq([namespace]) + expect(described_class.search('OLD-PATH')).to eq([first_namespace]) + end + + it 'returns namespaces with a matching route path' do + expect(described_class.search('parent-path/new-path', include_parents: true)).to eq([second_namespace]) + end + + it 'returns namespaces with a partially matching route path' do + expect(described_class.search('parent-path/new', include_parents: true)).to eq([second_namespace]) + end + + it 'returns namespaces with a matching route path regardless of the casing' do + expect(described_class.search('PARENT-PATH/NEW-PATH', include_parents: true)).to eq([second_namespace]) end end @@ -672,7 +687,7 @@ RSpec.describe Namespace do let!(:project) { create(:project_empty_repo, namespace: namespace) } it 'has no repositories base directories to remove' do - allow(GitlabShellWorker).to receive(:perform_in) + expect(GitlabShellWorker).not_to receive(:perform_in) expect(File.exist?(path_in_dir)).to be(false) @@ -855,8 +870,8 @@ RSpec.describe Namespace do end describe '#all_projects' do - shared_examples 'all projects for a namespace' do - let(:namespace) { create(:namespace) } + shared_examples 'all projects for a group' do + let(:namespace) { create(:group) } let(:child) { create(:group, parent: namespace) } let!(:project1) { create(:project_empty_repo, namespace: namespace) } let!(:project2) { create(:project_empty_repo, namespace: child) } @@ -865,30 +880,34 @@ RSpec.describe Namespace do it { expect(child.all_projects.to_a).to match_array([project2]) } end - shared_examples 'all project examples' do - include_examples 'all projects for a namespace' + shared_examples 'all projects for personal namespace' do + let_it_be(:user) { create(:user) } + let_it_be(:user_namespace) { create(:namespace, owner: user) } + let_it_be(:project) { create(:project, namespace: user_namespace) } + + it { expect(user_namespace.all_projects.to_a).to match_array([project]) } + end + context 'with recursive approach' do context 'when namespace is a group' do - let_it_be(:namespace) { create(:group) } + include_examples 'all projects for a group' + + it 'queries for the namespace and its descendants' do + expect(Project).to receive(:where).with(namespace: [namespace, child]) - include_examples 'all projects for a namespace' + namespace.all_projects + end end context 'when namespace is a user namespace' do - let_it_be(:user) { create(:user) } - let_it_be(:user_namespace) { create(:namespace, owner: user) } - let_it_be(:project) { create(:project, namespace: user_namespace) } + include_examples 'all projects for personal namespace' - it { expect(user_namespace.all_projects.to_a).to match_array([project]) } - end - end + it 'only queries for the namespace itself' do + expect(Project).to receive(:where).with(namespace: user_namespace) - context 'with recursive approach' do - before do - stub_feature_flags(recursive_approach_for_all_projects: true) + user_namespace.all_projects + end end - - include_examples 'all project examples' end context 'with route path wildcard approach' do @@ -896,7 +915,13 @@ RSpec.describe Namespace do stub_feature_flags(recursive_approach_for_all_projects: false) end - include_examples 'all project examples' + context 'when namespace is a group' do + include_examples 'all projects for a group' + end + + context 'when namespace is a user namespace' do + include_examples 'all projects for personal namespace' + end end end @@ -1246,24 +1271,6 @@ RSpec.describe Namespace do expect(virtual_domain.lookup_paths).not_to be_empty end end - - it 'preloads project_feature and route' do - project2 = create(:project, namespace: namespace) - project3 = create(:project, namespace: namespace) - - project.mark_pages_as_deployed - project2.mark_pages_as_deployed - project3.mark_pages_as_deployed - - virtual_domain = namespace.pages_virtual_domain - - queries = ActiveRecord::QueryRecorder.new { virtual_domain.lookup_paths } - - # 1 to load projects - # 1 to preload project features - # 1 to load routes - expect(queries.count).to eq(3) - end end end |