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
c0299ce4
Commit
c0299ce4
authored
Nov 03, 2017
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Projects::Clusters::ApplicationsController tests
parent
e6616e04
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
3 deletions
+76
-3
app/controllers/projects/clusters/applications_controller.rb
app/controllers/projects/clusters/applications_controller.rb
+1
-1
config/routes/project.rb
config/routes/project.rb
+1
-1
spec/controllers/projects/clusters/applications_controller_spec.rb
...rollers/projects/clusters/applications_controller_spec.rb
+73
-0
spec/support/matchers/access_matchers_for_controller.rb
spec/support/matchers/access_matchers_for_controller.rb
+1
-1
No files found.
app/controllers/projects/clusters/applications_controller.rb
View file @
c0299ce4
...
@@ -9,7 +9,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
...
@@ -9,7 +9,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
application_class:
@application_class
,
application_class:
@application_class
,
cluster:
@cluster
).
execute
cluster:
@cluster
).
execute
if
scheduled
if
scheduled
head
:no_
data
head
:no_
content
else
else
head
:bad_request
head
:bad_request
end
end
...
...
config/routes/project.rb
View file @
c0299ce4
...
@@ -192,7 +192,7 @@ constraints(ProjectUrlConstrainer.new) do
...
@@ -192,7 +192,7 @@ constraints(ProjectUrlConstrainer.new) do
get
:status
,
format: :json
get
:status
,
format: :json
scope
:applications
do
scope
:applications
do
post
'/*application'
,
to:
'clusters/applications#create'
post
'/*application'
,
to:
'clusters/applications#create'
,
as: :install_applications
end
end
end
end
end
end
...
...
spec/controllers/projects/clusters/applications_controller_spec.rb
0 → 100644
View file @
c0299ce4
require
'spec_helper'
describe
Projects
::
Clusters
::
ApplicationsController
do
include
AccessMatchersForController
def
current_application
Clusters
::
Cluster
::
APPLICATIONS
[
application
]
end
describe
'POST create'
do
let
(
:cluster
)
{
create
(
:cluster
,
:project
,
:providing_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
let
(
:application
)
{
'helm'
}
let
(
:params
)
{
{
application:
application
,
id:
cluster
.
id
}
}
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
it
'schedule an application installation'
do
expect
(
ClusterInstallAppWorker
).
to
receive
(
:perform_async
).
with
(
application
,
anything
).
once
expect
{
go
}.
to
change
{
current_application
.
count
}
expect
(
response
).
to
have_http_status
(
:no_content
)
expect
(
cluster
.
application_helm
).
to
be_scheduled
end
context
'when cluster do not exists'
do
before
do
cluster
.
destroy!
end
it
'return 404'
do
expect
{
go
}.
not_to
change
{
current_application
.
count
}
expect
(
response
).
to
have_http_status
(
:not_found
)
end
end
context
'when application is unknown'
do
let
(
:application
)
{
'unkwnown-app'
}
it
'return 404'
do
go
expect
(
response
).
to
have_http_status
(
:not_found
)
end
end
end
describe
'security'
do
before
do
allow
(
ClusterInstallAppWorker
).
to
receive
(
:perform_async
)
end
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
end
spec/support/matchers/access_matchers_for_controller.rb
View file @
c0299ce4
...
@@ -5,7 +5,7 @@ module AccessMatchersForController
...
@@ -5,7 +5,7 @@ module AccessMatchersForController
extend
RSpec
::
Matchers
::
DSL
extend
RSpec
::
Matchers
::
DSL
include
Warden
::
Test
::
Helpers
include
Warden
::
Test
::
Helpers
EXPECTED_STATUS_CODE_ALLOWED
=
[
200
,
201
,
302
].
freeze
EXPECTED_STATUS_CODE_ALLOWED
=
[
200
,
201
,
204
,
302
].
freeze
EXPECTED_STATUS_CODE_DENIED
=
[
401
,
404
].
freeze
EXPECTED_STATUS_CODE_DENIED
=
[
401
,
404
].
freeze
def
emulate_user
(
role
,
membership
=
nil
)
def
emulate_user
(
role
,
membership
=
nil
)
...
...
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