cleanup_namespaceless_pending_delete_projects_spec.rb 1.43 KB
Newer Older
1 2 3
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170502101023_cleanup_namespaceless_pending_delete_projects.rb')

4
describe CleanupNamespacelessPendingDeleteProjects, :migration, schema: 20180222043024 do
5 6
  let(:projects) { table(:projects) }

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

  describe '#up' do
    it 'only cleans up pending delete projects' do
15 16 17
      projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1)
      projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ee', namespace_id: 2, pending_delete: true)
      project = Project.new(pending_delete: true, namespace_id: nil)
18 19
      project.save(validate: false)

Douwe Maan's avatar
Douwe Maan committed
20
      expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id]])
21 22 23 24 25

      described_class.new.up
    end

    it 'does nothing when no pending delete projects without namespace found' do
26 27
      projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1)
      projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ee', namespace_id: 2, pending_delete: true)
28 29

      expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async)
30 31 32 33 34

      described_class.new.up
    end
  end
end