has_collection_update_examples.rb 1.4 KB

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