diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-05-22 13:24:14 +0300 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-05-23 17:58:40 +0300 |
commit | 0230ca839a2ec8debcbe4476c3deed8b422bf451 (patch) | |
tree | 5a4435de36faf3ef696cf855491367097e2e30e5 | |
parent | 4d674bd38c8a3568f6e1295c25c902ef10151aef (diff) |
Check if note's noteable is not nil when checking resolvability
This can occur when a note is added to a commit and then this commit
is deleted.
-rw-r--r-- | app/models/concerns/resolvable_note.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/jprovazn-fix-resolvable.yml | 5 | ||||
-rw-r--r-- | spec/models/concerns/resolvable_note_spec.rb | 8 |
3 files changed, 14 insertions, 1 deletions
diff --git a/app/models/concerns/resolvable_note.rb b/app/models/concerns/resolvable_note.rb index 668c5a079e3..4a0f8b92b3a 100644 --- a/app/models/concerns/resolvable_note.rb +++ b/app/models/concerns/resolvable_note.rb @@ -32,7 +32,7 @@ module ResolvableNote # Keep this method in sync with the `potentially_resolvable` scope def potentially_resolvable? - RESOLVABLE_TYPES.include?(self.class.name) && noteable.supports_resolvable_notes? + RESOLVABLE_TYPES.include?(self.class.name) && noteable&.supports_resolvable_notes? end # Keep this method in sync with the `resolvable` scope diff --git a/changelogs/unreleased/jprovazn-fix-resolvable.yml b/changelogs/unreleased/jprovazn-fix-resolvable.yml new file mode 100644 index 00000000000..e17c409e290 --- /dev/null +++ b/changelogs/unreleased/jprovazn-fix-resolvable.yml @@ -0,0 +1,5 @@ +--- +title: Fix resolvable check if note's commit could not be found. +merge_request: +author: +type: fixed diff --git a/spec/models/concerns/resolvable_note_spec.rb b/spec/models/concerns/resolvable_note_spec.rb index 91591017587..fcb5250278e 100644 --- a/spec/models/concerns/resolvable_note_spec.rb +++ b/spec/models/concerns/resolvable_note_spec.rb @@ -326,4 +326,12 @@ describe Note, ResolvableNote do end end end + + describe "#potentially_resolvable?" do + it 'returns false if noteable could not be found' do + allow(subject).to receive(:noteable).and_return(nil) + + expect(subject.potentially_resolvable?).to be_falsey + end + end end |