cleanup_namespaceless_pending_delete_projects_spec.rb 1.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170502101023_cleanup_namespaceless_pending_delete_projects.rb')

describe CleanupNamespacelessPendingDeleteProjects do
  before do
    # Stub after_save callbacks that will fail when Project has no namespace
    allow_any_instance_of(Project).to receive(:ensure_dir_exist).and_return(nil)
    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
      create(:empty_project)
      create(:empty_project, pending_delete: true)
      project = build(:empty_project, pending_delete: true, namespace_id: nil)
      project.save(validate: false)

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

      described_class.new.up
    end

    it 'does nothing when no pending delete projects without namespace found' do
      create(:empty_project)
      create(:empty_project, pending_delete: true)

      expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async)
28 29 30 31 32

      described_class.new.up
    end
  end
end