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
cc2bed92
Commit
cc2bed92
authored
Jan 23, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port #save_multiple to Groups::VariablesController
parent
edbe911b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
7 deletions
+96
-7
app/controllers/groups/variables_controller.rb
app/controllers/groups/variables_controller.rb
+15
-1
app/models/group.rb
app/models/group.rb
+2
-0
config/routes/group.rb
config/routes/group.rb
+5
-1
spec/controllers/groups/variables_controller_spec.rb
spec/controllers/groups/variables_controller_spec.rb
+74
-5
No files found.
app/controllers/groups/variables_controller.rb
View file @
cc2bed92
...
@@ -31,6 +31,16 @@ module Groups
...
@@ -31,6 +31,16 @@ module Groups
end
end
end
end
def
save_multiple
respond_to
do
|
format
|
format
.
json
do
return
head
:ok
if
@group
.
update
(
variables_params
)
head
:bad_request
end
end
end
def
destroy
def
destroy
if
variable
.
destroy
if
variable
.
destroy
redirect_to
group_settings_ci_cd_path
(
group
),
redirect_to
group_settings_ci_cd_path
(
group
),
...
@@ -49,8 +59,12 @@ module Groups
...
@@ -49,8 +59,12 @@ module Groups
params
.
require
(
:variable
).
permit
(
*
variable_params_attributes
)
params
.
require
(
:variable
).
permit
(
*
variable_params_attributes
)
end
end
def
variables_params
params
.
permit
(
variables_attributes:
[
*
variable_params_attributes
])
end
def
variable_params_attributes
def
variable_params_attributes
%i[
key value protected
]
%i[
id key value protected _destroy
]
end
end
def
variable
def
variable
...
...
app/models/group.rb
View file @
cc2bed92
...
@@ -31,6 +31,8 @@ class Group < Namespace
...
@@ -31,6 +31,8 @@ class Group < Namespace
has_many
:uploads
,
as: :model
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:uploads
,
as: :model
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
accepts_nested_attributes_for
:variables
,
allow_destroy:
true
validate
:visibility_level_allowed_by_projects
validate
:visibility_level_allowed_by_projects
validate
:visibility_level_allowed_by_sub_groups
validate
:visibility_level_allowed_by_sub_groups
validate
:visibility_level_allowed_by_parent
validate
:visibility_level_allowed_by_parent
...
...
config/routes/group.rb
View file @
cc2bed92
...
@@ -27,7 +27,11 @@ constraints(GroupUrlConstrainer.new) do
...
@@ -27,7 +27,11 @@ constraints(GroupUrlConstrainer.new) do
resource
:ci_cd
,
only:
[
:show
],
controller:
'ci_cd'
resource
:ci_cd
,
only:
[
:show
],
controller:
'ci_cd'
end
end
resources
:variables
,
only:
[
:index
,
:show
,
:update
,
:create
,
:destroy
]
resources
:variables
,
only:
[
:index
,
:show
,
:update
,
:create
,
:destroy
]
do
collection
do
post
:save_multiple
end
end
resources
:children
,
only:
[
:index
]
resources
:children
,
only:
[
:index
]
...
...
spec/controllers/groups/variables_controller_spec.rb
View file @
cc2bed92
...
@@ -29,13 +29,9 @@ describe Groups::VariablesController do
...
@@ -29,13 +29,9 @@ describe Groups::VariablesController do
end
end
describe
'POST #update'
do
describe
'POST #update'
do
let
(
:variable
)
{
create
(
:ci_group_variable
)
}
let
!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
context
'updating a variable with valid characters'
do
context
'updating a variable with valid characters'
do
before
do
group
.
variables
<<
variable
end
it
'shows a success flash message'
do
it
'shows a success flash message'
do
post
:update
,
group_id:
group
,
post
:update
,
group_id:
group
,
id:
variable
.
id
,
variable:
{
key:
variable
.
key
,
value:
'two'
}
id:
variable
.
id
,
variable:
{
key:
variable
.
key
,
value:
'two'
}
...
@@ -53,4 +49,77 @@ describe Groups::VariablesController do
...
@@ -53,4 +49,77 @@ describe Groups::VariablesController do
end
end
end
end
end
end
describe
'POST #save_multiple'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
context
'with invalid new variable parameters'
do
subject
do
post
:save_multiple
,
group_id:
group
,
variables_attributes:
[{
id:
variable
.
id
,
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
{
group
.
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
,
group_id:
group
,
variables_attributes:
[{
id:
variable
.
id
,
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
{
group
.
variables
.
count
}.
by
(
1
)
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
context
'with a deleted variable'
do
subject
do
post
:save_multiple
,
group_id:
group
,
variables_attributes:
[{
id:
variable
.
id
,
key:
variable
.
key
,
value:
variable
.
value
,
_destroy:
'true'
}],
format: :json
end
it
'destroys the variable'
do
expect
{
subject
}.
to
change
{
group
.
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
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