preview_cards_vacuum_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Vacuum::PreviewCardsVacuum do
  4. subject { described_class.new(retention_period) }
  5. let(:retention_period) { 7.days }
  6. describe '#perform' do
  7. let!(:orphaned_preview_card) { Fabricate(:preview_card, created_at: 2.days.ago) }
  8. let!(:old_preview_card) { Fabricate(:preview_card, updated_at: (retention_period + 1.day).ago) }
  9. let!(:new_preview_card) { Fabricate(:preview_card) }
  10. before do
  11. old_preview_card.statuses << Fabricate(:status)
  12. new_preview_card.statuses << Fabricate(:status)
  13. end
  14. it 'handles preview card cleanup' do
  15. subject.perform
  16. expect(old_preview_card.reload.image) # last updated before retention period
  17. .to be_blank
  18. expect(new_preview_card.reload.image) # last updated within the retention period
  19. .to_not be_blank
  20. expect(new_preview_card.reload) # Keep attached preview cards
  21. .to be_persisted
  22. expect(orphaned_preview_card.reload) # keep orphaned cards in the retention period
  23. .to be_persisted
  24. end
  25. end
  26. end