upload_cache_cleanup_job_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe UploadCacheCleanupJob, type: :job do
  4. context 'when upload cache exists' do
  5. let(:upload_cache) { UploadCache.new(1337) }
  6. before do
  7. UserInfo.current_user_id = 1
  8. upload_cache.add(
  9. data: 'current example',
  10. filename: 'current.txt',
  11. preferences: {
  12. 'Content-Type' => 'text/plain',
  13. },
  14. )
  15. travel_to 1.month.ago
  16. # create one taskbar and related upload cache entry, which should not be deleted
  17. create(:taskbar, state: { form_id: 9999 })
  18. UploadCache.new(9999).add(
  19. data: 'Some Example with related Taskbar',
  20. filename: 'another_example_with_taskbar.txt',
  21. preferences: {
  22. 'Content-Type' => 'text/plain',
  23. }
  24. )
  25. 3.times do
  26. upload_cache.add(
  27. data: 'hello world',
  28. filename: 'some.txt',
  29. preferences: {
  30. 'Content-Type' => 'text/plain',
  31. },
  32. )
  33. end
  34. travel_back
  35. end
  36. it 'cleanup the store items which are expired with job' do
  37. expect { described_class.perform_now }.to change(Store, :count).by(-3)
  38. end
  39. end
  40. context 'when upload cache does not exist' do
  41. it 'does not crash' do
  42. expect { described_class.perform_now }.not_to raise_error
  43. end
  44. end
  45. end