search_index_job_spec.rb 728 B

123456789101112131415161718192021222324
  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. expect(::User).to receive(:lookup).with(id: user.id).and_return(user)
  6. expect(user).to receive(:search_index_update_backend)
  7. described_class.perform_now('User', user.id)
  8. end
  9. it "doesn't perform for non existing records" do
  10. id = 9999
  11. expect(::User).to receive(:lookup).with(id: id).and_return(nil)
  12. described_class.perform_now('User', id)
  13. end
  14. it 'retries on exception' do
  15. expect(::User).to receive(:lookup).and_raise(RuntimeError)
  16. described_class.perform_now('User', 1)
  17. expect(described_class).to have_been_enqueued
  18. end
  19. end