diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-03 09:36:09 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-03 09:36:09 +0200 |
commit | fc550b398be6cdc4584dad79411929305815ffaa (patch) | |
tree | 0995b6990fa3599dddfed5bd2720589731bcdf31 /spec/models/namespace_spec.rb | |
parent | 83d1fe9b5aeb947c1387666205ecaca81f2bf3a2 (diff) | |
parent | e7e9307219d1c81427f95444b36471c519dc06c2 (diff) | |
download | gitlab-ce-fc550b398be6cdc4584dad79411929305815ffaa.tar.gz |
Merge branch 'master' into feature/multi-level-container-registry-images
* master: (230 commits)
Fix N+1 query in loading pipelines in merge requests
Fix Spinach and Capybara dependencies
Prevent users from disconnecting gitlab account from CAS
30276 Move issue, mr, todos next to profile dropdown in top nav
Refactor SearchController#show
Properly eagerly-load the Capybara server for JS feature specs only
Updating documentation to include a missing step in the update procedure
Eager-load the Capybara server to prevent timeouts
Increase Capybara's timeout
Add metrics button to Environment Overview page
Fix link to Jira service documentation
Handle parsing OpenBSD ps output properly to display sidekiq infos on ...
Eliminate unnecessary queries that add ~500 ms of load time for a large issue
20914 Limits line length for project home page
Allow users to import GitHub projects to subgroups
Update dpl CI example
Fix the docs:check:links job
Don't clean up the gitlab-test-fork_bare repo
Make GitLab use Gitaly for commit_is_ancestor
Remove unnecessary ORDER BY clause from `forked_to_project_id` subquery
...
Diffstat (limited to 'spec/models/namespace_spec.rb')
-rw-r--r-- | spec/models/namespace_spec.rb | 79 |
1 files changed, 69 insertions, 10 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 95f4785060c..e1bfd20a6aa 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -129,10 +129,10 @@ describe Namespace, models: true do end end - describe '#move_dir' do + describe '#move_dir', repository: true do before do @namespace = create :namespace - @project = create(:empty_project, namespace: @namespace) + @project = create(:project_empty_repo, namespace: @namespace) allow(@namespace).to receive(:path_changed?).and_return(true) end @@ -141,9 +141,9 @@ describe Namespace, models: true do end it "moves dir if path changed" do - new_path = @namespace.path + "_new" - allow(@namespace).to receive(:path_was).and_return(@namespace.path) - allow(@namespace).to receive(:path).and_return(new_path) + new_path = @namespace.full_path + "_new" + allow(@namespace).to receive(:full_path_was).and_return(@namespace.full_path) + allow(@namespace).to receive(:full_path).and_return(new_path) expect(@namespace).to receive(:remove_exports!) expect(@namespace.move_dir).to be_truthy end @@ -163,16 +163,75 @@ describe Namespace, models: true do it { expect { @namespace.move_dir }.to raise_error('Namespace cannot be moved, because at least one project has images in container registry') } end + + context 'renaming a sub-group' do + let(:parent) { create(:group, name: 'parent', path: 'parent') } + let(:child) { create(:group, name: 'child', path: 'child', parent: parent) } + let!(:project) { create(:project_empty_repo, path: 'the-project', namespace: child) } + let(:uploads_dir) { File.join(CarrierWave.root, 'uploads', 'parent') } + let(:pages_dir) { File.join(TestEnv.pages_path, 'parent') } + + before do + FileUtils.mkdir_p(File.join(uploads_dir, 'child', 'the-project')) + FileUtils.mkdir_p(File.join(pages_dir, 'child', 'the-project')) + end + + it 'correctly moves the repository, uploads and pages' do + expected_repository_path = File.join(TestEnv.repos_path, 'parent', 'renamed', 'the-project.git') + expected_upload_path = File.join(uploads_dir, 'renamed', 'the-project') + expected_pages_path = File.join(pages_dir, 'renamed', 'the-project') + + child.update_attributes!(path: 'renamed') + + expect(File.directory?(expected_repository_path)).to be(true) + expect(File.directory?(expected_upload_path)).to be(true) + expect(File.directory?(expected_pages_path)).to be(true) + end + end end - describe '#rm_dir', 'callback' do - let!(:project) { create(:empty_project, namespace: namespace) } - let!(:path) { File.join(Gitlab.config.repositories.storages.default['path'], namespace.full_path) } + describe '#rm_dir', 'callback', repository: true do + let!(:project) { create(:project_empty_repo, namespace: namespace) } + let(:repository_storage_path) { Gitlab.config.repositories.storages.default['path'] } + let(:path_in_dir) { File.join(repository_storage_path, namespace.full_path) } + let(:deleted_path) { namespace.full_path.gsub(namespace.path, "#{namespace.full_path}+#{namespace.id}+deleted") } + let(:deleted_path_in_dir) { File.join(repository_storage_path, deleted_path) } + + it 'renames its dirs when deleted' do + allow(GitlabShellWorker).to receive(:perform_in) - it "removes its dirs when deleted" do namespace.destroy - expect(File.exist?(path)).to be(false) + expect(File.exist?(deleted_path_in_dir)).to be(true) + end + + it 'schedules the namespace for deletion' do + expect(GitlabShellWorker).to receive(:perform_in).with(5.minutes, :rm_namespace, repository_storage_path, deleted_path) + + namespace.destroy + end + + context 'in sub-groups' do + let(:parent) { create(:namespace, path: 'parent') } + let(:child) { create(:namespace, parent: parent, path: 'child') } + let!(:project) { create(:project_empty_repo, namespace: child) } + let(:path_in_dir) { File.join(repository_storage_path, 'parent', 'child') } + let(:deleted_path) { File.join('parent', "child+#{child.id}+deleted") } + let(:deleted_path_in_dir) { File.join(repository_storage_path, deleted_path) } + + it 'renames its dirs when deleted' do + allow(GitlabShellWorker).to receive(:perform_in) + + child.destroy + + expect(File.exist?(deleted_path_in_dir)).to be(true) + end + + it 'schedules the namespace for deletion' do + expect(GitlabShellWorker).to receive(:perform_in).with(5.minutes, :rm_namespace, repository_storage_path, deleted_path) + + child.destroy + end end it 'removes the exports folder' do |