forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_index_job_spec.rb
31 lines (23 loc) · 975 Bytes
/
search_index_job_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
require 'rails_helper'
RSpec.describe SearchIndexJob, type: :job do
it 'calls search_index_update_backend on matching record' do
user = create(:user)
allow(::User).to receive(:find_by).with(id: user.id).and_return(user)
allow(user).to receive(:search_index_update_backend)
described_class.perform_now('User', user.id)
expect(user).to have_received(:search_index_update_backend)
end
it "doesn't perform for non existing records" do
id = 9999
allow(::User).to receive(:find_by).with(id: id).and_return(nil)
allow(SearchIndexBackend).to receive(:add)
described_class.perform_now('User', id)
expect(SearchIndexBackend).not_to have_received(:add)
end
it 'retries on exception' do
allow(::User).to receive(:find_by).and_raise(RuntimeError)
described_class.perform_now('User', 1)
expect(described_class).to have_been_enqueued
end
end