Skip to content

Commit

Permalink
[WIP] Increasing coverage for ReindexJob
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Jun 18, 2018
1 parent 1fdba19 commit 0e78a54
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/jobs/spotlight/reindex_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def resource_list(exhibit_or_resources)
end
end

# If it has been passed to the Job, retrieve the log entry for the reindexing
# @param job [Spotlight::ReindexJob]
# @return [Spotlight::ReindexingLogEntry]
def log_entry(job)
job.arguments.second if job.arguments.second.is_a?(Spotlight::ReindexingLogEntry)
end
Expand Down
32 changes: 32 additions & 0 deletions spec/jobs/spotlight/reindex_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,36 @@
expect(resources.first).to have_received(:reindex)
expect(resources.last).to have_received(:reindex)
end

context 'with an existing log entry' do
let(:log_entry) { Spotlight::ReindexingLogEntry.new }
let(:resource1) { instance_double(IIIFResource, reindex: true) }
let(:resource2) { instance_double(IIIFResource, reindex: true) }
let(:resources) { [resource1, resource2] }
let(:builder) { instance_double(Spotlight::SolrDocumentBuilder) }

before do
allow(builder).to receive(:documents_to_index).and_return([0])
allow(resource1).to receive(:document_builder).and_return(builder)
allow(resource2).to receive(:document_builder).and_return(builder)
allow(log_entry).to receive(:update)
end

it 'estimates the number of items being reindexed' do
described_class.perform_now(resources, log_entry)
expect(log_entry).to have_received(:update).with(items_reindexed_estimate: 2)
end

context 'when the job fails' do
before do
allow(resource1).to receive(:reindex).and_raise(StandardError)
allow(log_entry).to receive(:failed!)
end

it 'sets the state of the job to failure within the log entry' do
expect { described_class.perform_now(resources, log_entry) }.to raise_error(StandardError)
expect(log_entry).to have_received(:failed!)
end
end
end
end

0 comments on commit 0e78a54

Please sign in to comment.