BigW Consortium Gitlab

remove_unreferenced_lfs_objects_worker_spec.rb 1.72 KB
Newer Older
1 2 3
require 'spec_helper'

describe RemoveUnreferencedLfsObjectsWorker do
4
  let(:worker) { described_class.new }
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

  describe '#perform' do
    let!(:unreferenced_lfs_object1) { create(:lfs_object, oid: '1') }
    let!(:unreferenced_lfs_object2) { create(:lfs_object, oid: '2') }
    let!(:project1) { create(:empty_project, lfs_enabled: true) }
    let!(:project2) { create(:empty_project, lfs_enabled: true) }
    let!(:referenced_lfs_object1) { create(:lfs_object, oid: '3') }
    let!(:referenced_lfs_object2) { create(:lfs_object, oid: '4') }
    let!(:lfs_objects_project1_1) do
      create(:lfs_objects_project,
                project: project1,
                lfs_object: referenced_lfs_object1
            )
    end
    let!(:lfs_objects_project2_1) do
      create(:lfs_objects_project,
                project: project2,
                lfs_object: referenced_lfs_object1
            )
    end
    let!(:lfs_objects_project1_2) do
      create(:lfs_objects_project,
                project: project1,
                lfs_object: referenced_lfs_object2
            )
    end

    it 'removes unreferenced lfs objects' do
      worker.perform

      expect(LfsObject.where(id: unreferenced_lfs_object1.id)).to be_empty
      expect(LfsObject.where(id: unreferenced_lfs_object2.id)).to be_empty
    end

    it 'leaves referenced lfs objects' do
      worker.perform

      expect(referenced_lfs_object1.reload).to be_present
      expect(referenced_lfs_object2.reload).to be_present
    end

    it 'removes unreferenced lfs objects after project removal' do
      project1.destroy

      worker.perform

      expect(referenced_lfs_object1.reload).to be_present
      expect(LfsObject.where(id: referenced_lfs_object2.id)).to be_empty
    end
  end
end