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
Jérome Perrin
gitlab-ce
Commits
937567b7
Commit
937567b7
authored
Dec 31, 2015
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add create feature to variables API
parent
c5177dd5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
1 deletion
+59
-1
lib/api/variables.rb
lib/api/variables.rb
+20
-0
spec/factories/ci/variables.rb
spec/factories/ci/variables.rb
+1
-1
spec/requests/api/variables_spec.rb
spec/requests/api/variables_spec.rb
+38
-0
No files found.
lib/api/variables.rb
View file @
937567b7
...
@@ -41,6 +41,24 @@ module API
...
@@ -41,6 +41,24 @@ module API
present
variables
.
first
,
with:
Entities
::
Variable
present
variables
.
first
,
with:
Entities
::
Variable
end
end
# Create a new variable in project
#
# Parameters:
# id (required) - The ID of a project
# key (required) - The key of variable being created
# value (required) - The value of variable being created
# Example Request:
# POST /projects/:id/variables
post
':id/variables'
do
required_attributes!
[
:key
,
:value
]
variable
=
user_project
.
variables
.
create
(
key:
params
[
:key
],
value:
params
[
:value
])
return
render_validation_error!
(
variable
)
unless
variable
.
valid?
variable
.
save!
present
variable
,
with:
Entities
::
Variable
end
# Update existing variable of a project
# Update existing variable of a project
#
#
# Parameters:
# Parameters:
...
@@ -75,6 +93,8 @@ module API
...
@@ -75,6 +93,8 @@ module API
return
not_found!
(
'Variable'
)
unless
variable
return
not_found!
(
'Variable'
)
unless
variable
variable
.
destroy
variable
.
destroy
present
variable
,
with:
Entities
::
Variable
end
end
end
end
end
end
...
...
spec/factories/ci/variables.rb
View file @
937567b7
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:ci_variable
,
class:
Ci
::
Variable
do
factory
:ci_variable
,
class:
Ci
::
Variable
do
id
1
id
1
0
key
'TEST_VARIABLE_1'
key
'TEST_VARIABLE_1'
value
'VALUE_1'
value
'VALUE_1'
...
...
spec/requests/api/variables_spec.rb
View file @
937567b7
...
@@ -79,6 +79,44 @@ describe API::API, api: true do
...
@@ -79,6 +79,44 @@ describe API::API, api: true do
end
end
end
end
describe
'POST /projects/:id/variables'
do
context
'authorized user with proper permissions'
do
it
'should create variable'
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user
),
key:
'TEST_VARIABLE_2'
,
value:
'VALUE_2'
end
.
to
change
{
project
.
variables
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
'key'
]).
to
eq
(
'TEST_VARIABLE_2'
)
expect
(
json_response
[
'value'
]).
to
eq
(
'VALUE_2'
)
end
it
'should not allow to duplicate variable key'
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user
),
key:
'TEST_VARIABLE_1'
,
value:
'VALUE_2'
end
.
to
change
{
project
.
variables
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
400
)
end
end
context
'authorized user with invalid permissions'
do
it
'should not create variable'
do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'unauthorized user'
do
it
'should not create variable'
do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
describe
'PUT /projects/:id/variables/:variable_id'
do
describe
'PUT /projects/:id/variables/:variable_id'
do
context
'authorized user with proper permissions'
do
context
'authorized user with proper permissions'
do
it
'should update variable data'
do
it
'should update variable data'
do
...
...
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