Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cf72b317
Commit
cf72b317
authored
Apr 18, 2020
by
Sashi Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix mentions in Personal snippets
parent
cbb0a680
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
8 deletions
+36
-8
app/models/personal_snippet.rb
app/models/personal_snippet.rb
+4
-0
changelogs/unreleased/fix-mentions-personal-snippet.yml
changelogs/unreleased/fix-mentions-personal-snippet.yml
+5
-0
spec/models/concerns/mentionable_spec.rb
spec/models/concerns/mentionable_spec.rb
+17
-0
spec/services/snippets/create_service_spec.rb
spec/services/snippets/create_service_spec.rb
+6
-8
spec/support/shared_examples/models/mentionable_shared_examples.rb
...ort/shared_examples/models/mentionable_shared_examples.rb
+4
-0
No files found.
app/models/personal_snippet.rb
View file @
cf72b317
...
@@ -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
changelogs/unreleased/fix-mentions-personal-snippet.yml
0 → 100644
View file @
cf72b317
---
title
:
Fix bug in personal snippets when somebody is mentioned
merge_request
:
29835
author
:
Sashi Kumar
type
:
fixed
spec/models/concerns/mentionable_spec.rb
View file @
cf72b317
...
@@ -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
spec/services/snippets/create_service_spec.rb
View file @
cf72b317
...
@@ -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
spec/support/shared_examples/models/mentionable_shared_examples.rb
View file @
cf72b317
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment