summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReuben Pereira <reuben453@gmail.com>2018-07-05 01:55:55 +0530
committerReuben Pereira <reuben453@gmail.com>2018-07-05 01:55:55 +0530
commit74c81cc50e7d4deff11e9777b9522f8adf8b3c96 (patch)
tree0681e91baf0375b00e7b7972fb504cf3bd32f665
parent2730ae1d869af4ddd48dc312d230c1bcafec19b5 (diff)
downloadgitlab-ce-74c81cc50e7d4deff11e9777b9522f8adf8b3c96.tar.gz
Add back the Project#to_reference_with_postfix function since it can be used in the ProjectReferenceFilter#link_to_project function
-rw-r--r--app/models/project.rb4
-rw-r--r--lib/banzai/filter/project_reference_filter.rb2
-rw-r--r--spec/lib/banzai/filter/project_reference_filter_spec.rb2
-rw-r--r--spec/models/project_spec.rb9
4 files changed, 15 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 9dfa9a144fd..cf740de9405 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -902,6 +902,10 @@ class Project < ActiveRecord::Base
end
end
+ def to_reference_with_postfix
+ "#{to_reference(full: true)}#{self.class.reference_postfix}"
+ end
+
# `from` argument can be a Namespace or Project.
def to_reference(from = nil, full: false)
if full || cross_namespace_reference?(from)
diff --git a/lib/banzai/filter/project_reference_filter.rb b/lib/banzai/filter/project_reference_filter.rb
index 9764cfa4ef5..fd2a86a6d45 100644
--- a/lib/banzai/filter/project_reference_filter.rb
+++ b/lib/banzai/filter/project_reference_filter.rb
@@ -102,7 +102,7 @@ module Banzai
def link_to_project(project, link_content: nil)
url = urls.project_url(project, only_path: context[:only_path])
data = data_attribute(project: project.id)
- content = link_content || project.full_path + Project.reference_postfix
+ content = link_content || project.to_reference_with_postfix
link_tag(url, data, content, project.name)
end
diff --git a/spec/lib/banzai/filter/project_reference_filter_spec.rb b/spec/lib/banzai/filter/project_reference_filter_spec.rb
index 20f809e010e..13e1fc2d3e2 100644
--- a/spec/lib/banzai/filter/project_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/project_reference_filter_spec.rb
@@ -8,7 +8,7 @@ describe Banzai::Filter::ProjectReferenceFilter do
end
def get_reference(project)
- "#{project.to_reference(full: true)}#{Project.reference_postfix}"
+ project.to_reference_with_postfix
end
let(:project) { create(:project, :public) }
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index abdc65336ca..acc7821a21e 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -344,6 +344,15 @@ describe Project do
it { is_expected.to delegate_method(:name).to(:owner).with_prefix(true).with_arguments(allow_nil: true) }
end
+ describe '#to_reference_with_postfix' do
+ it 'returns the full path with reference_postfix' do
+ namespace = create(:namespace, path: 'sample-namespace')
+ project = create(:project, path: 'sample-project', namespace: namespace)
+
+ expect(project.to_reference_with_postfix).to eq 'sample-namespace/sample-project>'
+ end
+ end
+
describe '#to_reference' do
let(:owner) { create(:user, name: 'Gitlab') }
let(:namespace) { create(:namespace, path: 'sample-namespace', owner: owner) }