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
acd877c7
Commit
acd877c7
authored
Feb 25, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cross project references support for label model
parent
65ba4da9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
app/models/label.rb
app/models/label.rb
+20
-4
spec/models/label_spec.rb
spec/models/label_spec.rb
+25
-1
No files found.
app/models/label.rb
View file @
acd877c7
...
...
@@ -70,16 +70,20 @@ class Label < ActiveRecord::Base
#
# Label.first.to_reference # => "~1"
# Label.first.to_reference(format: :name) # => "~\"bug\""
# Label.first.to_reference(project) # => "gitlab-org/gitlab-ce~1"
#
# Returns a String
def
to_reference
(
_from_project
=
nil
,
format: :id
)
if
format
==
:name
&&
!
name
.
include?
(
'"'
)
%(#{self.class.reference_prefix}"#{name}")
def
to_reference
(
from_project
=
nil
,
format: :id
)
reference
=
label_format_reference
(
format
)
if
cross_project_reference?
(
from_project
)
project
.
to_reference
+
reference
else
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
reference
end
end
def
open_issues_count
issues
.
opened
.
count
end
...
...
@@ -95,4 +99,16 @@ class Label < ActiveRecord::Base
def
template?
template
end
private
def
label_format_reference
(
format
=
:id
)
raise
StandardError
,
'Unknown format'
unless
[
:id
,
:name
].
include?
(
format
)
if
format
==
:name
&&
!
name
.
include?
(
'"'
)
%(#{self.class.reference_prefix}"#{name}")
else
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
end
end
end
spec/models/label_spec.rb
View file @
acd877c7
...
...
@@ -59,7 +59,6 @@ describe Label, models: true do
context
'using id'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
).
to
eq
"~
#{
label
.
id
}
"
expect
(
label
.
to_reference
(
double
(
'project'
))).
to
eq
"~
#{
label
.
id
}
"
end
end
...
...
@@ -73,5 +72,30 @@ describe Label, models: true do
expect
(
label
.
to_reference
(
format: :name
)).
to
eq
"~
#{
label
.
id
}
"
end
end
context
'using invalid format'
do
it
'raises error'
do
expect
{
label
.
to_reference
(
format: :invalid
)
}
.
to
raise_error
StandardError
,
/Unknown format/
end
end
context
'cross project reference'
do
let
(
:project
)
{
create
(
:project
)
}
context
'using name'
do
it
'returns cross reference with label name'
do
expect
(
label
.
to_reference
(
project
,
format: :name
))
.
to
eq
%Q(
#{
label
.
project
.
to_reference
}
~"
#{
label
.
name
}
")
end
end
context
'using id'
do
it
'returns cross reference with label id'
do
expect
(
label
.
to_reference
(
project
,
format: :id
))
.
to
eq
%Q(
#{
label
.
project
.
to_reference
}
~
#{
label
.
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