From 05e792b4c492e04aaa7e301432f71e01d63c02bc Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Tue, 15 Apr 2014 16:39:46 +0200 Subject: 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./ --- spec/requests/api/users_spec.rb | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'spec') 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 } -- cgit v1.2.3