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
Léo-Paul Géneau
gitlab-ce
Commits
121d84d7
Commit
121d84d7
authored
Jan 13, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement multiple variable handling action
parent
fe96a1f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
4 deletions
+70
-4
app/controllers/projects/variables_controller.rb
app/controllers/projects/variables_controller.rb
+18
-1
spec/controllers/projects/variables_controller_spec.rb
spec/controllers/projects/variables_controller_spec.rb
+52
-3
No files found.
app/controllers/projects/variables_controller.rb
View file @
121d84d7
...
...
@@ -33,7 +33,20 @@ class Projects::VariablesController < Projects::ApplicationController
end
def
save_multiple
head
:ok
respond_to
do
|
format
|
format
.
json
do
variables
=
[]
variables_params
[
:variables
].
each
do
|
variable_hash
|
variable
=
project
.
variables
.
where
(
key:
variable_hash
[
:key
]).
first_or_initialize
(
variable_hash
)
variable
.
assign_attributes
(
variable_hash
)
unless
variable
.
new_record?
return
head
:bad_request
unless
variable
.
valid?
variables
<<
variable
end
variables
.
each
{
|
variable
|
variable
.
save
}
end
head
:ok
end
end
def
destroy
...
...
@@ -54,6 +67,10 @@ class Projects::VariablesController < Projects::ApplicationController
params
.
require
(
:variable
).
permit
(
*
variable_params_attributes
)
end
def
variables_params
params
.
permit
(
variables:
[
*
variable_params_attributes
])
end
def
variable_params_attributes
%i[id key value protected _destroy]
end
...
...
spec/controllers/projects/variables_controller_spec.rb
View file @
121d84d7
...
...
@@ -57,9 +57,58 @@ describe Projects::VariablesController do
end
describe
'POST #save_multiple'
do
it
'returns a successful response'
do
post
:save_multiple
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
let
(
:variable
)
{
create
(
:ci_variable
)
}
before
do
project
.
variables
<<
variable
end
context
'with invalid new variable parameters'
do
subject
do
post
:save_multiple
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables:
[{
key:
variable
.
key
,
value:
'other_value'
},
{
key:
'..?'
,
value:
'dummy_value'
}],
format: :json
end
it
'does not update the existing variable'
do
expect
{
subject
}.
not_to
change
{
variable
.
reload
.
value
}
end
it
'does not create the new variable'
do
expect
{
subject
}.
not_to
change
{
project
.
variables
.
count
}
end
it
'returns a bad request response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with valid new variable parameters'
do
subject
do
post
:save_multiple
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables:
[{
key:
variable
.
key
,
value:
'other_value'
},
{
key:
'new_key'
,
value:
'dummy_value'
}],
format: :json
end
it
'updates the existing variable'
do
expect
{
subject
}.
to
change
{
variable
.
reload
.
value
}.
to
(
'other_value'
)
end
it
'creates the new variable'
do
expect
{
subject
}.
to
change
{
project
.
variables
.
count
}.
by
(
1
)
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
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