Commit 580072f8 authored by Kerri Miller's avatar Kerri Miller

Guard against exceptions from unfound DiffNotes

If for some reason or another a DiffNote record is not found, we raise
an ActiveRecord::RecordNotFound error. These don't occur terribly often
(1-2 times/hour) but is worth guarding against.

Changelog: fixed
parent 812b7d2d
......@@ -10,8 +10,8 @@ class CreateNoteDiffFileWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :code_review
def perform(diff_note_id)
diff_note = DiffNote.find(diff_note_id)
diff_note = DiffNote.find_by_id(diff_note_id) # rubocop: disable CodeReuse/ActiveRecord
diff_note.create_diff_file
diff_note&.create_diff_file
end
end
......@@ -14,5 +14,14 @@ RSpec.describe CreateNoteDiffFileWorker do
described_class.new.perform(diff_note.id)
end
context "when the supplied diff_note_id doesn't belong to an existing DiffNote" do
it "returns nil without raising an error" do
expect_any_instance_of(DiffNote).not_to receive(:create_diff_file)
.and_call_original
described_class.new.perform(non_existing_record_id)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment