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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
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
Hide 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
...
@@ -66,16 +66,13 @@ class Label < ActiveRecord::Base
#
#
# format - Symbol format to use (default: :id, optional: :name)
# 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:
# Examples:
#
#
# Label.first.to_reference # => "~1"
# Label.first.to_reference
# => "~1"
# Label.first.to_reference(:name) # => "~\"bug\""
# Label.first.to_reference(
format:
:name) # => "~\"bug\""
#
#
# Returns a String
# Returns a String
def
to_reference
(
format
=
:id
)
def
to_reference
(
_from_project
=
nil
,
format:
:id
)
if
format
==
:name
&&
!
name
.
include?
(
'"'
)
if
format
==
:name
&&
!
name
.
include?
(
'"'
)
%(#{self.class.reference_prefix}"#{name}")
%(#{self.class.reference_prefix}"#{name}")
else
else
...
...
app/services/system_note_service.rb
View file @
65ba4da9
...
@@ -66,7 +66,7 @@ class SystemNoteService
...
@@ -66,7 +66,7 @@ class SystemNoteService
def
self
.
change_label
(
noteable
,
project
,
author
,
added_labels
,
removed_labels
)
def
self
.
change_label
(
noteable
,
project
,
author
,
added_labels
,
removed_labels
)
labels_count
=
added_labels
.
count
+
removed_labels
.
count
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
(
' '
)
added_labels
=
added_labels
.
map
(
&
references
).
join
(
' '
)
removed_labels
=
removed_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
...
@@ -209,7 +209,7 @@ References should be parseable even inside _<%= merge_request.to_reference %>_ e
- Label by ID:
<%=
simple_label
.
to_reference
%>
- Label by ID:
<%=
simple_label
.
to_reference
%>
- Label by name:
<%=
Label
.
reference_prefix
%><%=
simple_label
.
name
%>
- 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 code: `
<%=
simple_label
.
to_reference
%>
`
- Ignored in links: [Link to
<%=
simple_label
.
to_reference
%>
](#label-link)
- Ignored in links: [Link to
<%=
simple_label
.
to_reference
%>
](#label-link)
- Link to label by reference: [Label](
<%=
label
.
to_reference
%>
)
- 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
...
@@ -111,7 +111,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
context
'String-based multi-word references in quotes'
do
context
'String-based multi-word references in quotes'
do
let
(
:label
)
{
create
(
:label
,
name:
'gfm references'
,
project:
project
)
}
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
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
...
...
spec/models/label_spec.rb
View file @
65ba4da9
...
@@ -65,12 +65,12 @@ describe Label, models: true do
...
@@ -65,12 +65,12 @@ describe Label, models: true do
context
'using name'
do
context
'using name'
do
it
'returns a String reference to the object'
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
end
it
'uses id when name contains double quote'
do
it
'uses id when name contains double quote'
do
label
=
create
(
:label
,
name:
%q{"irony"}
)
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
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