Commit 0f3b20cd authored by Kerri Miller's avatar Kerri Miller

Add guard clause to ensure incoming params

When diff_note_id is missing, exit early instead of attempting to search
with a nil or empty string, which will raise an
ActiveRecord::RecordNotFound exception.

Changelog: fixed
parent 2fac068e
......@@ -10,6 +10,8 @@ class CreateNoteDiffFileWorker # rubocop:disable Scalability/IdempotentWorker
feature_category :code_review
def perform(diff_note_id)
return unless diff_note_id.present?
diff_note = DiffNote.find_by_id(diff_note_id) # rubocop: disable CodeReuse/ActiveRecord
diff_note&.create_diff_file
......
......@@ -23,5 +23,14 @@ RSpec.describe CreateNoteDiffFileWorker do
described_class.new.perform(non_existing_record_id)
end
end
context "when called with a missing diff_note id" do
it "returns nil without creating diff file" do
expect_any_instance_of(DiffNote).not_to receive(:create_diff_file)
.and_call_original
described_class.new.perform(nil)
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