2015-09-11 14:41:01 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe DestroyGroupService, services: true do
|
2015-09-11 14:41:01 +05:30
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:group) { create(:group) }
|
|
|
|
let!(:project) { create(:project, namespace: group) }
|
|
|
|
let!(:gitlab_shell) { Gitlab::Shell.new }
|
|
|
|
let!(:remove_path) { group.path + "+#{group.id}+deleted" }
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
shared_examples 'group destruction' do |async|
|
|
|
|
context 'database records' do
|
|
|
|
before do
|
|
|
|
destroy_group(group, user, async)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(Group.all).not_to include(group) }
|
|
|
|
it { expect(Project.all).not_to include(project) }
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'file system' do
|
|
|
|
context 'Sidekiq inline' do
|
|
|
|
before do
|
|
|
|
# Run sidekiq immediatly to check that renamed dir will be removed
|
|
|
|
Sidekiq::Testing.inline! { destroy_group(group, user, async) }
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it { expect(gitlab_shell.exists?(project.repository_storage_path, group.path)).to be_falsey }
|
|
|
|
it { expect(gitlab_shell.exists?(project.repository_storage_path, remove_path)).to be_falsey }
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'Sidekiq fake' do
|
|
|
|
before do
|
|
|
|
# Dont run sidekiq to check if renamed repository exists
|
|
|
|
Sidekiq::Testing.fake! { destroy_group(group, user, async) }
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it { expect(gitlab_shell.exists?(project.repository_storage_path, group.path)).to be_falsey }
|
|
|
|
it { expect(gitlab_shell.exists?(project.repository_storage_path, remove_path)).to be_truthy }
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def destroy_group(group, user, async)
|
|
|
|
if async
|
|
|
|
DestroyGroupService.new(group, user).async_execute
|
|
|
|
else
|
|
|
|
DestroyGroupService.new(group, user).execute
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'asynchronous delete' do
|
|
|
|
it_behaves_like 'group destruction', true
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'synchronous delete' do
|
|
|
|
it_behaves_like 'group destruction', false
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|