imports_vacuum_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Vacuum::ImportsVacuum do
  4. subject { described_class.new }
  5. let!(:old_unconfirmed) { Fabricate(:bulk_import, state: :unconfirmed, created_at: 2.days.ago) }
  6. let!(:new_unconfirmed) { Fabricate(:bulk_import, state: :unconfirmed, created_at: 10.seconds.ago) }
  7. let!(:recent_ongoing) { Fabricate(:bulk_import, state: :in_progress, created_at: 20.minutes.ago) }
  8. let!(:recent_finished) { Fabricate(:bulk_import, state: :finished, created_at: 1.day.ago) }
  9. let!(:old_finished) { Fabricate(:bulk_import, state: :finished, created_at: 2.months.ago) }
  10. describe '#perform' do
  11. it 'cleans up the expected imports' do
  12. expect { subject.perform }
  13. .to change { ordered_bulk_imports.pluck(:id) }
  14. .from(original_import_ids)
  15. .to(remaining_import_ids)
  16. end
  17. def ordered_bulk_imports
  18. BulkImport.order(id: :asc)
  19. end
  20. def original_import_ids
  21. [old_unconfirmed, new_unconfirmed, recent_ongoing, recent_finished, old_finished].map(&:id)
  22. end
  23. def vacuumed_import_ids
  24. [old_unconfirmed, old_finished].map(&:id)
  25. end
  26. def remaining_import_ids
  27. original_import_ids - vacuumed_import_ids
  28. end
  29. end
  30. end