Commit efc5fbfd authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '34282-fix-api-using-include_missing-false' into 'master'

Fix optional arugments for POST :id/variables

Closes #34282

See merge request !12474
parents 018f7e46 f8de6d65
---
title: 'API: Fix optional arugments for POST :id/variables'
merge_request: 12474
author:
...@@ -45,7 +45,7 @@ module API ...@@ -45,7 +45,7 @@ module API
optional :protected, type: String, desc: 'Whether the variable is protected' optional :protected, type: String, desc: 'Whether the variable is protected'
end end
post ':id/variables' do 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? if variable.valid?
present variable, with: Entities::Variable present variable, with: Entities::Variable
......
...@@ -82,6 +82,17 @@ describe API::Variables do ...@@ -82,6 +82,17 @@ describe API::Variables do
expect(json_response['protected']).to be_truthy expect(json_response['protected']).to be_truthy
end 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 it 'does not allow to duplicate variable key' do
expect do expect do
post api("/projects/#{project.id}/variables", user), key: variable.key, value: 'VALUE_2' post api("/projects/#{project.id}/variables", user), key: variable.key, value: 'VALUE_2'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment