summaryrefslogtreecommitdiff
path: root/app/presenters
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-02-20 18:59:19 -0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2018-02-20 18:59:19 -0300
commit1521fd9f5ca6e19d282bbd7253e64d741ab44380 (patch)
tree0313300a8c387abcdf0da75d3bcbb9c262e984e3 /app/presenters
parentd714073d62860bdd80f861baa6882f54d5c57e5f (diff)
downloadgitlab-ce-1521fd9f5ca6e19d282bbd7253e64d741ab44380.tar.gz
Add unit tests to presenter methods
Diffstat (limited to 'app/presenters')
-rw-r--r--app/presenters/project_presenter.rb74
1 files changed, 41 insertions, 33 deletions
diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb
index aa708c656ff..8dca777212e 100644
--- a/app/presenters/project_presenter.rb
+++ b/app/presenters/project_presenter.rb
@@ -100,6 +100,14 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
add_special_file_path(file_name: 'LICENSE')
end
+ def add_changelog_path
+ add_special_file_path(file_name: 'CHANGELOG')
+ end
+
+ def add_contribution_guide_path
+ add_special_file_path(file_name: 'CONTRIBUTING.md', commit_message: 'Add contribution guide')
+ end
+
def add_ci_yml_path
add_special_file_path(file_name: '.gitlab-ci.yml')
end
@@ -150,36 +158,6 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
license&.nickname || license&.name || 'LICENSE'
end
- private
-
- def filename_path(filename)
- if blob = repository.public_send(filename) # rubocop:disable GitlabSecurity/PublicSend
- project_blob_path(
- project,
- tree_join(default_branch, blob.name)
- )
- end
- end
-
- def anonymous_project_view
- if !project.empty_repo? && can?(current_user, :download_code, project)
- 'files'
- else
- 'activity'
- end
- end
-
- def add_special_file_path(file_name:, commit_message: nil, branch_name: nil)
- commit_message ||= s_("CommitMessage|Add %{file_name}") % { file_name: file_name }
- project_new_blob_path(
- project,
- project.default_branch || 'master',
- file_name: file_name,
- commit_message: commit_message,
- branch_name: branch_name
- )
- end
-
def can_current_user_push_code?
if empty_repo?
can?(current_user, :push_code, project)
@@ -237,7 +215,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
if current_user && can_current_user_push_code? && repository.changelog.blank?
OpenStruct.new(enabled: false,
label: _('Add Changelog'),
- link: add_special_file_path(file_name: 'CHANGELOG'))
+ link: add_changelog_path)
elsif repository.changelog.present?
OpenStruct.new(enabled: true,
label: _('Changelog'),
@@ -261,7 +239,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
if current_user && can_current_user_push_code? && repository.contribution_guide.blank?
OpenStruct.new(enabled: false,
label: _('Add Contribution guide'),
- link: add_special_file_path(file_name: 'CONTRIBUTING.md', commit_message: 'Add contribution guide'))
+ link: add_contribution_guide_path)
elsif repository.contribution_guide.present?
OpenStruct.new(enabled: true,
label: _('Contribution guide'),
@@ -283,7 +261,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
def kubernetes_cluster_anchor_data
if current_user && can?(current_user, :create_cluster, project)
- cluster_link = clusters.size == 1 ? project_cluster_path(project, clusters.first) : project_clusters_path(project)
+ cluster_link = clusters.count == 1 ? project_cluster_path(project, clusters.first) : project_clusters_path(project)
if clusters.empty?
cluster_link = new_project_cluster_path(project)
@@ -315,6 +293,36 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end
end
+ private
+
+ def filename_path(filename)
+ if blob = repository.public_send(filename) # rubocop:disable GitlabSecurity/PublicSend
+ project_blob_path(
+ project,
+ tree_join(default_branch, blob.name)
+ )
+ end
+ end
+
+ def anonymous_project_view
+ if !project.empty_repo? && can?(current_user, :download_code, project)
+ 'files'
+ else
+ 'activity'
+ end
+ end
+
+ def add_special_file_path(file_name:, commit_message: nil, branch_name: nil)
+ commit_message ||= s_("CommitMessage|Add %{file_name}") % { file_name: file_name }
+ project_new_blob_path(
+ project,
+ project.default_branch || 'master',
+ file_name: file_name,
+ commit_message: commit_message,
+ branch_name: branch_name
+ )
+ end
+
def koding_enabled?
Gitlab::CurrentSettings.koding_enabled?
end