diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-06-27 12:05:20 +0300 |
---|---|---|
committer | Clement Ho <ClemMakesApps@gmail.com> | 2017-06-27 22:13:06 +0300 |
commit | f96e0c8434699b1644a4ce60e1b2d4b4c095ad4f (patch) | |
tree | 235554d02f63a94f7300cad21ee5e1ca2b55cdd0 | |
parent | 600ef885357700c101a1c389f07f8d85c44a262d (diff) |
Merge branch '34282-fix-api-using-include_missing-false' into 'master'
Fix optional arugments for POST :id/variables
Closes #34282
See merge request !12474
-rw-r--r-- | changelogs/unreleased/34282-fix-api-using-include_missing-false.yml | 4 | ||||
-rw-r--r-- | lib/api/variables.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/variables_spec.rb | 11 |
3 files changed, 16 insertions, 1 deletions
diff --git a/changelogs/unreleased/34282-fix-api-using-include_missing-false.yml b/changelogs/unreleased/34282-fix-api-using-include_missing-false.yml new file mode 100644 index 00000000000..e7fff2c1a9f --- /dev/null +++ b/changelogs/unreleased/34282-fix-api-using-include_missing-false.yml @@ -0,0 +1,4 @@ +--- +title: 'API: Fix optional arugments for POST :id/variables' +merge_request: 12474 +author: diff --git a/lib/api/variables.rb b/lib/api/variables.rb index 381c4ef50b0..10374995497 100644 --- a/lib/api/variables.rb +++ b/lib/api/variables.rb @@ -45,7 +45,7 @@ module API optional :protected, type: String, desc: 'Whether the variable is protected' end post ':id/variables' do - variable = user_project.variables.create(declared(params, include_parent_namespaces: false).to_h) + variable = user_project.variables.create(declared_params(include_missing: false)) if variable.valid? present variable, with: Entities::Variable diff --git a/spec/requests/api/variables_spec.rb b/spec/requests/api/variables_spec.rb index 83673864fe7..e0975024b80 100644 --- a/spec/requests/api/variables_spec.rb +++ b/spec/requests/api/variables_spec.rb @@ -82,6 +82,17 @@ describe API::Variables do expect(json_response['protected']).to be_truthy end + it 'creates variable with optional attributes' 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).to have_http_status(201) + expect(json_response['key']).to eq('TEST_VARIABLE_2') + expect(json_response['value']).to eq('VALUE_2') + expect(json_response['protected']).to be_falsey + end + it 'does not allow to duplicate variable key' do expect do post api("/projects/#{project.id}/variables", user), key: variable.key, value: 'VALUE_2' |