Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/gitlab/client/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,15 @@ def deploy_key(project, id)
# Creates a new deploy key.
#
# @example
# Gitlab.create_deploy_key(42, 'My Key', 'Key contents')
# Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true)
#
# @param [Integer, String] project The ID or path of a project.
# @param [String] title The title of a deploy key.
# @param [String] key The content of a deploy key.
# @param [Hash] options A customizable set of options.
# @return [Gitlab::ObjectifiedHash] Information about created deploy key.
def create_deploy_key(project, title, key)
post("/projects/#{url_encode project}/deploy_keys", body: { title: title, key: key })
def create_deploy_key(project, title, key, options = {})
post("/projects/#{url_encode project}/deploy_keys", body: { title: title, key: key }.merge(options))
end

# Enables a deploy key at the project.
Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/project_key.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": 2,
"title": "Key Title",
"key": "ssh-rsa ...",
"can_push": false,
"created_at": "2013-09-22T18:34:32Z"
}
}
3 changes: 2 additions & 1 deletion spec/fixtures/project_keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": 2,
"title": "Key Title",
"key": "ssh-rsa ...",
"can_push": false,
"created_at": "2013-09-22T18:34:32Z"
}]
}]
34 changes: 34 additions & 0 deletions spec/gitlab/client/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,40 @@
end
end

describe ".create_deploy_key" do
context 'no options' do
before do
stub_post("/projects/42/deploy_keys", "project_key")
@deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents')
end

it "gets the correct resource" do
expect(a_post("/projects/42/deploy_keys").
with(body: { title: 'My Key', key: 'Key contents' })).to have_been_made
end

it "returns information about a created key" do
expect(@deploy_key.id).to eq(2)
end
end

context 'some options' do
before do
stub_post("/projects/42/deploy_keys", "project_key")
@deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true)
end

it "gets the correct resource" do
expect(a_post("/projects/42/deploy_keys").
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed a bracket there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh indeed: will fix.

with(body: { title: 'My Key', key: 'Key contents', can_push: true })).to have_been_made
end

it "returns information about a created key" do
expect(@deploy_key.id).to eq(2)
end
end
end

describe ".delete_deploy_key" do
before do
stub_delete("/projects/42/deploy_keys/2", "project_key")
Expand Down