diff --git a/app/jobs/search_index_job.rb b/app/jobs/search_index_job.rb index a1d7053e4..b301d4685 100644 --- a/app/jobs/search_index_job.rb +++ b/app/jobs/search_index_job.rb @@ -16,7 +16,7 @@ class SearchIndexJob < ApplicationJob @object = object @o_id = o_id - record = @object.constantize.lookup(id: @o_id) + record = @object.constantize.find_by(id: @o_id) return if !exists?(record) update_search_index(record) @@ -31,7 +31,7 @@ class SearchIndexJob < ApplicationJob def exists?(record) return true if record - Rails.logger.info "Can't index #{@object}.lookup(id: #{@o_id}), no such record found" + Rails.logger.info "Can't index #{@object}.find_by(id: #{@o_id}), no such record found" false end end diff --git a/spec/jobs/search_index_job_spec.rb b/spec/jobs/search_index_job_spec.rb index 32655b6da..703d5094d 100644 --- a/spec/jobs/search_index_job_spec.rb +++ b/spec/jobs/search_index_job_spec.rb @@ -4,7 +4,7 @@ RSpec.describe SearchIndexJob, type: :job do it 'calls search_index_update_backend on matching record' do user = create(:user) - allow(::User).to receive(:lookup).with(id: user.id).and_return(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) @@ -13,7 +13,7 @@ RSpec.describe SearchIndexJob, type: :job do it "doesn't perform for non existing records" do id = 9999 - allow(::User).to receive(:lookup).with(id: id).and_return(nil) + allow(::User).to receive(:find_by).with(id: id).and_return(nil) allow(SearchIndexBackend).to receive(:add) described_class.perform_now('User', id) @@ -21,7 +21,7 @@ RSpec.describe SearchIndexJob, type: :job do end it 'retries on exception' do - allow(::User).to receive(:lookup).and_raise(RuntimeError) + allow(::User).to receive(:find_by).and_raise(RuntimeError) described_class.perform_now('User', 1) expect(described_class).to have_been_enqueued