Commit cf72b317 authored by Sashi Kumar's avatar Sashi Kumar

Fix mentions in Personal snippets

parent cbb0a680
...@@ -2,4 +2,8 @@ ...@@ -2,4 +2,8 @@
class PersonalSnippet < Snippet class PersonalSnippet < Snippet
include WithUploads include WithUploads
def skip_project_check?
true
end
end end
---
title: Fix bug in personal snippets when somebody is mentioned
merge_request: 29835
author: Sashi Kumar
type: fixed
...@@ -325,3 +325,20 @@ describe Snippet, 'Mentionable' do ...@@ -325,3 +325,20 @@ describe Snippet, 'Mentionable' do
end end
end end
end end
describe PersonalSnippet, 'Mentionable' do
describe '#store_mentions!' do
it_behaves_like 'mentions in description', :personal_snippet
it_behaves_like 'mentions in notes', :personal_snippet do
let(:note) { create(:note_on_personal_snippet) }
let(:mentionable) { note.noteable }
end
end
describe 'load mentions' do
it_behaves_like 'load mentions from DB', :personal_snippet do
let(:note) { create(:note_on_personal_snippet) }
let(:mentionable) { note.noteable }
end
end
end
...@@ -252,12 +252,12 @@ describe Snippets::CreateService do ...@@ -252,12 +252,12 @@ describe Snippets::CreateService do
end end
end end
shared_examples 'after_save callback to store_mentions' do shared_examples 'after_save callback to store_mentions' do |mentionable_class|
context 'when mentionable attributes change' do context 'when mentionable attributes change' do
let(:extra_opts) { { description: "Description with #{user.to_reference}" } } let(:extra_opts) { { description: "Description with #{user.to_reference}" } }
it 'saves mentions' do it 'saves mentions' do
expect_next_instance_of(Snippet) do |instance| expect_next_instance_of(mentionable_class) do |instance|
expect(instance).to receive(:store_mentions!).and_call_original expect(instance).to receive(:store_mentions!).and_call_original
end end
expect(snippet.user_mentions.count).to eq 1 expect(snippet.user_mentions.count).to eq 1
...@@ -266,7 +266,7 @@ describe Snippets::CreateService do ...@@ -266,7 +266,7 @@ describe Snippets::CreateService do
context 'when mentionable attributes do not change' do context 'when mentionable attributes do not change' do
it 'does not call store_mentions' do it 'does not call store_mentions' do
expect_next_instance_of(Snippet) do |instance| expect_next_instance_of(mentionable_class) do |instance|
expect(instance).not_to receive(:store_mentions!) expect(instance).not_to receive(:store_mentions!)
end end
expect(snippet.user_mentions.count).to eq 0 expect(snippet.user_mentions.count).to eq 0
...@@ -277,7 +277,7 @@ describe Snippets::CreateService do ...@@ -277,7 +277,7 @@ describe Snippets::CreateService do
it 'does not call store_mentions' do it 'does not call store_mentions' do
base_opts.delete(:title) base_opts.delete(:title)
expect_next_instance_of(Snippet) do |instance| expect_next_instance_of(mentionable_class) do |instance|
expect(instance).not_to receive(:store_mentions!) expect(instance).not_to receive(:store_mentions!)
end end
expect(snippet.valid?).to be false expect(snippet.valid?).to be false
...@@ -298,7 +298,7 @@ describe Snippets::CreateService do ...@@ -298,7 +298,7 @@ describe Snippets::CreateService do
it_behaves_like 'snippet create data is tracked' it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails' it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository and files' it_behaves_like 'creates repository and files'
it_behaves_like 'after_save callback to store_mentions' it_behaves_like 'after_save callback to store_mentions', ProjectSnippet
end end
context 'when PersonalSnippet' do context 'when PersonalSnippet' do
...@@ -310,9 +310,7 @@ describe Snippets::CreateService do ...@@ -310,9 +310,7 @@ describe Snippets::CreateService do
it_behaves_like 'snippet create data is tracked' it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails' it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository and files' it_behaves_like 'creates repository and files'
pending('See https://gitlab.com/gitlab-org/gitlab/issues/30742') do it_behaves_like 'after_save callback to store_mentions', PersonalSnippet
it_behaves_like 'after_save callback to store_mentions'
end
end end
end end
end end
...@@ -210,6 +210,10 @@ RSpec.shared_examples 'mentions in description' do |mentionable_type| ...@@ -210,6 +210,10 @@ RSpec.shared_examples 'mentions in description' do |mentionable_type|
it 'stores no mentions' do it 'stores no mentions' do
expect(mentionable.user_mentions.count).to eq 0 expect(mentionable.user_mentions.count).to eq 0
end end
it 'renders description_html correctly' do
expect(mentionable.description_html).to include("<a href=\"/#{user.username}\" data-user=\"#{user.id}\"")
end
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