Commit 4c69a0b1 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'sk/30742-fix-mentions-personal-snippet' into 'master'

Fix mentions in Personal snippets

See merge request gitlab-org/gitlab!29835
parents dfdf2362 cf72b317
......@@ -2,4 +2,8 @@
class PersonalSnippet < Snippet
include WithUploads
def skip_project_check?
true
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
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
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
let(:extra_opts) { { description: "Description with #{user.to_reference}" } }
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
end
expect(snippet.user_mentions.count).to eq 1
......@@ -266,7 +266,7 @@ describe Snippets::CreateService do
context 'when mentionable attributes do not change' 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!)
end
expect(snippet.user_mentions.count).to eq 0
......@@ -277,7 +277,7 @@ describe Snippets::CreateService do
it 'does not call store_mentions' do
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!)
end
expect(snippet.valid?).to be false
......@@ -298,7 +298,7 @@ describe Snippets::CreateService do
it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails'
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
context 'when PersonalSnippet' do
......@@ -310,9 +310,7 @@ describe Snippets::CreateService do
it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails'
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'
end
it_behaves_like 'after_save callback to store_mentions', PersonalSnippet
end
end
end
......@@ -210,6 +210,10 @@ RSpec.shared_examples 'mentions in description' do |mentionable_type|
it 'stores no mentions' do
expect(mentionable.user_mentions.count).to eq 0
end
it 'renders description_html correctly' do
expect(mentionable.description_html).to include("<a href=\"/#{user.username}\" data-user=\"#{user.id}\"")
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