has_collection_update_examples.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'HasCollectionUpdate' do |collection_factory:|
  3. describe '#push_collection_to_clients', performs_jobs: true do
  4. subject { create(collection_factory) }
  5. context 'creating a record' do
  6. it 'enqueues a CollectionUpdateJob job' do
  7. expect { subject }.to have_enqueued_job(CollectionUpdateJob).with(described_class.name)
  8. end
  9. end
  10. context 'record exists' do
  11. before do
  12. subject
  13. clear_jobs
  14. end
  15. context 'attribute updated' do
  16. context 'name' do
  17. it 'enqueues a CollectionUpdateJob job' do
  18. expect do
  19. if subject.respond_to?(:name)
  20. subject.name = 'New name'
  21. else
  22. # EmailAdress has no `name` attribute
  23. subject.realname = 'New name'
  24. end
  25. subject.save!
  26. end.to have_enqueued_job(CollectionUpdateJob).with(described_class.name)
  27. end
  28. end
  29. context 'updated_at' do
  30. it 'enqueues a CollectionUpdateJob job' do
  31. expect { subject.touch }.to have_enqueued_job(CollectionUpdateJob).with(described_class.name)
  32. end
  33. end
  34. end
  35. context 'record is deleted' do
  36. it 'enqueues a CollectionUpdateJob job' do
  37. expect { subject.destroy! }.to have_enqueued_job(CollectionUpdateJob).with(described_class.name)
  38. end
  39. end
  40. end
  41. end
  42. end