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
9dc67bf1
Commit
9dc67bf1
authored
Dec 06, 2018
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move group path display logic to helper
Add specs
parent
887bbd8e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
6 deletions
+98
-6
app/helpers/clusters_helper.rb
app/helpers/clusters_helper.rb
+22
-0
app/views/clusters/clusters/_cluster.html.haml
app/views/clusters/clusters/_cluster.html.haml
+1
-6
spec/helpers/clusters_helper_spec.rb
spec/helpers/clusters_helper_spec.rb
+75
-0
No files found.
app/helpers/clusters_helper.rb
View file @
9dc67bf1
...
...
@@ -6,6 +6,28 @@ module ClustersHelper
false
end
# We do not want to show the group path for clusters belonging to the
# clusterable, only for the ancestor clusters.
def
cluster_group_path_display
(
cluster
,
clusterable
)
if
cluster
.
group_type?
&&
cluster
.
group
.
id
!=
clusterable
.
id
group_path_shortened
(
cluster
.
group
)
end
end
def
group_path_shortened
(
group
)
components
=
group
.
full_path_components
breadcrumb
=
if
components
.
size
>
2
[
components
.
first
,
'…'
.
html_safe
,
components
.
last
]
else
components
end
breadcrumb
.
each_with_object
(
''
.
html_safe
)
do
|
component
,
string
|
string
.
concat
(
component
+
' / '
)
end
end
def
render_gcp_signup_offer
return
if
Gitlab
::
CurrentSettings
.
current_application_settings
.
hide_third_party_offers?
return
unless
show_gcp_signup_offer?
...
...
app/views/clusters/clusters/_cluster.html.haml
View file @
9dc67bf1
...
...
@@ -3,12 +3,7 @@
.table-section.section-60
.table-mobile-header
{
role:
"rowheader"
}=
s_
(
"ClusterIntegration|Kubernetes cluster"
)
.table-mobile-content
-
if
cluster
.
group_type?
&&
cluster
.
group
.
id
!=
clusterable
.
id
-
if
cluster
.
group
.
ancestors
.
any?
=
"
#{
cluster
.
group
.
ancestors
.
first
.
name
}
/"
-
if
cluster
.
group
.
ancestors
.
length
>
1
=
"… /"
.
html_safe
=
"
#{
cluster
.
group
.
name
}
/"
=
cluster_group_path_display
(
cluster
,
clusterable
)
=
link_to
cluster
.
name
,
cluster
.
show_path
-
unless
cluster
.
enabled?
%span
.badge.badge-danger
Connection disabled
...
...
spec/helpers/clusters_helper_spec.rb
0 → 100644
View file @
9dc67bf1
# frozen_string_literal: true
require
'spec_helper'
describe
ClustersHelper
do
describe
'#cluster_group_path_display'
do
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let
(
:cluster
)
{
create
(
:cluster
,
cluster_type: :group_type
,
groups:
[
group
])
}
let
(
:clusterable
)
{
group
}
subject
{
helper
.
cluster_group_path_display
(
cluster
,
clusterable
)
}
it
'returns nothing'
do
is_expected
.
to
be_nil
end
context
'for another clusterable'
do
let
(
:clusterable
)
{
create
(
:group
)
}
it
'returns the group path'
do
is_expected
.
to
eq
(
'group / '
)
end
end
context
'for a project cluster'
do
let
(
:cluster
)
{
create
(
:cluster
,
:project
)
}
let
(
:clusterable
)
{
cluster
.
project
}
it
'returns nothing'
do
is_expected
.
to
be_nil
end
end
end
describe
'#group_path_shortened'
do
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
subject
{
helper
.
group_path_shortened
(
group
)
}
it
'returns the group name with trailing slash'
do
is_expected
.
to
eq
(
'group / '
)
end
it
'escapes group name'
do
expect
(
CGI
).
to
receive
(
:escapeHTML
).
with
(
'group / '
).
and_call_original
subject
end
context
'subgroup'
,
:nested_groups
do
let
(
:root_group
)
{
create
(
:group
,
name:
'root'
)
}
let
(
:group
)
{
create
(
:group
,
name:
'group'
,
parent:
root_group
)
}
it
'returns the full path with trailing slash'
do
is_expected
.
to
eq
(
'root / group / '
)
end
it
'escapes group names'
do
expect
(
CGI
).
to
receive
(
:escapeHTML
).
with
(
'root / '
).
and_call_original
expect
(
CGI
).
to
receive
(
:escapeHTML
).
with
(
'group / '
).
and_call_original
subject
end
context
'deeper nested'
do
let
(
:next_group
)
{
create
(
:group
,
name:
'next'
,
parent:
root_group
)
}
let
(
:group
)
{
create
(
:group
,
name:
'group'
,
parent:
next_group
)
}
it
'returns a shorted path with trailing slash'
do
is_expected
.
to
eq
(
'root / … / group / '
)
end
end
end
end
end
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