search_index_job_spec.rb 898 B

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