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
ad67c419
Commit
ad67c419
authored
Oct 09, 2019
by
Patrick Derichs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scopes to note
parent
f5bf17c9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
4 deletions
+56
-4
app/models/note.rb
app/models/note.rb
+3
-0
app/services/system_notes/issuables_service.rb
app/services/system_notes/issuables_service.rb
+2
-4
spec/models/note_spec.rb
spec/models/note_spec.rb
+51
-0
No files found.
app/models/note.rb
View file @
ad67c419
...
...
@@ -145,6 +145,9 @@ class Note < ApplicationRecord
end
scope
:with_metadata
,
->
{
includes
(
:system_note_metadata
)
}
scope
:for_note_or_capitalized_note
,
->
(
text
)
{
where
(
note:
[
text
,
text
.
capitalize
])
}
scope
:like_note_or_capitalized_note
,
->
(
text
)
{
where
(
'(note LIKE ? OR note LIKE ?)'
,
text
,
text
.
capitalize
)
}
after_initialize
:ensure_discussion_id
before_validation
:nullify_blank_type
,
:nullify_blank_line_code
before_validation
:set_discussion_id
,
on: :create
...
...
app/services/system_notes/issuables_service.rb
View file @
ad67c419
...
...
@@ -288,18 +288,16 @@ module SystemNotes
"
#{
self
.
class
.
cross_reference_note_prefix
}#{
gfm_reference
}
"
end
# rubocop: disable CodeReuse/ActiveRecord
def
notes_for_mentioner
(
mentioner
,
noteable
,
notes
)
if
mentioner
.
is_a?
(
Commit
)
text
=
"
#{
self
.
class
.
cross_reference_note_prefix
}
%
#{
mentioner
.
to_reference
(
nil
)
}
"
notes
.
where
(
'(note LIKE ? OR note LIKE ?)'
,
text
,
text
.
capitalize
)
notes
.
like_note_or_capitalized_note
(
text
)
else
gfm_reference
=
mentioner
.
gfm_reference
(
noteable
.
project
||
noteable
.
group
)
text
=
cross_reference_note_content
(
gfm_reference
)
notes
.
where
(
note:
[
text
,
text
.
capitalize
]
)
notes
.
for_note_or_capitalized_note
(
text
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
self
.
cross_reference_note_prefix
'mentioned in '
...
...
spec/models/note_spec.rb
View file @
ad67c419
...
...
@@ -981,4 +981,55 @@ describe Note do
expect
(
note
.
parent
).
to
be_nil
end
end
describe
'scopes'
do
let_it_be
(
:note1
)
{
create
(
:note
,
note:
'Test 345'
)
}
let_it_be
(
:note2
)
{
create
(
:note
,
note:
'Test 789'
)
}
describe
'#for_note_or_capitalized_note'
do
it
'returns the expected matching note'
do
notes
=
described_class
.
for_note_or_capitalized_note
(
'Test 345'
)
expect
(
notes
.
count
).
to
eq
(
1
)
expect
(
notes
.
first
.
id
).
to
eq
(
note1
.
id
)
end
it
'returns the expected capitalized note'
do
notes
=
described_class
.
for_note_or_capitalized_note
(
'test 345'
)
expect
(
notes
.
count
).
to
eq
(
1
)
expect
(
notes
.
first
.
id
).
to
eq
(
note1
.
id
)
end
it
'does not support pattern matching'
do
notes
=
described_class
.
for_note_or_capitalized_note
(
'test%'
)
expect
(
notes
.
count
).
to
eq
(
0
)
end
end
describe
'#like_note_or_capitalized_note'
do
it
'returns the expected matching note'
do
notes
=
described_class
.
like_note_or_capitalized_note
(
'Test 345'
)
expect
(
notes
.
count
).
to
eq
(
1
)
expect
(
notes
.
first
.
id
).
to
eq
(
note1
.
id
)
end
it
'returns the expected capitalized note'
do
notes
=
described_class
.
like_note_or_capitalized_note
(
'test 345'
)
expect
(
notes
.
count
).
to
eq
(
1
)
expect
(
notes
.
first
.
id
).
to
eq
(
note1
.
id
)
end
it
'supports pattern matching'
do
notes
=
described_class
.
like_note_or_capitalized_note
(
'test%'
)
expect
(
notes
.
count
).
to
eq
(
2
)
expect
(
notes
.
first
.
id
).
to
eq
(
note1
.
id
)
expect
(
notes
.
second
.
id
).
to
eq
(
note2
.
id
)
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