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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
8796e727
Commit
8796e727
authored
Nov 28, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ClustersFinder
parent
63b08da9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
15 deletions
+25
-15
app/finders/clusters_finder.rb
app/finders/clusters_finder.rb
+20
-10
spec/finders/clusters_finder_spec.rb
spec/finders/clusters_finder_spec.rb
+5
-5
No files found.
app/finders/clusters_finder.rb
View file @
8796e727
class
ClustersFinder
attr_reader
:project
,
:user
,
:scope
def
initialize
(
project
,
user
,
scope
)
@project
=
project
@user
=
user
@scope
=
scope
@scope
=
scope
||
:active
end
def
execute
clusters
=
case
@scope
when
:all
@project
.
clusters
when
:enabled
@project
.
clusters
.
enabled
when
:disabled
@project
.
clusters
.
disabled
end
clusters
.
map
{
|
cluster
|
cluster
.
present
(
current_user:
@user
)
}
clusters
=
project
.
clusters
filter_by_scope
(
clusters
)
end
private
def
filter_by_scope
(
clusters
)
case
@scope
.
to_sym
when
:all
clusters
when
:inactive
clusters
.
disabled
when
:active
clusters
.
enabled
else
raise
"Invalid scope
#{
@scope
}
"
end
end
end
spec/finders/clusters_finder_spec.rb
View file @
8796e727
...
...
@@ -15,19 +15,19 @@ describe ClustersFinder do
context
'when scope is all'
do
let
(
:scope
)
{
:all
}
it
{
is_expected
.
to
eq
(
project
.
clusters
.
to_a
)
}
it
{
is_expected
.
to
eq
(
project
.
clusters
)
}
end
context
'when scope is enabled'
do
let
(
:scope
)
{
:
enabled
}
let
(
:scope
)
{
:
active
}
it
{
is_expected
.
to
eq
(
project
.
clusters
.
enabled
.
to_a
)
}
it
{
is_expected
.
to
eq
(
project
.
clusters
.
enabled
)
}
end
context
'when scope is disabled'
do
let
(
:scope
)
{
:
disabled
}
let
(
:scope
)
{
:
inactive
}
it
{
is_expected
.
to
eq
(
project
.
clusters
.
disabled
.
to_a
)
}
it
{
is_expected
.
to
eq
(
project
.
clusters
.
disabled
)
}
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