Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2016-01-01 00:30:07 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2016-01-01 00:30:07 +0300
commit937567b767e6d7b34dcaa1d9c83fc75464638683 (patch)
tree2e3dc598ddd4c06c8a0ce2d33a1d55f40fd61e7e /spec/requests/api
parentc5177dd5e2171b047a695802c979cf779522ba8a (diff)
Add create feature to variables API
Diffstat (limited to 'spec/requests/api')
-rw-r--r--spec/requests/api/variables_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/requests/api/variables_spec.rb b/spec/requests/api/variables_spec.rb
index b35ee2d32d1..bf0dd77473a 100644
--- a/spec/requests/api/variables_spec.rb
+++ b/spec/requests/api/variables_spec.rb
@@ -79,6 +79,44 @@ describe API::API, api: true do
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
context 'authorized user with proper permissions' do
it 'should update variable data' do