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
ba077841
Commit
ba077841
authored
Jan 13, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add destroy functionality to save_multiple
parent
c64181ce
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
app/controllers/projects/variables_controller.rb
app/controllers/projects/variables_controller.rb
+9
-2
spec/controllers/projects/variables_controller_spec.rb
spec/controllers/projects/variables_controller_spec.rb
+20
-0
No files found.
app/controllers/projects/variables_controller.rb
View file @
ba077841
...
...
@@ -39,6 +39,7 @@ class Projects::VariablesController < Projects::ApplicationController
return
head
:bad_request
unless
@variables
.
all?
(
&
:valid?
)
@variables
.
each
(
&
:save
)
@variables_destroy
.
each
(
&
:destroy
)
head
:ok
end
end
...
...
@@ -75,10 +76,16 @@ class Projects::VariablesController < Projects::ApplicationController
end
def
variables
@variables
=
variables_params
[
:variables
].
map
do
|
variable_hash
|
destroy
,
edit
=
variables_params
[
:variables
].
partition
{
|
hash
|
hash
[
:_destroy
]
==
'true'
}
@variables
=
initialize_or_update_variables_from_hash
(
edit
)
@variables_destroy
=
initialize_or_update_variables_from_hash
(
destroy
)
end
def
initialize_or_update_variables_from_hash
(
hash
)
hash
.
map
do
|
variable_hash
|
variable
=
project
.
variables
.
where
(
key:
variable_hash
[
:key
])
.
first_or_initialize
(
variable_hash
).
present
(
current_user:
current_user
)
variable
.
assign_attributes
(
variable_hash
)
unless
variable
.
new_record?
variable
.
assign_attributes
(
variable_hash
.
except
(
:_destroy
)
)
unless
variable
.
new_record?
variable
end
end
...
...
spec/controllers/projects/variables_controller_spec.rb
View file @
ba077841
...
...
@@ -110,5 +110,25 @@ describe Projects::VariablesController do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
context
'with a deleted variable'
do
subject
do
post
:save_multiple
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables:
[{
key:
variable
.
key
,
value:
variable
.
value
,
_destroy:
'true'
}],
format: :json
end
it
'destroys the variable'
do
expect
{
subject
}.
to
change
{
project
.
variables
.
count
}.
by
(
-
1
)
expect
{
variable
.
reload
}.
to
raise_error
ActiveRecord
::
RecordNotFound
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