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
f272ee6e
Commit
f272ee6e
authored
Nov 02, 2016
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add shorthand support to gitlab markdown references
parent
3ebb815a
Changes
40
Show whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
1010 additions
and
286 deletions
+1010
-286
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+1
-1
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+1
-8
app/models/commit.rb
app/models/commit.rb
+12
-10
app/models/commit_range.rb
app/models/commit_range.rb
+10
-7
app/models/concerns/referable.rb
app/models/concerns/referable.rb
+0
-13
app/models/issue.rb
app/models/issue.rb
+1
-5
app/models/label.rb
app/models/label.rb
+6
-9
app/models/merge_request.rb
app/models/merge_request.rb
+1
-5
app/models/milestone.rb
app/models/milestone.rb
+5
-8
app/models/project.rb
app/models/project.rb
+30
-3
app/models/snippet.rb
app/models/snippet.rb
+4
-4
changelogs/unreleased/glm-shorthand-reference.yml
changelogs/unreleased/glm-shorthand-reference.yml
+4
-0
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+17
-6
lib/banzai/filter/commit_range_reference_filter.rb
lib/banzai/filter/commit_range_reference_filter.rb
+1
-1
lib/banzai/filter/commit_reference_filter.rb
lib/banzai/filter/commit_reference_filter.rb
+1
-1
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+10
-44
lib/banzai/filter/milestone_reference_filter.rb
lib/banzai/filter/milestone_reference_filter.rb
+12
-8
spec/features/issues/move_spec.rb
spec/features/issues/move_spec.rb
+1
-1
spec/features/merge_requests/create_new_mr_spec.rb
spec/features/merge_requests/create_new_mr_spec.rb
+1
-1
spec/helpers/labels_helper_spec.rb
spec/helpers/labels_helper_spec.rb
+2
-2
spec/lib/banzai/filter/abstract_link_filter_spec.rb
spec/lib/banzai/filter/abstract_link_filter_spec.rb
+2
-2
spec/lib/banzai/filter/commit_range_reference_filter_spec.rb
spec/lib/banzai/filter/commit_range_reference_filter_spec.rb
+84
-15
spec/lib/banzai/filter/commit_reference_filter_spec.rb
spec/lib/banzai/filter/commit_reference_filter_spec.rb
+64
-14
spec/lib/banzai/filter/issue_reference_filter_spec.rb
spec/lib/banzai/filter/issue_reference_filter_spec.rb
+98
-10
spec/lib/banzai/filter/label_reference_filter_spec.rb
spec/lib/banzai/filter/label_reference_filter_spec.rb
+239
-52
spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
.../lib/banzai/filter/merge_request_reference_filter_spec.rb
+83
-9
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
+99
-9
spec/lib/banzai/filter/snippet_reference_filter_spec.rb
spec/lib/banzai/filter/snippet_reference_filter_spec.rb
+79
-6
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
+2
-2
spec/models/commit_range_spec.rb
spec/models/commit_range_spec.rb
+4
-4
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+10
-4
spec/models/group_label_spec.rb
spec/models/group_label_spec.rb
+10
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+6
-4
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+6
-3
spec/models/milestone_spec.rb
spec/models/milestone_spec.rb
+14
-0
spec/models/project_label_spec.rb
spec/models/project_label_spec.rb
+2
-2
spec/models/project_spec.rb
spec/models/project_spec.rb
+63
-3
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+22
-7
spec/services/issues/move_service_spec.rb
spec/services/issues/move_service_spec.rb
+2
-2
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+1
-1
No files found.
app/helpers/gitlab_markdown_helper.rb
View file @
f272ee6e
...
@@ -174,7 +174,7 @@ module GitlabMarkdownHelper
...
@@ -174,7 +174,7 @@ module GitlabMarkdownHelper
# Returns a String
# Returns a String
def
cross_project_reference
(
project
,
entity
)
def
cross_project_reference
(
project
,
entity
)
if
entity
.
respond_to?
(
:to_reference
)
if
entity
.
respond_to?
(
:to_reference
)
"
#{
project
.
to_reference
}#{
entity
.
to_reference
}
"
entity
.
to_reference
(
project
)
else
else
''
''
end
end
...
...
app/helpers/labels_helper.rb
View file @
f272ee6e
...
@@ -82,12 +82,6 @@ module LabelsHelper
...
@@ -82,12 +82,6 @@ module LabelsHelper
span
.
html_safe
span
.
html_safe
end
end
def
render_colored_cross_project_label
(
label
,
source_project
=
nil
,
tooltip:
true
)
label_suffix
=
source_project
?
source_project
.
name_with_namespace
:
label
.
project
.
name_with_namespace
label_suffix
=
" <i>in
#{
escape_once
(
label_suffix
)
}
</i>"
render_colored_label
(
label
,
label_suffix
,
tooltip:
tooltip
)
end
def
suggested_colors
def
suggested_colors
[
[
'#0033CC'
,
'#0033CC'
,
...
@@ -166,6 +160,5 @@ module LabelsHelper
...
@@ -166,6 +160,5 @@ module LabelsHelper
end
end
# Required for Banzai::Filter::LabelReferenceFilter
# Required for Banzai::Filter::LabelReferenceFilter
module_function
:render_colored_label
,
:render_colored_cross_project_label
,
module_function
:render_colored_label
,
:text_color_for_bg
,
:escape_once
:text_color_for_bg
,
:escape_once
end
end
app/models/commit.rb
View file @
f272ee6e
...
@@ -92,19 +92,11 @@ class Commit
...
@@ -92,19 +92,11 @@ class Commit
end
end
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
if
cross_project_reference?
(
from_project
)
commit_reference
(
from_project
,
id
)
project
.
to_reference
+
self
.
class
.
reference_prefix
+
self
.
id
else
self
.
id
end
end
end
def
reference_link_text
(
from_project
=
nil
)
def
reference_link_text
(
from_project
=
nil
)
if
cross_project_reference?
(
from_project
)
commit_reference
(
from_project
,
short_id
)
project
.
to_reference
+
self
.
class
.
reference_prefix
+
self
.
short_id
else
self
.
short_id
end
end
end
def
diff_line_count
def
diff_line_count
...
@@ -329,6 +321,16 @@ class Commit
...
@@ -329,6 +321,16 @@ class Commit
private
private
def
commit_reference
(
from_project
,
referable_commit_id
)
reference
=
project
.
to_reference
(
from_project
)
if
reference
.
present?
"
#{
reference
}#{
self
.
class
.
reference_prefix
}#{
referable_commit_id
}
"
else
referable_commit_id
end
end
def
find_author_by_any_email
def
find_author_by_any_email
User
.
find_by_any_email
(
author_email
.
downcase
)
User
.
find_by_any_email
(
author_email
.
downcase
)
end
end
...
...
app/models/commit_range.rb
View file @
f272ee6e
...
@@ -90,22 +90,25 @@ class CommitRange
...
@@ -90,22 +90,25 @@ class CommitRange
alias_method
:id
,
:to_s
alias_method
:id
,
:to_s
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
if
cross_project_reference?
(
from_project
)
project_reference
=
project
.
to_reference
(
from_project
)
project
.
to_reference
+
self
.
class
.
reference_prefix
+
self
.
id
if
project_reference
.
present?
project_reference
+
self
.
class
.
reference_prefix
+
self
.
id
else
else
self
.
id
self
.
id
end
end
end
end
def
reference_link_text
(
from_project
=
nil
)
def
reference_link_text
(
from_project
=
nil
)
project_reference
=
project
.
to_reference
(
from_project
)
reference
=
ref_from
+
notation
+
ref_to
reference
=
ref_from
+
notation
+
ref_to
if
cross_project_reference?
(
from_project
)
if
project_reference
.
present?
reference
=
project
.
to_reference
+
self
.
class
.
reference_prefix
+
reference
project_reference
+
self
.
class
.
reference_prefix
+
reference
end
else
reference
reference
end
end
end
# Return a Hash of parameters for passing to a URL helper
# Return a Hash of parameters for passing to a URL helper
#
#
...
...
app/models/concerns/referable.rb
View file @
f272ee6e
...
@@ -72,17 +72,4 @@ module Referable
...
@@ -72,17 +72,4 @@ module Referable
}x
}x
end
end
end
end
private
# Check if a reference is being done cross-project
#
# from_project - Refering Project object
def
cross_project_reference?
(
from_project
)
if
self
.
is_a?
(
Project
)
self
!=
from_project
else
from_project
&&
self
.
project
&&
self
.
project
!=
from_project
end
end
end
end
app/models/issue.rb
View file @
f272ee6e
...
@@ -153,11 +153,7 @@ class Issue < ActiveRecord::Base
...
@@ -153,11 +153,7 @@ class Issue < ActiveRecord::Base
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
iid
}
"
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
iid
}
"
if
cross_project_reference?
(
from_project
)
"
#{
project
.
to_reference
(
from_project
)
}#{
reference
}
"
reference
=
project
.
to_reference
+
reference
end
reference
end
end
def
referenced_merge_requests
(
current_user
=
nil
)
def
referenced_merge_requests
(
current_user
=
nil
)
...
...
app/models/label.rb
View file @
f272ee6e
...
@@ -146,7 +146,8 @@ class Label < ActiveRecord::Base
...
@@ -146,7 +146,8 @@ class Label < ActiveRecord::Base
#
#
# Label.first.to_reference # => "~1"
# Label.first.to_reference # => "~1"
# Label.first.to_reference(format: :name) # => "~\"bug\""
# Label.first.to_reference(format: :name) # => "~\"bug\""
# Label.first.to_reference(project1, project2) # => "gitlab-org/gitlab-ce~1"
# Label.first.to_reference(project, same_namespace_project) # => "gitlab-ce~1"
# Label.first.to_reference(project, another_namespace_project) # => "gitlab-org/gitlab-ce~1"
#
#
# Returns a String
# Returns a String
#
#
...
@@ -154,8 +155,8 @@ class Label < ActiveRecord::Base
...
@@ -154,8 +155,8 @@ class Label < ActiveRecord::Base
format_reference
=
label_format_reference
(
format
)
format_reference
=
label_format_reference
(
format
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
if
cross_project_reference?
(
source_project
,
target_project
)
if
source_project
source_project
.
to_reference
+
reference
"
#{
source_project
.
to_reference
(
target_project
)
}#{
reference
}
"
else
else
reference
reference
end
end
...
@@ -169,10 +170,6 @@ class Label < ActiveRecord::Base
...
@@ -169,10 +170,6 @@ class Label < ActiveRecord::Base
private
private
def
cross_project_reference?
(
source_project
,
target_project
)
source_project
&&
target_project
&&
source_project
!=
target_project
end
def
issues_count
(
user
,
params
=
{})
def
issues_count
(
user
,
params
=
{})
params
.
merge!
(
subject_foreign_key
=>
subject
.
id
,
label_name:
title
,
scope:
'all'
)
params
.
merge!
(
subject_foreign_key
=>
subject
.
id
,
label_name:
title
,
scope:
'all'
)
IssuesFinder
.
new
(
user
,
params
.
with_indifferent_access
).
execute
.
count
IssuesFinder
.
new
(
user
,
params
.
with_indifferent_access
).
execute
.
count
...
...
app/models/merge_request.rb
View file @
f272ee6e
...
@@ -176,11 +176,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -176,11 +176,7 @@ class MergeRequest < ActiveRecord::Base
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
iid
}
"
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
iid
}
"
if
cross_project_reference?
(
from_project
)
"
#{
project
.
to_reference
(
from_project
)
}#{
reference
}
"
reference
=
project
.
to_reference
+
reference
end
reference
end
end
def
first_commit
def
first_commit
...
...
app/models/milestone.rb
View file @
f272ee6e
...
@@ -115,17 +115,14 @@ class Milestone < ActiveRecord::Base
...
@@ -115,17 +115,14 @@ class Milestone < ActiveRecord::Base
#
#
# Milestone.first.to_reference # => "%1"
# Milestone.first.to_reference # => "%1"
# Milestone.first.to_reference(format: :name) # => "%\"goal\""
# Milestone.first.to_reference(format: :name) # => "%\"goal\""
# Milestone.first.to_reference(project) # => "gitlab-org/gitlab-ce%1"
# Milestone.first.to_reference(cross_namespace_project) # => "gitlab-org/gitlab-ce%1"
# Milestone.first.to_reference(same_namespace_project) # => "gitlab-ce%1"
#
#
def
to_reference
(
from_project
=
nil
,
format: :iid
)
def
to_reference
(
from_project
=
nil
,
format: :iid
)
format_reference
=
milestone_format_reference
(
format
)
format_reference
=
milestone_format_reference
(
format
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
if
cross_project_reference?
(
from_project
)
"
#{
project
.
to_reference
(
from_project
)
}#{
reference
}
"
project
.
to_reference
+
reference
else
reference
end
end
end
def
reference_link_text
(
from_project
=
nil
)
def
reference_link_text
(
from_project
=
nil
)
...
...
app/models/project.rb
View file @
f272ee6e
...
@@ -419,7 +419,11 @@ class Project < ActiveRecord::Base
...
@@ -419,7 +419,11 @@ class Project < ActiveRecord::Base
def
reference_pattern
def
reference_pattern
name_pattern
=
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
name_pattern
=
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
%r{(?<project>
#{
name_pattern
}
/
#{
name_pattern
}
)}
%r{
((?<namespace>
#{
name_pattern
}
)
\/
)?
(?<project>
#{
name_pattern
}
)
}x
end
end
def
trending
def
trending
...
@@ -650,8 +654,20 @@ class Project < ActiveRecord::Base
...
@@ -650,8 +654,20 @@ class Project < ActiveRecord::Base
end
end
end
end
def
to_reference
(
_from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
if
cross_namespace_reference?
(
from_project
)
path_with_namespace
path_with_namespace
elsif
cross_project_reference?
(
from_project
)
path
end
end
def
to_human_reference
(
from_project
=
nil
)
if
cross_namespace_reference?
(
from_project
)
name_with_namespace
elsif
cross_project_reference?
(
from_project
)
name
end
end
end
def
web_url
def
web_url
...
@@ -1327,10 +1343,21 @@ class Project < ActiveRecord::Base
...
@@ -1327,10 +1343,21 @@ class Project < ActiveRecord::Base
private
private
# Check if a reference is being done cross-project
#
# from_project - Refering Project object
def
cross_project_reference?
(
from_project
)
from_project
&&
self
!=
from_project
end
def
pushes_since_gc_redis_key
def
pushes_since_gc_redis_key
"projects/
#{
id
}
/pushes_since_gc"
"projects/
#{
id
}
/pushes_since_gc"
end
end
def
cross_namespace_reference?
(
from_project
)
from_project
&&
namespace
!=
from_project
.
namespace
end
def
default_branch_protected?
def
default_branch_protected?
current_application_settings
.
default_branch_protection
==
Gitlab
::
Access
::
PROTECTION_FULL
||
current_application_settings
.
default_branch_protection
==
Gitlab
::
Access
::
PROTECTION_FULL
||
current_application_settings
.
default_branch_protection
==
Gitlab
::
Access
::
PROTECTION_DEV_CAN_MERGE
current_application_settings
.
default_branch_protection
==
Gitlab
::
Access
::
PROTECTION_DEV_CAN_MERGE
...
...
app/models/snippet.rb
View file @
f272ee6e
...
@@ -67,12 +67,12 @@ class Snippet < ActiveRecord::Base
...
@@ -67,12 +67,12 @@ class Snippet < ActiveRecord::Base
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
if
cross_project_reference?
(
from_project
)
if
project
.
present?
reference
=
project
.
to_reference
+
reference
"
#{
project
.
to_reference
(
from_project
)
}#{
reference
}
"
end
else
reference
reference
end
end
end
def
self
.
content_types
def
self
.
content_types
[
[
...
...
changelogs/unreleased/glm-shorthand-reference.yml
0 → 100644
View file @
f272ee6e
---
title
:
Add shorthand support to gitlab markdown references
merge_request
:
7255
author
:
Oswaldo Ferreira
lib/banzai/filter/abstract_reference_filter.rb
View file @
f272ee6e
...
@@ -33,7 +33,7 @@ module Banzai
...
@@ -33,7 +33,7 @@ module Banzai
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
,
pattern
=
object_class
.
reference_pattern
)
def
self
.
references_in
(
text
,
pattern
=
object_class
.
reference_pattern
)
text
.
gsub
(
pattern
)
do
|
match
|
text
.
gsub
(
pattern
)
do
|
match
|
yield
match
,
$~
[
object_sym
].
to_i
,
$~
[
:project
],
$~
yield
match
,
$~
[
object_sym
].
to_i
,
$~
[
:project
],
$~
[
:namespace
],
$~
end
end
end
end
...
@@ -145,8 +145,9 @@ module Banzai
...
@@ -145,8 +145,9 @@ module Banzai
# Returns a String with references replaced with links. All links
# Returns a String with references replaced with links. All links
# have `gfm` and `gfm-OBJECT_NAME` class names attached for styling.
# have `gfm` and `gfm-OBJECT_NAME` class names attached for styling.
def
object_link_filter
(
text
,
pattern
,
link_content:
nil
)
def
object_link_filter
(
text
,
pattern
,
link_content:
nil
)
references_in
(
text
,
pattern
)
do
|
match
,
id
,
project_ref
,
matches
|
references_in
(
text
,
pattern
)
do
|
match
,
id
,
project_ref
,
namespace_ref
,
matches
|
project
=
project_from_ref_cached
(
project_ref
)
project_path
=
full_project_path
(
namespace_ref
,
project_ref
)
project
=
project_from_ref_cached
(
project_path
)
if
project
&&
object
=
find_object_cached
(
project
,
id
)
if
project
&&
object
=
find_object_cached
(
project
,
id
)
title
=
object_link_title
(
object
)
title
=
object_link_title
(
object
)
...
@@ -217,10 +218,9 @@ module Banzai
...
@@ -217,10 +218,9 @@ module Banzai
nodes
.
each
do
|
node
|
nodes
.
each
do
|
node
|
node
.
to_html
.
scan
(
regex
)
do
node
.
to_html
.
scan
(
regex
)
do
project
=
$~
[
:project
]
||
current_project_path
project
_path
=
full_project_path
(
$~
[
:namespace
],
$~
[
:project
])
symbol
=
$~
[
object_sym
]
symbol
=
$~
[
object_sym
]
refs
[
project_path
]
<<
symbol
if
object_class
.
reference_valid?
(
symbol
)
refs
[
project
]
<<
symbol
if
object_class
.
reference_valid?
(
symbol
)
end
end
end
end
...
@@ -272,8 +272,19 @@ module Banzai
...
@@ -272,8 +272,19 @@ module Banzai
@current_project_path
||=
project
.
path_with_namespace
@current_project_path
||=
project
.
path_with_namespace
end
end
def
current_project_namespace_path
@current_project_namespace_path
||=
project
.
namespace
.
path
end
private
private
def
full_project_path
(
namespace
,
project_ref
)
return
current_project_path
unless
project_ref
namespace_ref
=
namespace
||
current_project_namespace_path
"
#{
namespace_ref
}
/
#{
project_ref
}
"
end
def
project_refs_cache
def
project_refs_cache
RequestStore
[
:banzai_project_refs
]
||=
{}
RequestStore
[
:banzai_project_refs
]
||=
{}
end
end
...
...
lib/banzai/filter/commit_range_reference_filter.rb
View file @
f272ee6e
...
@@ -12,7 +12,7 @@ module Banzai
...
@@ -12,7 +12,7 @@ module Banzai
def
self
.
references_in
(
text
,
pattern
=
CommitRange
.
reference_pattern
)
def
self
.
references_in
(
text
,
pattern
=
CommitRange
.
reference_pattern
)
text
.
gsub
(
pattern
)
do
|
match
|
text
.
gsub
(
pattern
)
do
|
match
|
yield
match
,
$~
[
:commit_range
],
$~
[
:project
],
$~
yield
match
,
$~
[
:commit_range
],
$~
[
:project
],
$~
[
:namespace
],
$~
end
end
end
end
...
...
lib/banzai/filter/commit_reference_filter.rb
View file @
f272ee6e
...
@@ -12,7 +12,7 @@ module Banzai
...
@@ -12,7 +12,7 @@ module Banzai
def
self
.
references_in
(
text
,
pattern
=
Commit
.
reference_pattern
)
def
self
.
references_in
(
text
,
pattern
=
Commit
.
reference_pattern
)
text
.
gsub
(
pattern
)
do
|
match
|
text
.
gsub
(
pattern
)
do
|
match
|
yield
match
,
$~
[
:commit
],
$~
[
:project
],
$~
yield
match
,
$~
[
:commit
],
$~
[
:project
],
$~
[
:namespace
],
$~
end
end
end
end
...
...
lib/banzai/filter/label_reference_filter.rb
View file @
f272ee6e
...
@@ -14,16 +14,18 @@ module Banzai
...
@@ -14,16 +14,18 @@ module Banzai
def
self
.
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
def
self
.
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
unescape_html_entities
(
text
).
gsub
(
pattern
)
do
|
match
|
unescape_html_entities
(
text
).
gsub
(
pattern
)
do
|
match
|
yield
match
,
$~
[
:label_id
].
to_i
,
$~
[
:label_name
],
$~
[
:project
],
$~
yield
match
,
$~
[
:label_id
].
to_i
,
$~
[
:label_name
],
$~
[
:project
],
$~
[
:namespace
],
$~
end
end
end
end
def
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
def
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
unescape_html_entities
(
text
).
gsub
(
pattern
)
do
|
match
|
unescape_html_entities
(
text
).
gsub
(
pattern
)
do
|
match
|
label
=
find_label
(
$~
[
:project
],
$~
[
:label_id
],
$~
[
:label_name
])
namespace
,
project
=
$~
[
:namespace
],
$~
[
:project
]
project_path
=
full_project_path
(
namespace
,
project
)
label
=
find_label
(
project_path
,
$~
[
:label_id
],
$~
[
:label_name
])
if
label
if
label
yield
match
,
label
.
id
,
$~
[
:project
]
,
$~
yield
match
,
label
.
id
,
project
,
namespace
,
$~
else
else
match
match
end
end
...
@@ -64,48 +66,12 @@ module Banzai
...
@@ -64,48 +66,12 @@ module Banzai
end
end
def
object_link_text
(
object
,
matches
)
def
object_link_text
(
object
,
matches
)
if
same_group?
(
object
)
&&
namespace_match?
(
matches
)
project_path
=
full_project_path
(
matches
[
:namespace
],
matches
[
:project
])
render_same_project_label
(
object
)
project_from_ref
=
project_from_ref_cached
(
project_path
)
elsif
same_project?
(
object
)
reference
=
project_from_ref
.
to_human_reference
(
project
)
render_same_project_label
(
object
)
label_suffix
=
" <i>in
#{
reference
}
</i>"
if
reference
.
present?
else
render_cross_project_label
(
object
,
matches
)
end
end
def
same_group?
(
object
)
object
.
is_a?
(
GroupLabel
)
&&
object
.
group
==
project
.
group
end
def
namespace_match?
(
matches
)
matches
[
:project
].
blank?
||
matches
[
:project
]
==
project
.
path_with_namespace
end
def
same_project?
(
object
)
object
.
is_a?
(
ProjectLabel
)
&&
object
.
project
==
project
end
def
user
context
[
:current_user
]
||
context
[
:author
]
end
def
project
context
[
:project
]
end
def
render_same_project_label
(
object
)
LabelsHelper
.
render_colored_label
(
object
)
end
def
render_cross_project_label
(
object
,
matches
)
source_project
=
if
matches
[
:project
]
Project
.
find_with_namespace
(
matches
[
:project
])
else
object
.
project
end
LabelsHelper
.
render_colored_
cross_project_label
(
object
,
source_project
)
LabelsHelper
.
render_colored_
label
(
object
,
label_suffix
)
end
end
def
unescape_html_entities
(
text
)
def
unescape_html_entities
(
text
)
...
...
lib/banzai/filter/milestone_reference_filter.rb
View file @
f272ee6e
...
@@ -19,18 +19,20 @@ module Banzai
...
@@ -19,18 +19,20 @@ module Banzai
return
super
(
text
,
pattern
)
if
pattern
!=
Milestone
.
reference_pattern
return
super
(
text
,
pattern
)
if
pattern
!=
Milestone
.
reference_pattern
text
.
gsub
(
pattern
)
do
|
match
|
text
.
gsub
(
pattern
)
do
|
match
|
milestone
=
find_milestone
(
$~
[
:project
],
$~
[
:milestone_iid
],
$~
[
:milestone_name
])
milestone
=
find_milestone
(
$~
[
:project
],
$~
[
:
namespace
],
$~
[
:
milestone_iid
],
$~
[
:milestone_name
])
if
milestone
if
milestone
yield
match
,
milestone
.
iid
,
$~
[
:project
],
$~
yield
match
,
milestone
.
iid
,
$~
[
:project
],
$~
[
:namespace
],
$~
else
else
match
match
end
end
end
end
end
end
def
find_milestone
(
project_ref
,
milestone_id
,
milestone_name
)
def
find_milestone
(
project_ref
,
namespace_ref
,
milestone_id
,
milestone_name
)
project
=
project_from_ref
(
project_ref
)
project_path
=
full_project_path
(
namespace_ref
,
project_ref
)
project
=
project_from_ref
(
project_path
)
return
unless
project
return
unless
project
milestone_params
=
milestone_params
(
milestone_id
,
milestone_name
)
milestone_params
=
milestone_params
(
milestone_id
,
milestone_name
)
...
@@ -52,11 +54,13 @@ module Banzai
...
@@ -52,11 +54,13 @@ module Banzai
end
end
def
object_link_text
(
object
,
matches
)
def
object_link_text
(
object
,
matches
)
if
context
[
:project
]
==
object
.
project
milestone_link
=
escape_once
(
super
)
super
reference
=
object
.
project
.
to_reference
(
project
)
if
reference
.
present?
"
#{
milestone_link
}
<i>in
#{
reference
}
</i>"
.
html_safe
else
else
"
#{
escape_once
(
super
)
}
<i>in
#{
escape_once
(
object
.
project
.
path_with_namespace
)
}
</i>"
.
milestone_link
html_safe
end
end
end
end
...
...
spec/features/issues/move_spec.rb
View file @
f272ee6e
...
@@ -28,7 +28,7 @@ feature 'issue move to another project' do
...
@@ -28,7 +28,7 @@ feature 'issue move to another project' do
let
(
:new_project
)
{
create
(
:project
)
}
let
(
:new_project
)
{
create
(
:project
)
}
let
(
:new_project_search
)
{
create
(
:project
)
}
let
(
:new_project_search
)
{
create
(
:project
)
}
let
(
:text
)
{
"Text with
#{
mr
.
to_reference
}
"
}
let
(
:text
)
{
"Text with
#{
mr
.
to_reference
}
"
}
let
(
:cross_reference
)
{
old_project
.
to_reference
}
let
(
:cross_reference
)
{
old_project
.
to_reference
(
new_project
)
}
background
do
background
do
old_project
.
team
<<
[
user
,
:reporter
]
old_project
.
team
<<
[
user
,
:reporter
]
...
...
spec/features/merge_requests/create_new_mr_spec.rb
View file @
f272ee6e
...
@@ -40,7 +40,7 @@ feature 'Create New Merge Request', feature: true, js: true do
...
@@ -40,7 +40,7 @@ feature 'Create New Merge Request', feature: true, js: true do
visit
new_namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request:
{
target_project_id:
private_project
.
id
})
visit
new_namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request:
{
target_project_id:
private_project
.
id
})
expect
(
page
).
not_to
have_content
private_project
.
to_referen
ce
expect
(
page
).
not_to
have_content
private_project
.
path_with_namespa
ce
end
end
end
end
...
...
spec/helpers/labels_helper_spec.rb
View file @
f272ee6e
...
@@ -7,7 +7,7 @@ describe LabelsHelper do
...
@@ -7,7 +7,7 @@ describe LabelsHelper do
context
'without subject'
do
context
'without subject'
do
it
"uses the label's project"
do
it
"uses the label's project"
do
expect
(
link_to_label
(
label
)).
to
match
%r{<a href="/
#{
label
.
project
.
to_referen
ce
}
/issues
\?
label_name%5B%5D=
#{
label
.
name
}
">.*</a>}
expect
(
link_to_label
(
label
)).
to
match
%r{<a href="/
#{
label
.
project
.
path_with_namespa
ce
}
/issues
\?
label_name%5B%5D=
#{
label
.
name
}
">.*</a>}
end
end
end
end
...
@@ -32,7 +32,7 @@ describe LabelsHelper do
...
@@ -32,7 +32,7 @@ describe LabelsHelper do
[
'issue'
,
:issue
,
'merge_request'
,
:merge_request
].
each
do
|
type
|
[
'issue'
,
:issue
,
'merge_request'
,
:merge_request
].
each
do
|
type
|
context
"set to
#{
type
}
"
do
context
"set to
#{
type
}
"
do
it
'links to correct page'
do
it
'links to correct page'
do
expect
(
link_to_label
(
label
,
type:
type
)).
to
match
%r{<a href="/
#{
label
.
project
.
to_referen
ce
}
/
#{
type
.
to_s
.
pluralize
}
\?
label_name%5B%5D=
#{
label
.
name
}
">.*</a>}
expect
(
link_to_label
(
label
,
type:
type
)).
to
match
%r{<a href="/
#{
label
.
project
.
path_with_namespa
ce
}
/
#{
type
.
to_s
.
pluralize
}
\?
label_name%5B%5D=
#{
label
.
name
}
">.*</a>}
end
end
end
end
end
end
...
...
spec/lib/banzai/filter/abstract_link_filter_spec.rb
View file @
f272ee6e
...
@@ -5,7 +5,7 @@ describe Banzai::Filter::AbstractReferenceFilter do
...
@@ -5,7 +5,7 @@ describe Banzai::Filter::AbstractReferenceFilter do
describe
'#references_per_project'
do
describe
'#references_per_project'
do
it
'returns a Hash containing references grouped per project paths'
do
it
'returns a Hash containing references grouped per project paths'
do
doc
=
Nokogiri
::
HTML
.
fragment
(
"#1
#{
project
.
to_referen
ce
}
#2"
)
doc
=
Nokogiri
::
HTML
.
fragment
(
"#1
#{
project
.
path_with_namespa
ce
}
#2"
)
filter
=
described_class
.
new
(
doc
,
project:
project
)
filter
=
described_class
.
new
(
doc
,
project:
project
)
expect
(
filter
).
to
receive
(
:object_class
).
exactly
(
4
).
times
.
and_return
(
Issue
)
expect
(
filter
).
to
receive
(
:object_class
).
exactly
(
4
).
times
.
and_return
(
Issue
)
...
@@ -14,7 +14,7 @@ describe Banzai::Filter::AbstractReferenceFilter do
...
@@ -14,7 +14,7 @@ describe Banzai::Filter::AbstractReferenceFilter do
refs
=
filter
.
references_per_project
refs
=
filter
.
references_per_project
expect
(
refs
).
to
be_an_instance_of
(
Hash
)
expect
(
refs
).
to
be_an_instance_of
(
Hash
)
expect
(
refs
[
project
.
to_referen
ce
]).
to
eq
(
Set
.
new
(
%w[1 2]
))
expect
(
refs
[
project
.
path_with_namespa
ce
]).
to
eq
(
Set
.
new
(
%w[1 2]
))
end
end
end
end
...
...
spec/lib/banzai/filter/commit_range_reference_filter_spec.rb
View file @
f272ee6e
...
@@ -59,9 +59,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do
...
@@ -59,9 +59,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do
it
'ignores invalid commit IDs'
do
it
'ignores invalid commit IDs'
do
exp
=
act
=
"See
#{
commit1
.
id
.
reverse
}
...
#{
commit2
.
id
}
"
exp
=
act
=
"See
#{
commit1
.
id
.
reverse
}
...
#{
commit2
.
id
}
"
expect
(
project
).
to
receive
(
:valid_repo?
).
and_return
(
true
)
allow
(
project
.
repository
).
to
receive
(
:commit
).
with
(
commit1
.
id
.
reverse
)
expect
(
project
.
repository
).
to
receive
(
:commit
).
with
(
commit1
.
id
.
reverse
)
expect
(
project
.
repository
).
to
receive
(
:commit
).
with
(
commit2
.
id
)
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
...
@@ -100,15 +98,45 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do
...
@@ -100,15 +98,45 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do
end
end
end
end
context
'cross-project reference'
do
context
'cross-project / cross-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:project2
)
{
create
(
:project
,
:public
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
@
#{
commit1
.
id
}
...
#{
commit2
.
id
}
"
}
let
(
:reference
)
{
range
.
to_reference
(
project
)
}
before
do
it
'links to a valid reference'
do
range
.
project
=
project2
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
range
.
to_param
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path_with_namespace
}
@
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"Fixed (
#{
project2
.
path_with_namespace
}
@
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
.)"
)
end
it
'ignores invalid commit IDs on the referenced project'
do
exp
=
act
=
"Fixed
#{
project2
.
path_with_namespace
}
@
#{
commit1
.
id
.
reverse
}
...
#{
commit2
.
id
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
exp
=
act
=
"Fixed
#{
project2
.
path_with_namespace
}
@
#{
commit1
.
id
}
...
#{
commit2
.
id
.
reverse
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
context
'cross-project / same-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
path:
"same-namespace"
,
namespace:
namespace
)
}
let
(
:reference
)
{
"
#{
project2
.
path
}
@
#{
commit1
.
id
}
...
#{
commit2
.
id
}
"
}
it
'links to a valid reference'
do
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
...
@@ -116,24 +144,65 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do
...
@@ -116,24 +144,65 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do
to
eq
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
range
.
to_param
)
to
eq
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
range
.
to_param
)
end
end
it
'link
s with adjacent
text'
do
it
'link
has valid
text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
exp
=
Regexp
.
escape
(
"
#{
project2
.
to_reference
}
@
#{
range
.
reference_link_text
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
exp
}
<\/a>\.\)/
)
to
eql
(
"
#{
project2
.
path
}
@
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"Fixed (
#{
project2
.
path
}
@
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
.)"
)
end
end
it
'ignores invalid commit IDs on the referenced project'
do
it
'ignores invalid commit IDs on the referenced project'
do
exp
=
act
=
"Fixed
#{
project2
.
to_reference
}
@
#{
commit1
.
id
.
reverse
}
...
#{
commit2
.
id
}
"
exp
=
act
=
"Fixed
#{
project2
.
path
}
@
#{
commit1
.
id
.
reverse
}
...
#{
commit2
.
id
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
exp
=
act
=
"Fixed
#{
project2
.
to_reference
}
@
#{
commit1
.
id
}
...
#{
commit2
.
id
.
reverse
}
"
exp
=
act
=
"Fixed
#{
project2
.
path
}
@
#{
commit1
.
id
}
...
#{
commit2
.
id
.
reverse
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project shorthand reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
path:
"same-namespace"
,
namespace:
namespace
)
}
let
(
:reference
)
{
"
#{
project2
.
path
}
@
#{
commit1
.
id
}
...
#{
commit2
.
id
}
"
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
range
.
to_param
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path
}
@
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"Fixed (
#{
project2
.
path
}
@
#{
commit1
.
short_id
}
...
#{
commit2
.
short_id
}
.)"
)
end
it
'ignores invalid commit IDs on the referenced project'
do
exp
=
act
=
"Fixed
#{
project2
.
path
}
@
#{
commit1
.
id
.
reverse
}
...
#{
commit2
.
id
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
exp
=
act
=
"Fixed
#{
project2
.
path
}
@
#{
commit1
.
id
}
...
#{
commit2
.
id
.
reverse
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
context
'cross-project URL reference'
do
context
'cross-project URL reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:range
)
{
CommitRange
.
new
(
"
#{
commit1
.
id
}
...master"
,
project
)
}
let
(
:range
)
{
CommitRange
.
new
(
"
#{
commit1
.
id
}
...master"
,
project
)
}
let
(
:reference
)
{
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
from:
commit1
.
id
,
to:
'master'
)
}
let
(
:reference
)
{
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
from:
commit1
.
id
,
to:
'master'
)
}
...
...
spec/lib/banzai/filter/commit_reference_filter_spec.rb
View file @
f272ee6e
...
@@ -41,6 +41,7 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
...
@@ -41,6 +41,7 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
it
'links with adjacent text'
do
it
'links with adjacent text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
commit
.
short_id
}
<\/a>\.\)/
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
commit
.
short_id
}
<\/a>\.\)/
)
end
end
...
@@ -48,8 +49,6 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
...
@@ -48,8 +49,6 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
invalid
=
invalidate_reference
(
reference
)
invalid
=
invalidate_reference
(
reference
)
exp
=
act
=
"See
#{
invalid
}
"
exp
=
act
=
"See
#{
invalid
}
"
expect
(
project
).
to
receive
(
:valid_repo?
).
and_return
(
true
)
expect
(
project
.
repository
).
to
receive
(
:commit
).
with
(
invalid
)
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
...
@@ -95,34 +94,85 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
...
@@ -95,34 +94,85 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
end
end
end
end
context
'cross-project reference'
do
context
'cross-project
/ cross-namespace complete
reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:commit
)
{
project2
.
commit
}
let
(
:commit
)
{
project2
.
commit
}
let
(
:reference
)
{
commit
.
to_reference
(
project
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
@
#{
commit
.
short_id
}
"
}
it
'link
s to a valid reference
'
do
it
'link
has valid text
'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
doc
=
reference_filter
(
"See
(
#{
reference
}
.)
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path_with_namespace
}
@
#{
commit
.
short_id
}
"
)
to
eq
urls
.
namespace_project_commit_url
(
project2
.
namespace
,
project2
,
commit
.
id
)
end
end
it
'links with adjacent text'
do
it
'has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"See (
#{
project2
.
path_with_namespace
}
@
#{
commit
.
short_id
}
.)"
)
end
it
'ignores invalid commit IDs on the referenced project'
do
exp
=
act
=
"Committed
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project / same-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:commit
)
{
project2
.
commit
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
@
#{
commit
.
short_id
}
"
}
it
'link has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
exp
=
Regexp
.
escape
(
project2
.
to_reference
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path
}
@
#{
commit
.
short_id
}
"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
exp
}
@
#{
commit
.
short_id
}
<\/a>\.\)/
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"See (
#{
project2
.
path
}
@
#{
commit
.
short_id
}
.)"
)
end
end
it
'ignores invalid commit IDs on the referenced project'
do
it
'ignores invalid commit IDs on the referenced project'
do
exp
=
act
=
"Committed
#{
invalidate_reference
(
reference
)
}
"
exp
=
act
=
"Committed
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project shorthand reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:commit
)
{
project2
.
commit
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
@
#{
commit
.
short_id
}
"
}
it
'link has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path
}
@
#{
commit
.
short_id
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"See (
#{
project2
.
path
}
@
#{
commit
.
short_id
}
.)"
)
end
it
'ignores invalid commit IDs on the referenced project'
do
exp
=
act
=
"Committed
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
context
'cross-project URL reference'
do
context
'cross-project URL reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:commit
)
{
project2
.
commit
}
let
(
:commit
)
{
project2
.
commit
}
let
(
:reference
)
{
urls
.
namespace_project_commit_url
(
project2
.
namespace
,
project2
,
commit
.
id
)
}
let
(
:reference
)
{
urls
.
namespace_project_commit_url
(
project2
.
namespace
,
project2
,
commit
.
id
)
}
...
...
spec/lib/banzai/filter/issue_reference_filter_spec.rb
View file @
f272ee6e
...
@@ -24,7 +24,7 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
...
@@ -24,7 +24,7 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
context
'internal reference'
do
context
'internal reference'
do
it_behaves_like
'a reference containing an element node'
it_behaves_like
'a reference containing an element node'
let
(
:reference
)
{
issue
.
to_reference
}
let
(
:reference
)
{
"#
#{
issue
.
iid
}
"
}
it
'ignores valid references when using non-default tracker'
do
it
'ignores valid references when using non-default tracker'
do
allow
(
project
).
to
receive
(
:default_issues_tracker?
).
and_return
(
false
)
allow
(
project
).
to
receive
(
:default_issues_tracker?
).
and_return
(
false
)
...
@@ -42,7 +42,7 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
...
@@ -42,7 +42,7 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
it
'links with adjacent text'
do
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
t
o_html
).
to
match
(
/\(<a.+>
#{
Regexp
.
escape
(
reference
)
}
<\/a>\.\)/
)
expect
(
doc
.
t
ext
).
to
eql
(
"Fixed (
#{
reference
}
.)"
)
end
end
it
'ignores invalid issue IDs'
do
it
'ignores invalid issue IDs'
do
...
@@ -116,13 +116,56 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
...
@@ -116,13 +116,56 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
end
end
end
end
context
'cross-project reference'
do
context
'cross-project
/ cross-namespace complete
reference'
do
it_behaves_like
'a reference containing an element node'
it_behaves_like
'a reference containing an element node'
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project2
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
#
#{
issue
.
iid
}
"
}
it
'ignores valid references when cross-reference project uses external tracker'
do
expect_any_instance_of
(
described_class
).
to
receive
(
:find_object
).
with
(
project2
,
issue
.
iid
).
and_return
(
nil
)
exp
=
act
=
"Issue
#{
reference
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
helper
.
url_for_issue
(
issue
.
iid
,
project2
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path_with_namespace
}
#
#{
issue
.
iid
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"Fixed (
#{
project2
.
path_with_namespace
}
#
#{
issue
.
iid
}
.)"
)
end
it
'ignores invalid issue IDs on the referenced project'
do
exp
=
act
=
"Fixed
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project / same-namespace complete reference'
do
it_behaves_like
'a reference containing an element node'
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project2
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project2
)
}
let
(
:reference
)
{
issue
.
to_reference
(
project
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
#
#{
issue
.
iid
}
"
}
it
'ignores valid references when cross-reference project uses external tracker'
do
it
'ignores valid references when cross-reference project uses external tracker'
do
expect_any_instance_of
(
described_class
).
to
receive
(
:find_object
).
expect_any_instance_of
(
described_class
).
to
receive
(
:find_object
).
...
@@ -140,9 +183,16 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
...
@@ -140,9 +183,16 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
to
eq
helper
.
url_for_issue
(
issue
.
iid
,
project2
)
to
eq
helper
.
url_for_issue
(
issue
.
iid
,
project2
)
end
end
it
'link
s with adjacent
text'
do
it
'link
has valid
text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
Regexp
.
escape
(
reference
)
}
<\/a>\.\)/
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path
}
#
#{
issue
.
iid
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"Fixed (
#{
project2
.
path
}
#
#{
issue
.
iid
}
.)"
)
end
end
it
'ignores invalid issue IDs on the referenced project'
do
it
'ignores invalid issue IDs on the referenced project'
do
...
@@ -150,9 +200,47 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
...
@@ -150,9 +200,47 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
context
'cross-project shorthand reference'
do
it_behaves_like
'a reference containing an element node'
it
'ignores out-of-bounds issue IDs on the referenced project'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
exp
=
act
=
"Fixed #
#{
Gitlab
::
Database
::
MAX_INT_VALUE
+
1
}
"
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project2
)
}
let
(
:reference
)
{
"
#{
project2
.
path
}
#
#{
issue
.
iid
}
"
}
it
'ignores valid references when cross-reference project uses external tracker'
do
expect_any_instance_of
(
described_class
).
to
receive
(
:find_object
).
with
(
project2
,
issue
.
iid
).
and_return
(
nil
)
exp
=
act
=
"Issue
#{
reference
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
helper
.
url_for_issue
(
issue
.
iid
,
project2
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path
}
#
#{
issue
.
iid
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Fixed (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"Fixed (
#{
project2
.
path
}
#
#{
issue
.
iid
}
.)"
)
end
it
'ignores invalid issue IDs on the referenced project'
do
exp
=
act
=
"Fixed
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
...
...
spec/lib/banzai/filter/label_reference_filter_spec.rb
View file @
f272ee6e
...
@@ -4,7 +4,7 @@ require 'html/pipeline'
...
@@ -4,7 +4,7 @@ require 'html/pipeline'
describe
Banzai
::
Filter
::
LabelReferenceFilter
,
lib:
true
do
describe
Banzai
::
Filter
::
LabelReferenceFilter
,
lib:
true
do
include
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:empty_project
,
:public
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
name:
'sample-project'
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
)
}
let
(
:reference
)
{
label
.
to_reference
}
let
(
:reference
)
{
label
.
to_reference
}
...
@@ -48,6 +48,14 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
...
@@ -48,6 +48,14 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
expect
(
link
).
to
eq
urls
.
namespace_project_issues_path
(
project
.
namespace
,
project
,
label_name:
label
.
name
)
expect
(
link
).
to
eq
urls
.
namespace_project_issues_path
(
project
.
namespace
,
project
,
label_name:
label
.
name
)
end
end
context
'project that does not exist referenced'
do
let
(
:result
)
{
reference_filter
(
'aaa/bbb~ccc'
)
}
it
'does not link reference'
do
expect
(
result
.
to_html
).
to
eq
'aaa/bbb~ccc'
end
end
describe
'label span element'
do
describe
'label span element'
do
it
'includes default classes'
do
it
'includes default classes'
do
doc
=
reference_filter
(
"Label
#{
reference
}
"
)
doc
=
reference_filter
(
"Label
#{
reference
}
"
)
...
@@ -334,14 +342,14 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
...
@@ -334,14 +342,14 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
context
'with project reference'
do
context
'with project reference'
do
let
(
:reference
)
{
project
.
to_reference
+
group_label
.
to_reference
(
format: :name
)
}
let
(
:reference
)
{
"
#{
project
.
to_reference
}#{
group_label
.
to_reference
(
format: :name
)
}
"
}
it
'links to a valid reference'
do
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
doc
=
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
group_label
.
name
)
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
group_label
.
name
)
expect
(
doc
.
text
).
to
eq
'See gfm references'
expect
(
doc
.
text
).
to
eq
"See gfm references"
end
end
it
'links with adjacent text'
do
it
'links with adjacent text'
do
...
@@ -357,51 +365,114 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
...
@@ -357,51 +365,114 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
end
end
describe
'cross project label references'
do
describe
'cross-project / cross-namespace complete reference'
do
context
'valid project referenced'
do
let
(
:project2
)
{
create
(
:empty_project
)
}
let
(
:another_project
)
{
create
(
:empty_project
,
:public
)
}
let
(
:label
)
{
create
(
:label
,
project:
project2
,
color:
'#00ff00'
)
}
let
(
:project_name
)
{
another_project
.
name_with_namespace
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
~
#{
label
.
name
}
"
}
let
(
:label
)
{
create
(
:label
,
project:
another_project
,
color:
'#00ff00'
)
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
let
(
:reference
)
{
label
.
to_reference
(
project
)
}
it
'links to a valid reference'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_issues_url
(
project2
.
namespace
,
project2
,
label_name:
label
.
name
)
end
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
)).
to
match
/background-color: #00ff00/
end
it
'has valid link text'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
label
.
name
}
in
#{
project2
.
name_with_namespace
}
"
end
it
'has valid text'
do
expect
(
result
.
text
).
to
eq
"See
#{
label
.
name
}
in
#{
project2
.
name_with_namespace
}
"
end
it
'ignores invalid IDs on the referenced label'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
describe
'cross-project / same-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:label
)
{
create
(
:label
,
project:
project2
,
color:
'#00ff00'
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
~
#{
label
.
name
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
it
'points to referenced project issues pag
e'
do
it
'links to a valid referenc
e'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
))
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_issues_url
(
another_project
.
namespace
,
.
to
eq
urls
.
namespace_project_issues_url
(
project2
.
namespace
,
another_project
,
project2
,
label_name:
label
.
name
)
label_name:
label
.
name
)
end
end
it
'has valid color'
do
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
))
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
)).
to
match
/background-color: #00ff00/
.
to
match
/background-color: #00ff00/
end
end
it
'contains cross project conten
t'
do
it
'has valid link tex
t'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
label
.
name
}
in
#{
project_
name
}
"
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
label
.
name
}
in
#{
project2
.
name
}
"
end
end
it
'has valid text'
do
expect
(
result
.
text
).
to
eq
"See
#{
label
.
name
}
in
#{
project2
.
name
}
"
end
end
context
'project that does not exist referenced
'
do
it
'ignores invalid IDs on the referenced label
'
do
let
(
:result
)
{
reference_filter
(
'aaa/bbb~ccc'
)
}
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
it
'does not link reference'
do
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
expect
(
result
.
to_html
).
to
eq
'aaa/bbb~ccc'
end
end
end
describe
'cross-project shorthand reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:label
)
{
create
(
:label
,
project:
project2
,
color:
'#00ff00'
)
}
let
(
:reference
)
{
"
#{
project2
.
path
}
~
#{
label
.
name
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
it
'links to a valid reference'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_issues_url
(
project2
.
namespace
,
project2
,
label_name:
label
.
name
)
end
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
)).
to
match
/background-color: #00ff00/
end
it
'has valid link text'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
label
.
name
}
in
#{
project2
.
name
}
"
end
it
'has valid text'
do
expect
(
result
.
text
).
to
eq
"See
#{
label
.
name
}
in
#{
project2
.
name
}
"
end
it
'ignores invalid IDs on the referenced label'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
describe
'cross group label references'
do
describe
'cross group label references'
do
context
'valid project referenced'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:another_group
)
{
create
(
:group
)
}
let
(
:another_group
)
{
create
(
:group
)
}
let
(
:another_project
)
{
create
(
:empty_project
,
:public
,
namespace:
another_group
)
}
let
(
:another_project
)
{
create
(
:empty_project
,
:public
,
namespace:
another_group
)
}
let
(
:project_name
)
{
another_project
.
name_with_namespace
}
let
(
:group_label
)
{
create
(
:group_label
,
group:
another_group
,
color:
'#00ff00'
)
}
let
(
:group_label
)
{
create
(
:group_label
,
group:
another_group
,
color:
'#00ff00'
)
}
let
(
:reference
)
{
another_project
.
to_reference
+
group_label
.
to_reference
}
let
(
:reference
)
{
"
#{
another_project
.
path_with_namespace
}
~
#{
group_label
.
name
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
}
it
'points to referenced project issues page'
do
it
'points to referenced project issues page'
do
...
@@ -411,14 +482,130 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
...
@@ -411,14 +482,130 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
label_name:
group_label
.
name
)
label_name:
group_label
.
name
)
end
end
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
)).
to
match
/background-color: #00ff00/
end
it
'has valid link text'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
group_label
.
name
}
in
#{
another_project
.
name_with_namespace
}
"
end
it
'has valid text'
do
expect
(
result
.
text
).
to
eq
"See
#{
group_label
.
name
}
in
#{
another_project
.
name_with_namespace
}
"
end
it
'ignores invalid IDs on the referenced label'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
describe
'cross-project / same-group_label complete reference'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:another_project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:group_label
)
{
create
(
:group_label
,
group:
group
,
color:
'#00ff00'
)
}
let
(
:reference
)
{
"
#{
another_project
.
path_with_namespace
}
~
#{
group_label
.
name
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
}
it
'points to referenced project issues page'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
another_project
.
namespace
,
another_project
,
label_name:
group_label
.
name
)
end
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
)).
to
match
/background-color: #00ff00/
end
it
'has valid link text'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
group_label
.
name
}
in
#{
another_project
.
name
}
"
end
it
'has valid text'
do
expect
(
result
.
text
).
to
eq
"See
#{
group_label
.
name
}
in
#{
another_project
.
name
}
"
end
it
'ignores invalid IDs on the referenced label'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
describe
'same project / same group_label complete reference'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:group_label
)
{
create
(
:group_label
,
group:
group
,
color:
'#00ff00'
)
}
let
(
:reference
)
{
"
#{
project
.
path_with_namespace
}
~
#{
group_label
.
name
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
}
it
'points to referenced project issues page'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
group_label
.
name
)
end
it
'has valid color'
do
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
))
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
))
.
to
match
/background-color: #00ff00/
.
to
match
/background-color: #00ff00/
end
end
it
'contains cross project content'
do
it
'has valid link text'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
group_label
.
name
}
in
#{
project_name
}
"
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
group_label
.
name
end
it
'has valid text'
do
expect
(
result
.
text
).
to
eq
"See
#{
group_label
.
name
}
"
end
it
'ignores invalid IDs on the referenced label'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
describe
'same project / same group_label shorthand reference'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:group_label
)
{
create
(
:group_label
,
group:
group
,
color:
'#00ff00'
)
}
let
(
:reference
)
{
"
#{
project
.
path
}
~
#{
group_label
.
name
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
}
it
'points to referenced project issues page'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
group_label
.
name
)
end
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
)).
to
match
/background-color: #00ff00/
end
it
'has valid link text'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
group_label
.
name
end
it
'has valid text'
do
expect
(
result
.
text
).
to
eq
"See
#{
group_label
.
name
}
"
end
it
'ignores invalid IDs on the referenced label'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
end
end
spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
View file @
f272ee6e
...
@@ -3,7 +3,7 @@ require 'spec_helper'
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Banzai
::
Filter
::
MergeRequestReferenceFilter
,
lib:
true
do
describe
Banzai
::
Filter
::
MergeRequestReferenceFilter
,
lib:
true
do
include
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:project
)
{
create
(
:
empty_
project
,
:public
)
}
let
(
:merge
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:merge
)
{
create
(
:merge_request
,
source_project:
project
)
}
it
'requires project context'
do
it
'requires project context'
do
...
@@ -86,23 +86,97 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do
...
@@ -86,23 +86,97 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do
end
end
end
end
context
'cross-project reference'
do
context
'cross-project / cross-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:merge
)
{
create
(
:merge_request
,
source_project:
project2
)
}
let
(
:merge
)
{
create
(
:merge_request
,
source_project:
project2
)
}
let
(
:reference
)
{
merge
.
to_reference
(
project
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
!
#{
merge
.
iid
}
"
}
it
'links to a valid reference'
do
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_merge_request_url
(
project2
.
namespace
,
to
eq
urls
.
namespace_project_merge_request_url
(
project2
.
namespace
,
project
,
merge
)
project2
,
merge
)
end
end
it
'link
s with adjacent
text'
do
it
'link
has valid
text'
do
doc
=
reference_filter
(
"Merge (
#{
reference
}
.)"
)
doc
=
reference_filter
(
"Merge (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
Regexp
.
escape
(
reference
)
}
<\/a>\.\)/
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
(
reference
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Merge (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"Merge (
#{
reference
}
.)"
)
end
it
'ignores invalid merge IDs on the referenced project'
do
exp
=
act
=
"Merge
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project / same-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let!
(
:merge
)
{
create
(
:merge_request
,
source_project:
project2
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
!
#{
merge
.
iid
}
"
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_merge_request_url
(
project2
.
namespace
,
project2
,
merge
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"Merge (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
(
"
#{
project2
.
path
}
!
#{
merge
.
iid
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Merge (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"Merge (
#{
project2
.
path
}
!
#{
merge
.
iid
}
.)"
)
end
it
'ignores invalid merge IDs on the referenced project'
do
exp
=
act
=
"Merge
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project shorthand reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let!
(
:merge
)
{
create
(
:merge_request
,
source_project:
project2
)
}
let
(
:reference
)
{
"
#{
project2
.
path
}
!
#{
merge
.
iid
}
"
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_merge_request_url
(
project2
.
namespace
,
project2
,
merge
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"Merge (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
(
"
#{
project2
.
path
}
!
#{
merge
.
iid
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"Merge (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"Merge (
#{
project2
.
path
}
!
#{
merge
.
iid
}
.)"
)
end
end
it
'ignores invalid merge IDs on the referenced project'
do
it
'ignores invalid merge IDs on the referenced project'
do
...
...
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
View file @
f272ee6e
...
@@ -148,12 +148,50 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do
...
@@ -148,12 +148,50 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do
end
end
end
end
describe
'cross
project milestone references
'
do
describe
'cross
-project / cross-namespace complete reference
'
do
let
(
:
another_project
)
{
create
(
:empty_project
,
:public
)
}
let
(
:
namespace
)
{
create
(
:namespace
)
}
let
(
:
project_path
)
{
another_project
.
path_with_namespace
}
let
(
:
another_project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
another_project
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
another_project
)
}
let
(
:reference
)
{
milestone
.
to_reference
(
project
)
}
let
(
:reference
)
{
"
#{
another_project
.
path_with_namespace
}
%
#{
milestone
.
iid
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
it
'points to referenced project milestone page'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_milestone_url
(
another_project
.
namespace
,
another_project
,
milestone
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
(
"
#{
milestone
.
name
}
in
#{
another_project
.
path_with_namespace
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"See (
#{
milestone
.
name
}
in
#{
another_project
.
path_with_namespace
}
.)"
)
end
it
'escapes the name attribute'
do
allow_any_instance_of
(
Milestone
).
to
receive
(
:title
).
and_return
(
%{"></a>whatever<a title="}
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
milestone
.
name
}
in
#{
another_project
.
path_with_namespace
}
"
end
end
describe
'cross-project / same-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:another_project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
another_project
)
}
let
(
:reference
)
{
"
#{
another_project
.
path_with_namespace
}
%
#{
milestone
.
iid
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
it
'points to referenced project milestone page'
do
it
'points to referenced project milestone page'
do
...
@@ -163,14 +201,66 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do
...
@@ -163,14 +201,66 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do
milestone
)
milestone
)
end
end
it
'contains cross project content'
do
it
'link has valid text'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
milestone
.
name
}
in
#{
project_path
}
"
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
(
"
#{
milestone
.
name
}
in
#{
another_project
.
path
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"See (
#{
milestone
.
name
}
in
#{
another_project
.
path
}
.)"
)
end
end
it
'escapes the name attribute'
do
it
'escapes the name attribute'
do
allow_any_instance_of
(
Milestone
).
to
receive
(
:title
).
and_return
(
%{"></a>whatever<a title="}
)
allow_any_instance_of
(
Milestone
).
to
receive
(
:title
).
and_return
(
%{"></a>whatever<a title="}
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
milestone
.
name
}
in
#{
another_project
.
path
}
"
end
end
describe
'cross project shorthand reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:another_project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
another_project
)
}
let
(
:reference
)
{
"
#{
another_project
.
path
}
%
#{
milestone
.
iid
}
"
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
)
}
it
'points to referenced project milestone page'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_milestone_url
(
another_project
.
namespace
,
another_project
,
milestone
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
(
"
#{
milestone
.
name
}
in
#{
another_project
.
path
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eq
(
"See (
#{
milestone
.
name
}
in
#{
another_project
.
path
}
.)"
)
end
it
'escapes the name attribute'
do
allow_any_instance_of
(
Milestone
).
to
receive
(
:title
).
and_return
(
%{"></a>whatever<a title="}
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
milestone
.
name
}
in
#{
project_path
}
"
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
milestone
.
name
}
in
#{
another_project
.
path
}
"
end
end
end
end
end
end
spec/lib/banzai/filter/snippet_reference_filter_spec.rb
View file @
f272ee6e
...
@@ -79,11 +79,11 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do
...
@@ -79,11 +79,11 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do
end
end
end
end
context
'cross-project reference'
do
context
'cross-project
/ cross-namespace complete
reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project2
)
}
let
!
(
:snippet
)
{
create
(
:project_snippet
,
project:
project2
)
}
let
(
:reference
)
{
snippet
.
to_reference
(
project
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
$
#{
snippet
.
id
}
"
}
it
'links to a valid reference'
do
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
doc
=
reference_filter
(
"See
#{
reference
}
"
)
...
@@ -92,9 +92,82 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do
...
@@ -92,9 +92,82 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do
to
eq
urls
.
namespace_project_snippet_url
(
project2
.
namespace
,
project2
,
snippet
)
to
eq
urls
.
namespace_project_snippet_url
(
project2
.
namespace
,
project2
,
snippet
)
end
end
it
'link
s with adjacent
text'
do
it
'link
has valid
text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>
#{
Regexp
.
escape
(
reference
)
}
<\/a>\.\)/
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
reference
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
reference
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"See (
#{
reference
}
.)"
)
end
it
'ignores invalid snippet IDs on the referenced project'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project / same-namespace complete reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let!
(
:snippet
)
{
create
(
:project_snippet
,
project:
project2
)
}
let
(
:reference
)
{
"
#{
project2
.
path_with_namespace
}
$
#{
snippet
.
id
}
"
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_snippet_url
(
project2
.
namespace
,
project2
,
snippet
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"See (
#{
project2
.
path
}
$
#{
snippet
.
id
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path
}
$
#{
snippet
.
id
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
project2
.
path
}
$
#{
snippet
.
id
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"See (
#{
project2
.
path
}
$
#{
snippet
.
id
}
.)"
)
end
it
'ignores invalid snippet IDs on the referenced project'
do
exp
=
act
=
"See
#{
invalidate_reference
(
reference
)
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'cross-project shorthand reference'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
let!
(
:snippet
)
{
create
(
:project_snippet
,
project:
project2
)
}
let
(
:reference
)
{
"
#{
project2
.
path
}
$
#{
snippet
.
id
}
"
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_snippet_url
(
project2
.
namespace
,
project2
,
snippet
)
end
it
'link has valid text'
do
doc
=
reference_filter
(
"See (
#{
project2
.
path
}
$
#{
snippet
.
id
}
.)"
)
expect
(
doc
.
css
(
'a'
).
first
.
text
).
to
eql
(
"
#{
project2
.
path
}
$
#{
snippet
.
id
}
"
)
end
it
'has valid text'
do
doc
=
reference_filter
(
"See (
#{
project2
.
path
}
$
#{
snippet
.
id
}
.)"
)
expect
(
doc
.
text
).
to
eql
(
"See (
#{
project2
.
path
}
$
#{
snippet
.
id
}
.)"
)
end
end
it
'ignores invalid snippet IDs on the referenced project'
do
it
'ignores invalid snippet IDs on the referenced project'
do
...
...
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
View file @
f272ee6e
...
@@ -64,7 +64,7 @@ describe Gitlab::Gfm::ReferenceRewriter do
...
@@ -64,7 +64,7 @@ describe Gitlab::Gfm::ReferenceRewriter do
context
'description with project labels'
do
context
'description with project labels'
do
let!
(
:label
)
{
create
(
:label
,
id:
123
,
name:
'test'
,
project:
old_project
)
}
let!
(
:label
)
{
create
(
:label
,
id:
123
,
name:
'test'
,
project:
old_project
)
}
let
(
:project_ref
)
{
old_project
.
to_reference
}
let
(
:project_ref
)
{
old_project
.
to_reference
(
new_project
)
}
context
'label referenced by id'
do
context
'label referenced by id'
do
let
(
:text
)
{
'#1 and ~123'
}
let
(
:text
)
{
'#1 and ~123'
}
...
@@ -80,7 +80,7 @@ describe Gitlab::Gfm::ReferenceRewriter do
...
@@ -80,7 +80,7 @@ describe Gitlab::Gfm::ReferenceRewriter do
context
'description with group labels'
do
context
'description with group labels'
do
let
(
:old_group
)
{
create
(
:group
)
}
let
(
:old_group
)
{
create
(
:group
)
}
let!
(
:group_label
)
{
create
(
:group_label
,
id:
321
,
name:
'group label'
,
group:
old_group
)
}
let!
(
:group_label
)
{
create
(
:group_label
,
id:
321
,
name:
'group label'
,
group:
old_group
)
}
let
(
:project_ref
)
{
old_project
.
to_reference
}
let
(
:project_ref
)
{
old_project
.
to_reference
(
new_project
)
}
before
do
before
do
old_project
.
update
(
namespace:
old_group
)
old_project
.
update
(
namespace:
old_group
)
...
...
spec/models/commit_range_spec.rb
View file @
f272ee6e
...
@@ -45,7 +45,7 @@ describe CommitRange, models: true do
...
@@ -45,7 +45,7 @@ describe CommitRange, models: true do
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
let
(
:cross
)
{
create
(
:
project
)
}
let
(
:cross
)
{
create
(
:
empty_project
,
namespace:
project
.
namespace
)
}
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
range
.
to_reference
).
to
eq
"
#{
full_sha_from
}
...
#{
full_sha_to
}
"
expect
(
range
.
to_reference
).
to
eq
"
#{
full_sha_from
}
...
#{
full_sha_to
}
"
...
@@ -56,12 +56,12 @@ describe CommitRange, models: true do
...
@@ -56,12 +56,12 @@ describe CommitRange, models: true do
end
end
it
'supports a cross-project reference'
do
it
'supports a cross-project reference'
do
expect
(
range
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
full_sha_from
}
...
#{
full_sha_to
}
"
expect
(
range
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
path
}
@
#{
full_sha_from
}
...
#{
full_sha_to
}
"
end
end
end
end
describe
'#reference_link_text'
do
describe
'#reference_link_text'
do
let
(
:cross
)
{
create
(
:
project
)
}
let
(
:cross
)
{
create
(
:
empty_project
,
namespace:
project
.
namespace
)
}
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
range
.
reference_link_text
).
to
eq
"
#{
sha_from
}
...
#{
sha_to
}
"
expect
(
range
.
reference_link_text
).
to
eq
"
#{
sha_from
}
...
#{
sha_to
}
"
...
@@ -72,7 +72,7 @@ describe CommitRange, models: true do
...
@@ -72,7 +72,7 @@ describe CommitRange, models: true do
end
end
it
'supports a cross-project reference'
do
it
'supports a cross-project reference'
do
expect
(
range
.
reference_link_text
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
sha_from
}
...
#{
sha_to
}
"
expect
(
range
.
reference_link_text
(
cross
)).
to
eq
"
#{
project
.
path
}
@
#{
sha_from
}
...
#{
sha_to
}
"
end
end
end
end
...
...
spec/models/commit_spec.rb
View file @
f272ee6e
...
@@ -34,24 +34,30 @@ describe Commit, models: true do
...
@@ -34,24 +34,30 @@ describe Commit, models: true do
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
let
(
:project
)
{
create
(
:project
,
path:
'sample-project'
)
}
let
(
:commit
)
{
project
.
commit
}
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
commit
.
to_reference
).
to
eq
commit
.
id
expect
(
commit
.
to_reference
).
to
eq
commit
.
id
end
end
it
'supports a cross-project reference'
do
it
'supports a cross-project reference'
do
cross
=
double
(
'project'
)
another_project
=
build
(
:project
,
name:
'another-project'
,
namespace:
project
.
namespace
)
expect
(
commit
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
commit
.
id
}
"
expect
(
commit
.
to_reference
(
another_project
)).
to
eq
"sample-project
@
#{
commit
.
id
}
"
end
end
end
end
describe
'#reference_link_text'
do
describe
'#reference_link_text'
do
let
(
:project
)
{
create
(
:project
,
path:
'sample-project'
)
}
let
(
:commit
)
{
project
.
commit
}
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
commit
.
reference_link_text
).
to
eq
commit
.
short_id
expect
(
commit
.
reference_link_text
).
to
eq
commit
.
short_id
end
end
it
'supports a cross-project reference'
do
it
'supports a cross-project reference'
do
cross
=
double
(
'project'
)
another_project
=
build
(
:project
,
name:
'another-project'
,
namespace:
project
.
namespace
)
expect
(
commit
.
reference_link_text
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
@
#{
commit
.
short_id
}
"
expect
(
commit
.
reference_link_text
(
another_project
)).
to
eq
"sample-project
@
#{
commit
.
short_id
}
"
end
end
end
end
...
...
spec/models/group_label_spec.rb
View file @
f272ee6e
...
@@ -37,6 +37,16 @@ describe GroupLabel, models: true do
...
@@ -37,6 +37,16 @@ describe GroupLabel, models: true do
end
end
end
end
context
'cross-project'
do
let
(
:namespace
)
{
build_stubbed
(
:namespace
)
}
let
(
:source_project
)
{
build_stubbed
(
:empty_project
,
name:
'project-1'
,
namespace:
namespace
)
}
let
(
:target_project
)
{
build_stubbed
(
:empty_project
,
name:
'project-2'
,
namespace:
namespace
)
}
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
(
source_project
,
target_project
)).
to
eq
%(project-1~#{label.id})
end
end
context
'using invalid format'
do
context
'using invalid format'
do
it
'raises error'
do
it
'raises error'
do
expect
{
label
.
to_reference
(
format: :invalid
)
}
expect
{
label
.
to_reference
(
format: :invalid
)
}
...
...
spec/models/issue_spec.rb
View file @
f272ee6e
...
@@ -43,14 +43,16 @@ describe Issue, models: true do
...
@@ -43,14 +43,16 @@ describe Issue, models: true do
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
let
(
:project
)
{
build
(
:empty_project
,
name:
'sample-project'
)
}
let
(
:issue
)
{
build
(
:issue
,
iid:
1
,
project:
project
)
}
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
subject
.
to_reference
).
to
eq
"#
#{
subject
.
iid
}
"
expect
(
issue
.
to_reference
).
to
eq
"#1
"
end
end
it
'supports a cross-project reference'
do
it
'supports a cross-project reference'
do
cross
=
double
(
'project'
)
another_project
=
build
(
:project
,
name:
'another-project'
,
namespace:
project
.
namespace
)
expect
(
subject
.
to_reference
(
cross
)).
expect
(
issue
.
to_reference
(
another_project
)).
to
eq
"sample-project#1"
to
eq
"
#{
subject
.
project
.
to_reference
}
#
#{
subject
.
iid
}
"
end
end
end
end
...
...
spec/models/merge_request_spec.rb
View file @
f272ee6e
...
@@ -142,13 +142,16 @@ describe MergeRequest, models: true do
...
@@ -142,13 +142,16 @@ describe MergeRequest, models: true do
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
let
(
:project
)
{
build
(
:empty_project
,
name:
'sample-project'
)
}
let
(
:merge_request
)
{
build
(
:merge_request
,
target_project:
project
,
iid:
1
)
}
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
subject
.
to_reference
).
to
eq
"!
#{
subject
.
iid
}
"
expect
(
merge_request
.
to_reference
).
to
eq
"!1
"
end
end
it
'supports a cross-project reference'
do
it
'supports a cross-project reference'
do
cross
=
double
(
'project'
)
another_project
=
build
(
:project
,
name:
'another-project'
,
namespace:
project
.
namespace
)
expect
(
subject
.
to_reference
(
cross
)).
to
eq
"
#{
subject
.
source_project
.
to_reference
}
!
#{
subject
.
iid
}
"
expect
(
merge_request
.
to_reference
(
another_project
)).
to
eq
"sample-project!1
"
end
end
end
end
...
...
spec/models/milestone_spec.rb
View file @
f272ee6e
...
@@ -246,4 +246,18 @@ describe Milestone, models: true do
...
@@ -246,4 +246,18 @@ describe Milestone, models: true do
end
end
end
end
end
end
describe
'#to_reference'
do
let
(
:project
)
{
build
(
:empty_project
,
name:
'sample-project'
)
}
let
(
:milestone
)
{
build
(
:milestone
,
iid:
1
,
project:
project
)
}
it
'returns a String reference to the object'
do
expect
(
milestone
.
to_reference
).
to
eq
"%1"
end
it
'supports a cross-project reference'
do
another_project
=
build
(
:project
,
name:
'another-project'
,
namespace:
project
.
namespace
)
expect
(
milestone
.
to_reference
(
another_project
)).
to
eq
"sample-project%1"
end
end
end
end
spec/models/project_label_spec.rb
View file @
f272ee6e
...
@@ -105,14 +105,14 @@ describe ProjectLabel, models: true do
...
@@ -105,14 +105,14 @@ describe ProjectLabel, models: true do
context
'using name'
do
context
'using name'
do
it
'returns cross reference with label name'
do
it
'returns cross reference with label name'
do
expect
(
label
.
to_reference
(
project
,
format: :name
))
expect
(
label
.
to_reference
(
project
,
format: :name
))
.
to
eq
%Q(
#{
label
.
project
.
to_referen
ce
}
~"
#{
label
.
name
}
")
.
to
eq
%Q(
#{
label
.
project
.
path_with_namespa
ce
}
~"
#{
label
.
name
}
")
end
end
end
end
context
'using id'
do
context
'using id'
do
it
'returns cross reference with label id'
do
it
'returns cross reference with label id'
do
expect
(
label
.
to_reference
(
project
,
format: :id
))
expect
(
label
.
to_reference
(
project
,
format: :id
))
.
to
eq
%Q(
#{
label
.
project
.
to_referen
ce
}
~
#{
label
.
id
}
)
.
to
eq
%Q(
#{
label
.
project
.
path_with_namespa
ce
}
~
#{
label
.
id
}
)
end
end
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
f272ee6e
...
@@ -258,10 +258,70 @@ describe Project, models: true do
...
@@ -258,10 +258,70 @@ describe Project, models: true do
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:owner
)
{
create
(
:user
,
name:
'Gitlab'
)
}
let
(
:namespace
)
{
create
(
:namespace
,
path:
'sample-namespace'
,
owner:
owner
)
}
let
(
:project
)
{
create
(
:empty_project
,
path:
'sample-project'
,
namespace:
namespace
)
}
context
'when nil argument'
do
it
'returns nil'
do
expect
(
project
.
to_reference
).
to
be_nil
end
end
context
'when same project argument'
do
it
'returns nil'
do
expect
(
project
.
to_reference
(
project
)).
to
be_nil
end
end
it
'returns a String reference to the object'
do
context
'when cross namespace project argument'
do
expect
(
project
.
to_reference
).
to
eq
project
.
path_with_namespace
let
(
:another_namespace_project
)
{
create
(
:empty_project
,
name:
'another-project'
)
}
it
'returns complete path to the project'
do
expect
(
project
.
to_reference
(
another_namespace_project
)).
to
eq
'sample-namespace/sample-project'
end
end
context
'when same namespace / cross-project argument'
do
let
(
:another_project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
it
'returns complete path to the project'
do
expect
(
project
.
to_reference
(
another_project
)).
to
eq
'sample-project'
end
end
end
describe
'#to_human_reference'
do
let
(
:owner
)
{
create
(
:user
,
name:
'Gitlab'
)
}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'Sample namespace'
,
owner:
owner
)
}
let
(
:project
)
{
create
(
:empty_project
,
name:
'Sample project'
,
namespace:
namespace
)
}
context
'when nil argument'
do
it
'returns nil'
do
expect
(
project
.
to_human_reference
).
to
be_nil
end
end
context
'when same project argument'
do
it
'returns nil'
do
expect
(
project
.
to_human_reference
(
project
)).
to
be_nil
end
end
context
'when cross namespace project argument'
do
let
(
:another_namespace_project
)
{
create
(
:empty_project
,
name:
'another-project'
)
}
it
'returns complete name with namespace of the project'
do
expect
(
project
.
to_human_reference
(
another_namespace_project
)).
to
eq
'Gitlab / Sample project'
end
end
context
'when same namespace / cross-project argument'
do
let
(
:another_project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
it
'returns name of the project'
do
expect
(
project
.
to_human_reference
(
another_project
)).
to
eq
'Sample project'
end
end
end
end
end
...
...
spec/models/snippet_spec.rb
View file @
f272ee6e
...
@@ -33,16 +33,31 @@ describe Snippet, models: true do
...
@@ -33,16 +33,31 @@ describe Snippet, models: true do
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
let
(
:project
)
{
create
(
:empty_project
)
}
context
'when snippet belongs to a project'
do
let
(
:snippet
)
{
create
(
:snippet
,
project:
project
)
}
let
(
:project
)
{
build
(
:empty_project
,
name:
'sample-project'
)
}
let
(
:snippet
)
{
build
(
:snippet
,
id:
1
,
project:
project
)
}
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
snippet
.
to_reference
).
to
eq
"$
#{
snippet
.
id
}
"
expect
(
snippet
.
to_reference
).
to
eq
"$1
"
end
end
it
'supports a cross-project reference'
do
it
'supports a cross-project reference'
do
cross
=
double
(
'project'
)
another_project
=
build
(
:project
,
name:
'another-project'
,
namespace:
project
.
namespace
)
expect
(
snippet
.
to_reference
(
cross
)).
to
eq
"
#{
project
.
to_reference
}
$
#{
snippet
.
id
}
"
expect
(
snippet
.
to_reference
(
another_project
)).
to
eq
"sample-project$1"
end
end
context
'when snippet does not belong to a project'
do
let
(
:snippet
)
{
build
(
:snippet
,
id:
1
,
project:
nil
)
}
it
'returns a String reference to the object'
do
expect
(
snippet
.
to_reference
).
to
eq
"$1"
end
it
'still returns shortest reference when project arg present'
do
another_project
=
build
(
:project
,
name:
'another-project'
)
expect
(
snippet
.
to_reference
(
another_project
)).
to
eq
"$1"
end
end
end
end
end
...
...
spec/services/issues/move_service_spec.rb
View file @
f272ee6e
...
@@ -189,7 +189,7 @@ describe Issues::MoveService, services: true do
...
@@ -189,7 +189,7 @@ describe Issues::MoveService, services: true do
it
'rewrites references using a cross reference to old project'
do
it
'rewrites references using a cross reference to old project'
do
expect
(
new_note
.
note
)
expect
(
new_note
.
note
)
.
to
eq
"Note with reference to merge request
#{
old_project
.
to_reference
}
!1"
.
to
eq
"Note with reference to merge request
#{
old_project
.
to_reference
(
new_project
)
}
!1"
end
end
end
end
...
@@ -217,7 +217,7 @@ describe Issues::MoveService, services: true do
...
@@ -217,7 +217,7 @@ describe Issues::MoveService, services: true do
it
'rewrites referenced issues creating cross project reference'
do
it
'rewrites referenced issues creating cross project reference'
do
expect
(
new_issue
.
description
)
expect
(
new_issue
.
description
)
.
to
eq
"Some description
#{
old_project
.
to_reference
}#{
another_issue
.
to_reference
}
"
.
to
eq
"Some description
#{
another_issue
.
to_reference
(
new_project
)
}
"
end
end
end
end
...
...
spec/services/system_note_service_spec.rb
View file @
f272ee6e
...
@@ -530,7 +530,7 @@ describe SystemNoteService, services: true do
...
@@ -530,7 +530,7 @@ describe SystemNoteService, services: true do
end
end
it
'mentions referenced project'
do
it
'mentions referenced project'
do
expect
(
subject
.
note
).
to
include
new_project
.
to_referen
ce
expect
(
subject
.
note
).
to
include
new_project
.
path_with_namespa
ce
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