diff options
author | Timm Friebe <thekid@thekid.de> | 2014-04-15 16:39:46 +0200 |
---|---|---|
committer | Timm Friebe <thekid@thekid.de> | 2014-04-18 14:16:19 +0200 |
commit | 05e792b4c492e04aaa7e301432f71e01d63c02bc (patch) | |
tree | cafed848f51b017459a8bb4a2e5c0f003c3c8fa2 /spec/requests | |
parent | cd6232187b707b0a278bd91986ec85dcfe66046f (diff) | |
download | gitlab-ce-05e792b4c492e04aaa7e301432f71e01d63c02bc.tar.gz |
Implement GET /users/:uid/keys for admin users
Complements POST operation added in gitlabhq/gitlabhq#3146
Implement DELETE /users/:uid/keys/:id for admin users
Fix "Line is too long. [83/80]"
Use single quotes as advised
Use single quotes as advised
Use single quotes as advised
Fix missing space around { and }
Fix typo in documentation
Only catch ActiveRecord::RecordNotFound, let other exceptions propagate
Raise a "404 Not found" if key to be deleted cannot be found
As requested by @jvanbaarsen in https://github.com/gitlabhq/gitlabhq/pull/6781#discussion_r11735114
Remove tab
Unconfigured vim on this box, grrrr./
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/users_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 86610c47513..a6d300b099b 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -242,6 +242,67 @@ describe API::API, api: true do end end + describe 'GET /user/:uid/keys' do + before { admin } + + context 'when unauthenticated' do + it 'should return authentication error' do + get api("/users/#{user.id}/keys") + response.status.should == 401 + end + end + + context 'when authenticated' do + it 'should return 404 for non-existing user' do + get api('/users/999999/keys', admin) + response.status.should == 404 + end + + it 'should return array of ssh keys' do + user.keys << key + user.save + get api("/users/#{user.id}/keys", admin) + response.status.should == 200 + json_response.should be_an Array + json_response.first['title'].should == key.title + end + end + end + + describe 'DELETE /user/:uid/keys/:id' do + before { admin } + + context 'when unauthenticated' do + it 'should return authentication error' do + delete api("/users/#{user.id}/keys/42") + response.status.should == 401 + end + end + + context 'when authenticated' do + it 'should delete existing key' do + user.keys << key + user.save + expect { + delete api("/users/#{user.id}/keys/#{key.id}", admin) + }.to change { user.keys.count }.by(-1) + response.status.should == 200 + end + + it 'should return 404 error if user not found' do + user.keys << key + user.save + delete api("/users/999999/keys/#{key.id}", admin) + response.status.should == 404 + end + + it 'should return 404 error if key not foud' do + delete api("/users/#{user.id}/keys/42", admin) + response.status.should == 404 + end + end + end + describe "DELETE /users/:id" do before { admin } |