diff options
author | Artem V. Navrotskiy <bozaro@users.noreply.github.com> | 2015-08-29 12:52:21 +0300 |
---|---|---|
committer | Artem V. Navrotskiy <navrotskiy@corp.mail.ru> | 2015-09-03 15:47:22 +0300 |
commit | 8ec59bd18bcacf13c012a34b3e37c2c9167bcc65 (patch) | |
tree | 4b654ce3e78bb82e5341fb13ca36a5c7005398bf /spec/requests | |
parent | ff8fb6a6a26578c02f04a2f7450a769b2f293d58 (diff) | |
download | gitlab-ce-8ec59bd18bcacf13c012a34b3e37c2c9167bcc65.tar.gz |
Add API method for get user by ID of an SSH key
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/keys_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/requests/api/keys_spec.rb b/spec/requests/api/keys_spec.rb new file mode 100644 index 00000000000..d2b87f88712 --- /dev/null +++ b/spec/requests/api/keys_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe API::API, api: true do + include ApiHelpers + + let(:user) { create(:user) } + let(:admin) { create(:admin) } + let(:key) { create(:key, user: user) } + let(:email) { create(:email, user: user) } + + describe 'GET /keys/:uid' do + before { admin } + + context 'when unauthenticated' do + it 'should return authentication error' do + get api("/keys/#{key.id}") + expect(response.status).to eq(401) + end + end + + context 'when authenticated' do + it 'should return 404 for non-existing key' do + get api('/keys/999999', admin) + expect(response.status).to eq(404) + expect(json_response['message']).to eq('404 Not found') + end + + it 'should return single ssh key with user information' do + user.keys << key + user.save + get api("/keys/#{key.id}", admin) + expect(response.status).to eq(200) + expect(json_response['title']).to eq(key.title) + expect(json_response['user']['id']).to eq(user.id) + expect(json_response['user']['username']).to eq(user.username) + end + end + end +end |