has_attachments_examples.rb 1.5 KB

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