namespaceless_project_destroy_worker_spec.rb 2.14 KB
Newer Older
1
2
3
4
5
6
7
require 'spec_helper'

describe NamespacelessProjectDestroyWorker do
  subject { described_class.new }

  before do
    # Stub after_save callbacks that will fail when Project has no namespace
8
    allow_any_instance_of(Project).to receive(:ensure_storage_path_exists).and_return(nil)
9
10
11
12
13
14
    allow_any_instance_of(Project).to receive(:update_project_statistics).and_return(nil)
  end

  describe '#perform' do
    context 'project has namespace' do
      it 'does not do anything' do
15
        project = create(:project)
16

17
        subject.perform(project.id)
18
19
20
21
22
23
24

        expect(Project.unscoped.all).to include(project)
      end
    end

    context 'project has no namespace' do
      let!(:project) do
25
        project = build(:project, namespace_id: nil)
26
27
28
29
30
31
32
33
        project.save(validate: false)
        project
      end

      context 'project not a fork of another project' do
        it "truncates the project's team" do
          expect_any_instance_of(ProjectTeam).to receive(:truncate)

34
          subject.perform(project.id)
35
36
37
        end

        it 'deletes the project' do
38
          subject.perform(project.id)
39
40
41
42
43
44
45

          expect(Project.unscoped.all).not_to include(project)
        end

        it 'does not call unlink_fork' do
          is_expected.not_to receive(:unlink_fork)

46
          subject.perform(project.id)
47
48
49
50
51
        end

        it 'does not do anything in Project#remove_pages method' do
          expect(Gitlab::PagesTransfer).not_to receive(:new)

52
          subject.perform(project.id)
53
54
55
56
        end
      end

      context 'project forked from another' do
57
        let!(:parent_project) { create(:project) }
58
59
60
61
62
63
64
65

        before do
          create(:forked_project_link, forked_to_project: project, forked_from_project: parent_project)
        end

        it 'closes open merge requests' do
          merge_request = create(:merge_request, source_project: project, target_project: parent_project)

66
          subject.perform(project.id)
67
68
69
70
71

          expect(merge_request.reload).to be_closed
        end

        it 'destroys the link' do
72
          subject.perform(project.id)
73
74
75
76
77
78
79

          expect(parent_project.forked_project_links).to be_empty
        end
      end
    end
  end
end