Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
b5802d14
Commit
b5802d14
authored
Apr 17, 2015
by
Douwe Maan
Committed by
Robert Speicher
Apr 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
project_from_ref returns nil when reference doesn't exist.
parent
b5952494
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
11 deletions
+14
-11
lib/gitlab/markdown/cross_project_reference.rb
lib/gitlab/markdown/cross_project_reference.rb
+6
-9
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
+8
-2
No files found.
lib/gitlab/markdown/cross_project_reference.rb
View file @
b5802d14
...
@@ -16,15 +16,12 @@ module Gitlab
...
@@ -16,15 +16,12 @@ module Gitlab
#
#
# Returns a Project, or nil if the reference can't be accessed
# Returns a Project, or nil if the reference can't be accessed
def
project_from_ref
(
ref
)
def
project_from_ref
(
ref
)
if
ref
&&
other
=
Project
.
find_with_namespace
(
ref
)
return
context
[
:project
]
unless
ref
if
user_can_reference_project?
(
other
)
other
=
Project
.
find_with_namespace
(
ref
)
return
nil
unless
other
&&
user_can_reference_project?
(
other
)
other
other
else
nil
end
else
context
[
:project
]
end
end
end
def
user_can_reference_project?
(
project
,
user
=
context
[
:current_user
])
def
user_can_reference_project?
(
project
,
user
=
context
[
:current_user
])
...
...
spec/lib/gitlab/markdown/cross_project_reference_spec.rb
View file @
b5802d14
...
@@ -13,9 +13,15 @@ module Gitlab::Markdown
...
@@ -13,9 +13,15 @@ module Gitlab::Markdown
include
described_class
include
described_class
describe
'#project_from_ref'
do
describe
'#project_from_ref'
do
context
'when
referenced project does not exist
'
do
context
'when
no project was referenced
'
do
it
'returns the project from context'
do
it
'returns the project from context'
do
expect
(
project_from_ref
(
'invalid/reference'
)).
to
eq
context
[
:project
]
expect
(
project_from_ref
(
nil
)).
to
eq
context
[
:project
]
end
end
context
'when referenced project does not exist'
do
it
'returns nil'
do
expect
(
project_from_ref
(
'invalid/reference'
)).
to
be_nil
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