summaryrefslogtreecommitdiff
path: root/spec/services/destroy_group_service_spec.rb
blob: da72464360490627f451a08b7601aa8860cfbab8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'spec_helper'

describe DestroyGroupService, services: true do
  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" }

  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) }
    end

    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

        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 }
      end

      context 'Sidekiq fake' do
        before do
          # Dont run sidekiq to check if renamed repository exists
          Sidekiq::Testing.fake! { destroy_group(group, user, async) }
        end

        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 }
      end
    end

    def destroy_group(group, user, async)
      if async
        DestroyGroupService.new(group, user).async_execute
      else
        DestroyGroupService.new(group, user).execute
      end
    end
  end

  describe 'asynchronous delete' do
    it_behaves_like 'group destruction', true
  end

  describe 'synchronous delete' do
    it_behaves_like 'group destruction', false
  end
end