search_index_job_spec.rb 969 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe SearchIndexJob, type: :job do
  4. it 'calls search_index_update_backend on matching record' do
  5. user = create(:user)
  6. allow(User).to receive(:find_by).with(id: user.id).and_return(user)
  7. allow(user).to receive(:search_index_update_backend)
  8. described_class.perform_now('User', user.id)
  9. expect(user).to have_received(:search_index_update_backend)
  10. end
  11. it "doesn't perform for non existing records" do
  12. id = 9999
  13. allow(User).to receive(:find_by).with(id: id).and_return(nil)
  14. allow(SearchIndexBackend).to receive(:add)
  15. described_class.perform_now('User', id)
  16. expect(SearchIndexBackend).not_to have_received(:add)
  17. end
  18. it 'retries on exception' do
  19. allow(User).to receive(:find_by).and_raise(RuntimeError)
  20. described_class.perform_now('User', 1)
  21. expect(described_class).to have_been_enqueued
  22. end
  23. end