summaryrefslogtreecommitdiff
path: root/spec/models/namespace_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/namespace_spec.rb')
-rw-r--r--spec/models/namespace_spec.rb187
1 files changed, 169 insertions, 18 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 4ef2ddd218a..ca1f06370d4 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -175,12 +175,13 @@ RSpec.describe Namespace do
end
describe '.with_statistics' do
- let(:namespace) { create :namespace }
+ let_it_be(:namespace) { create(:namespace) }
let(:project1) do
create(:project,
namespace: namespace,
statistics: build(:project_statistics,
+ namespace: namespace,
repository_size: 101,
wiki_size: 505,
lfs_objects_size: 202,
@@ -193,6 +194,7 @@ RSpec.describe Namespace do
create(:project,
namespace: namespace,
statistics: build(:project_statistics,
+ namespace: namespace,
repository_size: 10,
wiki_size: 50,
lfs_objects_size: 20,
@@ -391,14 +393,14 @@ RSpec.describe Namespace do
let(:uploads_dir) { FileUploader.root }
let(:pages_dir) { File.join(TestEnv.pages_path) }
- def expect_project_directories_at(namespace_path)
+ def expect_project_directories_at(namespace_path, with_pages: true)
expected_repository_path = File.join(TestEnv.repos_path, namespace_path, 'the-project.git')
expected_upload_path = File.join(uploads_dir, namespace_path, 'the-project')
expected_pages_path = File.join(pages_dir, namespace_path, 'the-project')
expect(File.directory?(expected_repository_path)).to be_truthy
expect(File.directory?(expected_upload_path)).to be_truthy
- expect(File.directory?(expected_pages_path)).to be_truthy
+ expect(File.directory?(expected_pages_path)).to be(with_pages)
end
before do
@@ -407,43 +409,156 @@ RSpec.describe Namespace do
FileUtils.mkdir_p(File.join(pages_dir, project.full_path))
end
+ after do
+ FileUtils.remove_entry(File.join(TestEnv.repos_path, parent.full_path), true)
+ FileUtils.remove_entry(File.join(TestEnv.repos_path, new_parent.full_path), true)
+ FileUtils.remove_entry(File.join(TestEnv.repos_path, child.full_path), true)
+ FileUtils.remove_entry(File.join(uploads_dir, project.full_path), true)
+ FileUtils.remove_entry(pages_dir, true)
+ end
+
context 'renaming child' do
- it 'correctly moves the repository, uploads and pages' do
- child.update!(path: 'renamed')
+ context 'when no projects have pages deployed' do
+ it 'moves the repository and uploads', :sidekiq_inline do
+ project.pages_metadatum.update!(deployed: false)
+ child.update!(path: 'renamed')
- expect_project_directories_at('parent/renamed')
+ expect_project_directories_at('parent/renamed', with_pages: false)
+ end
+ end
+
+ context 'when the project has pages deployed' do
+ before do
+ project.pages_metadatum.update!(deployed: true)
+ end
+
+ it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
+ child.update!(path: 'renamed')
+
+ expect_project_directories_at('parent/renamed')
+ end
+
+ it 'performs the move async of pages async' do
+ expect(PagesTransferWorker).to receive(:perform_async).with('rename_namespace', ['parent/child', 'parent/renamed'])
+
+ child.update!(path: 'renamed')
+ end
end
end
context 'renaming parent' do
- it 'correctly moves the repository, uploads and pages' do
- parent.update!(path: 'renamed')
+ context 'when no projects have pages deployed' do
+ it 'moves the repository and uploads', :sidekiq_inline do
+ project.pages_metadatum.update!(deployed: false)
+ parent.update!(path: 'renamed')
- expect_project_directories_at('renamed/child')
+ expect_project_directories_at('renamed/child', with_pages: false)
+ end
+ end
+
+ context 'when the project has pages deployed' do
+ before do
+ project.pages_metadatum.update!(deployed: true)
+ end
+
+ it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
+ parent.update!(path: 'renamed')
+
+ expect_project_directories_at('renamed/child')
+ end
+
+ it 'performs the move async of pages async' do
+ expect(PagesTransferWorker).to receive(:perform_async).with('rename_namespace', %w(parent renamed))
+
+ parent.update!(path: 'renamed')
+ end
end
end
context 'moving from one parent to another' do
- it 'correctly moves the repository, uploads and pages' do
- child.update!(parent: new_parent)
+ context 'when no projects have pages deployed' do
+ it 'moves the repository and uploads', :sidekiq_inline do
+ project.pages_metadatum.update!(deployed: false)
+ child.update!(parent: new_parent)
+
+ expect_project_directories_at('new_parent/child', with_pages: false)
+ end
+ end
- expect_project_directories_at('new_parent/child')
+ context 'when the project has pages deployed' do
+ before do
+ project.pages_metadatum.update!(deployed: true)
+ end
+
+ it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
+ child.update!(parent: new_parent)
+
+ expect_project_directories_at('new_parent/child')
+ end
+
+ it 'performs the move async of pages async' do
+ expect(PagesTransferWorker).to receive(:perform_async).with('move_namespace', %w(child parent new_parent))
+
+ child.update!(parent: new_parent)
+ end
end
end
context 'moving from having a parent to root' do
- it 'correctly moves the repository, uploads and pages' do
- child.update!(parent: nil)
+ context 'when no projects have pages deployed' do
+ it 'moves the repository and uploads', :sidekiq_inline do
+ project.pages_metadatum.update!(deployed: false)
+ child.update!(parent: nil)
+
+ expect_project_directories_at('child', with_pages: false)
+ end
+ end
+
+ context 'when the project has pages deployed' do
+ before do
+ project.pages_metadatum.update!(deployed: true)
+ end
+
+ it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
+ child.update!(parent: nil)
- expect_project_directories_at('child')
+ expect_project_directories_at('child')
+ end
+
+ it 'performs the move async of pages async' do
+ expect(PagesTransferWorker).to receive(:perform_async).with('move_namespace', ['child', 'parent', nil])
+
+ child.update!(parent: nil)
+ end
end
end
context 'moving from root to having a parent' do
- it 'correctly moves the repository, uploads and pages' do
- parent.update!(parent: new_parent)
+ context 'when no projects have pages deployed' do
+ it 'moves the repository and uploads', :sidekiq_inline do
+ project.pages_metadatum.update!(deployed: false)
+ parent.update!(parent: new_parent)
- expect_project_directories_at('new_parent/parent/child')
+ expect_project_directories_at('new_parent/parent/child', with_pages: false)
+ end
+ end
+
+ context 'when the project has pages deployed' do
+ before do
+ project.pages_metadatum.update!(deployed: true)
+ end
+
+ it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
+ parent.update!(parent: new_parent)
+
+ expect_project_directories_at('new_parent/parent/child')
+ end
+
+ it 'performs the move async of pages async' do
+ expect(PagesTransferWorker).to receive(:perform_async).with('move_namespace', ['parent', nil, 'new_parent'])
+
+ parent.update!(parent: new_parent)
+ end
end
end
end
@@ -588,6 +703,21 @@ RSpec.describe Namespace do
end
end
+ describe ".clean_name" do
+ context "when the name complies with the group name regex" do
+ it "returns the name as is" do
+ valid_name = "Hello - World _ (Hi.)"
+ expect(described_class.clean_name(valid_name)).to eq(valid_name)
+ end
+ end
+
+ context "when the name does not comply with the group name regex" do
+ it "sanitizes the name by replacing all invalid char sequences with a space" do
+ expect(described_class.clean_name("Green'! Test~~~")).to eq("Green Test")
+ end
+ end
+ end
+
describe "#default_branch_protection" do
let(:namespace) { create(:namespace) }
let(:default_branch_protection) { nil }
@@ -1101,6 +1231,27 @@ RSpec.describe Namespace do
end
end
+ describe '#any_project_with_pages_deployed?' do
+ it 'returns true if any project nested under the group has pages deployed' do
+ parent_1 = create(:group) # Three projects, one with pages
+ child_1_1 = create(:group, parent: parent_1) # Two projects, one with pages
+ child_1_2 = create(:group, parent: parent_1) # One project, no pages
+ parent_2 = create(:group) # No projects
+
+ create(:project, group: child_1_1).tap do |project|
+ project.pages_metadatum.update!(deployed: true)
+ end
+
+ create(:project, group: child_1_1)
+ create(:project, group: child_1_2)
+
+ expect(parent_1.any_project_with_pages_deployed?).to be(true)
+ expect(child_1_1.any_project_with_pages_deployed?).to be(true)
+ expect(child_1_2.any_project_with_pages_deployed?).to be(false)
+ expect(parent_2.any_project_with_pages_deployed?).to be(false)
+ end
+ end
+
describe '#has_parent?' do
it 'returns true when the group has a parent' do
group = create(:group, :nested)