Avoid 500's when commit is not reachable

This commit is contained in:
Oswaldo Ferreira 2019-02-19 16:29:10 -03:00
parent d9a761ed14
commit 5a89bcc4da
3 changed files with 14 additions and 1 deletions

View File

@ -77,7 +77,7 @@ class DiffNote < Note
end
def supports_suggestion?
return false unless noteable.supports_suggestion? && on_text?
return false unless noteable&.supports_suggestion? && on_text?
# We don't want to trigger side-effects of `diff_file` call.
return false unless file = latest_diff_file
return false unless line = file.line_for_position(self.position)

View File

@ -0,0 +1,5 @@
---
title: Avoid 500 when rendering users ATOM data
merge_request: 25408
author:
type: fixed

View File

@ -321,6 +321,14 @@ describe DiffNote do
end
describe '#supports_suggestion?' do
context 'when noteable does not exist' do
it 'returns false' do
allow(subject).to receive(:noteable) { nil }
expect(subject.supports_suggestion?).to be(false)
end
end
context 'when noteable does not support suggestions' do
it 'returns false' do
allow(subject.noteable).to receive(:supports_suggestion?) { false }