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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
65ba4da9
Commit
65ba4da9
authored
Feb 25, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for keyword arguments in label reference method
parent
1fa7671f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
8 additions
and
11 deletions
+8
-11
app/models/label.rb
app/models/label.rb
+3
-6
app/services/system_note_service.rb
app/services/system_note_service.rb
+1
-1
spec/fixtures/markdown.md.erb
spec/fixtures/markdown.md.erb
+1
-1
spec/lib/banzai/filter/label_reference_filter_spec.rb
spec/lib/banzai/filter/label_reference_filter_spec.rb
+1
-1
spec/models/label_spec.rb
spec/models/label_spec.rb
+2
-2
No files found.
app/models/label.rb
View file @
65ba4da9
...
...
@@ -66,16 +66,13 @@ class Label < ActiveRecord::Base
#
# format - Symbol format to use (default: :id, optional: :name)
#
# Note that its argument differs from other objects implementing Referable. If
# a non-Symbol argument is given (such as a Project), it will default to :id.
#
# Examples:
#
# Label.first.to_reference # => "~1"
# Label.first.to_reference(:name) # => "~\"bug\""
# Label.first.to_reference(
format:
:name) # => "~\"bug\""
#
# Returns a String
def
to_reference
(
format
=
:id
)
def
to_reference
(
_from_project
=
nil
,
format:
:id
)
if
format
==
:name
&&
!
name
.
include?
(
'"'
)
%(#{self.class.reference_prefix}"#{name}")
else
...
...
app/services/system_note_service.rb
View file @
65ba4da9
...
...
@@ -66,7 +66,7 @@ class SystemNoteService
def
self
.
change_label
(
noteable
,
project
,
author
,
added_labels
,
removed_labels
)
labels_count
=
added_labels
.
count
+
removed_labels
.
count
references
=
->
(
label
)
{
label
.
to_reference
(
:id
)
}
references
=
->
(
label
)
{
label
.
to_reference
(
format:
:id
)
}
added_labels
=
added_labels
.
map
(
&
references
).
join
(
' '
)
removed_labels
=
removed_labels
.
map
(
&
references
).
join
(
' '
)
...
...
spec/fixtures/markdown.md.erb
View file @
65ba4da9
...
...
@@ -209,7 +209,7 @@ References should be parseable even inside _<%= merge_request.to_reference %>_ e
- Label by ID:
<%=
simple_label
.
to_reference
%>
- Label by name:
<%=
Label
.
reference_prefix
%><%=
simple_label
.
name
%>
- Label by name in quotes:
<%=
label
.
to_reference
(
:name
)
%>
- Label by name in quotes:
<%=
label
.
to_reference
(
format:
:name
)
%>
- Ignored in code: `
<%=
simple_label
.
to_reference
%>
`
- Ignored in links: [Link to
<%=
simple_label
.
to_reference
%>
](#label-link)
- Link to label by reference: [Label](
<%=
label
.
to_reference
%>
)
...
...
spec/lib/banzai/filter/label_reference_filter_spec.rb
View file @
65ba4da9
...
...
@@ -111,7 +111,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
context
'String-based multi-word references in quotes'
do
let
(
:label
)
{
create
(
:label
,
name:
'gfm references'
,
project:
project
)
}
let
(
:reference
)
{
label
.
to_reference
(
:name
)
}
let
(
:reference
)
{
label
.
to_reference
(
format:
:name
)
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
...
...
spec/models/label_spec.rb
View file @
65ba4da9
...
...
@@ -65,12 +65,12 @@ describe Label, models: true do
context
'using name'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
(
:name
)).
to
eq
%(~"#{label.name}")
expect
(
label
.
to_reference
(
format:
:name
)).
to
eq
%(~"#{label.name}")
end
it
'uses id when name contains double quote'
do
label
=
create
(
:label
,
name:
%q{"irony"}
)
expect
(
label
.
to_reference
(
:name
)).
to
eq
"~
#{
label
.
id
}
"
expect
(
label
.
to_reference
(
format:
:name
)).
to
eq
"~
#{
label
.
id
}
"
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