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
1521fd9f
Commit
1521fd9f
authored
Feb 20, 2018
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests to presenter methods
parent
d714073d
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
315 additions
and
33 deletions
+315
-33
app/presenters/project_presenter.rb
app/presenters/project_presenter.rb
+41
-33
spec/presenters/project_presenter_spec.rb
spec/presenters/project_presenter_spec.rb
+274
-0
No files found.
app/presenters/project_presenter.rb
View file @
1521fd9f
...
...
@@ -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
...
...
spec/presenters/project_presenter_spec.rb
View file @
1521fd9f
This diff is collapsed.
Click to expand it.
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