Commit 220728f1 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '339704-fix-discussion-note-without-author-error' into 'master'

Fix error when displaying discussions with note without an author

See merge request gitlab-org/gitlab!69270
parents ef9ed6a2 534419ba
......@@ -582,7 +582,7 @@ class Note < ApplicationRecord
end
def post_processed_cache_key
cache_key_items = [cache_key, author.cache_key]
cache_key_items = [cache_key, author&.cache_key]
cache_key_items << Digest::SHA1.hexdigest(redacted_note_html) if redacted_note_html.present?
cache_key_items.join(':')
......
......@@ -1576,6 +1576,14 @@ RSpec.describe Note do
expect(note.post_processed_cache_key).to eq("#{note.cache_key}:#{note.author.cache_key}")
end
context 'when note has no author' do
let(:note) { build(:note, author: nil) }
it 'returns cache key only' do
expect(note.post_processed_cache_key).to eq("#{note.cache_key}:")
end
end
context 'when note has redacted_note_html' do
let(:redacted_note_html) { 'redacted note html' }
......
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