project_from_ref returns nil when reference doesn't exist.
This commit is contained in:
parent
b595249462
commit
b5802d144b
2 changed files with 14 additions and 11 deletions
|
@ -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
|
other = Project.find_with_namespace(ref)
|
||||||
else
|
return nil unless other && user_can_reference_project?(other)
|
||||||
nil
|
|
||||||
end
|
other
|
||||||
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])
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue