2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-01-15 12:32:14 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe SearchIndexJob, type: :job do
|
|
|
|
|
|
|
|
it 'calls search_index_update_backend on matching record' do
|
|
|
|
user = create(:user)
|
2021-01-19 11:07:42 +00:00
|
|
|
allow(::User).to receive(:find_by).with(id: user.id).and_return(user)
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(user).to receive(:search_index_update_backend)
|
2019-01-15 12:32:14 +00:00
|
|
|
|
|
|
|
described_class.perform_now('User', user.id)
|
2020-10-22 13:57:01 +00:00
|
|
|
expect(user).to have_received(:search_index_update_backend)
|
2019-01-15 12:32:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't perform for non existing records" do
|
|
|
|
id = 9999
|
2021-01-19 11:07:42 +00:00
|
|
|
allow(::User).to receive(:find_by).with(id: id).and_return(nil)
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(SearchIndexBackend).to receive(:add)
|
|
|
|
|
2019-01-15 12:32:14 +00:00
|
|
|
described_class.perform_now('User', id)
|
2020-10-22 13:57:01 +00:00
|
|
|
expect(SearchIndexBackend).not_to have_received(:add)
|
2019-01-15 12:32:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'retries on exception' do
|
2021-01-19 11:07:42 +00:00
|
|
|
allow(::User).to receive(:find_by).and_raise(RuntimeError)
|
2020-10-22 13:57:01 +00:00
|
|
|
|
2019-01-15 12:32:14 +00:00
|
|
|
described_class.perform_now('User', 1)
|
2019-09-16 15:04:17 +00:00
|
|
|
expect(described_class).to have_been_enqueued
|
2019-01-15 12:32:14 +00:00
|
|
|
end
|
|
|
|
end
|