has_attachments_examples.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.shared_examples 'Taskbar::HasAttachments' do
  4. let(:form_id) { SecureRandom.uuid }
  5. describe '.with_form_id' do
  6. before do
  7. create(:taskbar)
  8. create_list(:taskbar, 2, state: { form_id: form_id })
  9. end
  10. it 'get list of all form ids' do
  11. expect(described_class.with_form_id.filter_map(&:persisted_form_id)).to eq([form_id, form_id])
  12. end
  13. end
  14. describe 'delete attachments in upload cache' do
  15. let(:state) { nil }
  16. let(:taskbar) do
  17. taskbar = create(:taskbar, state: state)
  18. UploadCache.new(form_id).add(
  19. data: 'Some Example',
  20. filename: 'another_example.txt',
  21. preferences: {
  22. 'Content-Type' => 'text/plain',
  23. }
  24. )
  25. taskbar
  26. end
  27. # required for adding items to the Store
  28. before do
  29. UserInfo.current_user_id = 1
  30. # initialize taskbar to have different store counts in expect test
  31. taskbar
  32. end
  33. context 'when ticket create' do
  34. let(:state) do
  35. { form_id: form_id }
  36. end
  37. it 'delete attachments in upload cache after destroy' do
  38. expect { taskbar.destroy }.to change(Store, :count).by(-1)
  39. end
  40. end
  41. context 'when ticket zoom' do
  42. let(:state) do
  43. { ticket: {}, article: { form_id: form_id } }
  44. end
  45. it 'delete attachments in upload cache after destroy' do
  46. expect { taskbar.destroy }.to change(Store, :count).by(-1)
  47. end
  48. end
  49. end
  50. end