1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.shared_examples 'Taskbar::HasAttachments' do
- let(:form_id) { SecureRandom.uuid }
- describe '.with_form_id' do
- before do
- create(:taskbar)
- create_list(:taskbar, 2, state: { form_id: form_id })
- end
- it 'get list of all form ids' do
- expect(described_class.with_form_id.filter_map(&:persisted_form_id)).to eq([form_id, form_id])
- end
- end
- describe 'delete attachments in upload cache' do
- let(:state) { nil }
- let(:taskbar) do
- taskbar = create(:taskbar, state: state)
- UploadCache.new(form_id).add(
- data: 'Some Example',
- filename: 'another_example.txt',
- preferences: {
- 'Content-Type' => 'text/plain',
- }
- )
- taskbar
- end
- # required for adding items to the Store
- before do
- UserInfo.current_user_id = 1
- # initialize taskbar to have different store counts in expect test
- taskbar
- end
- context 'when ticket create' do
- let(:state) do
- { form_id: form_id }
- end
- it 'delete attachments in upload cache after destroy' do
- expect { taskbar.destroy }.to change(Store, :count).by(-1)
- end
- end
- context 'when ticket zoom' do
- let(:state) do
- { ticket: {}, article: { form_id: form_id } }
- end
- it 'delete attachments in upload cache after destroy' do
- expect { taskbar.destroy }.to change(Store, :count).by(-1)
- end
- end
- end
- end
|