debian-mirror-gitlab/spec/requests/api/keys_spec.rb

40 lines
1.1 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
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
2016-09-13 17:45:13 +05:30
it 'returns authentication error' do
2015-09-25 12:07:36 +05:30
get api("/keys/#{key.id}")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2015-09-25 12:07:36 +05:30
end
end
context 'when authenticated' do
2016-09-13 17:45:13 +05:30
it 'returns 404 for non-existing key' do
2015-09-25 12:07:36 +05:30
get api('/keys/999999', admin)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2015-09-25 12:07:36 +05:30
expect(json_response['message']).to eq('404 Not found')
end
2016-09-13 17:45:13 +05:30
it 'returns single ssh key with user information' do
2015-09-25 12:07:36 +05:30
user.keys << key
user.save
get api("/keys/#{key.id}", admin)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-09-25 12:07:36 +05:30
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