1
0

preview_cards_vacuum_spec.rb 1016 B

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