diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-06 07:43:45 -0800 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-06 07:43:45 -0800 |
commit | afee5303ff3a31d4b3eca82e19c7a326f2c86659 (patch) | |
tree | 7ae515b3f1bbbdcad5fcb30898466b712fda4349 /spec/requests | |
parent | 65d78253cb289091a4eb389bada11828849d434c (diff) | |
parent | f411772e3395f569da893dd1fc0fd666dcbb5caa (diff) | |
download | gitlab-ce-afee5303ff3a31d4b3eca82e19c7a326f2c86659.tar.gz |
Merge pull request #3149 from m4tthumphrey/api-deploy-keys
Added methods to manage project deploy keys via API
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/projects_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index d410885bd22..422ccbf6f68 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -11,6 +11,8 @@ describe Gitlab::API do let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } + let(:key) { create(:key, project: project) } + before { project.team << [user, :reporter] } describe "GET /projects" do @@ -380,4 +382,59 @@ describe Gitlab::API do response.status.should == 404 end end + + describe "GET /projects/:id/keys" do + it "should return array of ssh keys" do + project.deploy_keys << key + project.save + get api("/projects/#{project.id}/keys", user) + response.status.should == 200 + json_response.should be_an Array + json_response.first['title'].should == key.title + end + end + + describe "GET /projects/:id/keys/:key_id" do + it "should return a single key" do + project.deploy_keys << key + project.save + get api("/projects/#{project.id}/keys/#{key.id}", user) + response.status.should == 200 + json_response['title'].should == key.title + end + + it "should return 404 Not Found with invalid ID" do + get api("/projects/#{project.id}/keys/404", user) + response.status.should == 404 + end + end + + describe "POST /projects/:id/keys" do + it "should not create an invalid ssh key" do + post api("/projects/#{project.id}/keys", user), { title: "invalid key" } + response.status.should == 404 + end + + it "should create new ssh key" do + key_attrs = attributes_for :key + expect { + post api("/projects/#{project.id}/keys", user), key_attrs + }.to change{ project.deploy_keys.count }.by(1) + end + end + + describe "DELETE /projects/:id/keys/:key_id" do + it "should delete existing key" do + project.deploy_keys << key + project.save + expect { + delete api("/projects/#{project.id}/keys/#{key.id}", user) + }.to change{ project.deploy_keys.count }.by(-1) + end + + it "should return 404 Not Found with invalid ID" do + delete api("/projects/#{project.id}/keys/404", user) + response.status.should == 404 + end + end end |