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
87f1f6fc
Commit
87f1f6fc
authored
Feb 20, 2018
by
Oswaldo Ferreira
Committed by
Eric Eastwood
Feb 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests to presenter methods
parent
1a2cd2cd
Changes
2
Expand all
Hide 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 @
87f1f6fc
...
@@ -100,6 +100,14 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
...
@@ -100,6 +100,14 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
add_special_file_path
(
file_name:
'LICENSE'
)
add_special_file_path
(
file_name:
'LICENSE'
)
end
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
def
add_ci_yml_path
add_special_file_path
(
file_name:
'.gitlab-ci.yml'
)
add_special_file_path
(
file_name:
'.gitlab-ci.yml'
)
end
end
...
@@ -150,36 +158,6 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
...
@@ -150,36 +158,6 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
license
&
.
nickname
||
license
&
.
name
||
'LICENSE'
license
&
.
nickname
||
license
&
.
name
||
'LICENSE'
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
can_current_user_push_code?
def
can_current_user_push_code?
if
empty_repo?
if
empty_repo?
can?
(
current_user
,
:push_code
,
project
)
can?
(
current_user
,
:push_code
,
project
)
...
@@ -237,7 +215,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
...
@@ -237,7 +215,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
if
current_user
&&
can_current_user_push_code?
&&
repository
.
changelog
.
blank?
if
current_user
&&
can_current_user_push_code?
&&
repository
.
changelog
.
blank?
OpenStruct
.
new
(
enabled:
false
,
OpenStruct
.
new
(
enabled:
false
,
label:
_
(
'Add Changelog'
),
label:
_
(
'Add Changelog'
),
link:
add_
special_file_path
(
file_name:
'CHANGELOG'
)
)
link:
add_
changelog_path
)
elsif
repository
.
changelog
.
present?
elsif
repository
.
changelog
.
present?
OpenStruct
.
new
(
enabled:
true
,
OpenStruct
.
new
(
enabled:
true
,
label:
_
(
'Changelog'
),
label:
_
(
'Changelog'
),
...
@@ -261,7 +239,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
...
@@ -261,7 +239,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
if
current_user
&&
can_current_user_push_code?
&&
repository
.
contribution_guide
.
blank?
if
current_user
&&
can_current_user_push_code?
&&
repository
.
contribution_guide
.
blank?
OpenStruct
.
new
(
enabled:
false
,
OpenStruct
.
new
(
enabled:
false
,
label:
_
(
'Add Contribution guide'
),
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?
elsif
repository
.
contribution_guide
.
present?
OpenStruct
.
new
(
enabled:
true
,
OpenStruct
.
new
(
enabled:
true
,
label:
_
(
'Contribution guide'
),
label:
_
(
'Contribution guide'
),
...
@@ -283,7 +261,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
...
@@ -283,7 +261,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
def
kubernetes_cluster_anchor_data
def
kubernetes_cluster_anchor_data
if
current_user
&&
can?
(
current_user
,
:create_cluster
,
project
)
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?
if
clusters
.
empty?
cluster_link
=
new_project_cluster_path
(
project
)
cluster_link
=
new_project_cluster_path
(
project
)
...
@@ -315,6 +293,36 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
...
@@ -315,6 +293,36 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end
end
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?
def
koding_enabled?
Gitlab
::
CurrentSettings
.
koding_enabled?
Gitlab
::
CurrentSettings
.
koding_enabled?
end
end
...
...
spec/presenters/project_presenter_spec.rb
View file @
87f1f6fc
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