implement profile endpoint

This commit is contained in:
Konstantin Haase 2012-08-15 01:19:13 +02:00
parent f05ea7198b
commit 8e179dde4d
2 changed files with 40 additions and 4 deletions

View File

@ -2,10 +2,23 @@ require 'travis/api/app'
class Travis::Api::App
class Endpoint
# TODO: Add documentation.
class Profile < Endpoint
# TODO: Add implementation and documentation.
get('/', scope: :private) { raise NotImplementedError }
# Gives information about the currently logged in user.
#
# Example:
#
# {
# "user": {
# "email": "svenfuchs@artweb-design.de",
# "gravatar_id": "402602a60e500e85f2f5dc1ff3648ecb",
# "is_syncing": false,
# "locale": "de",
# "login": "svenfuchs",
# "name": "Sven Fuchs",
# "synced_at": "2012-08-14T22:11:21Z"
# }
# }
get('/', scope: :private) { body(user) }
# TODO: Add implementation and documentation.
post('/sync', scope: :private) { raise NotImplementedError }

View File

@ -1,5 +1,28 @@
require 'spec_helper'
describe Travis::Api::App::Endpoint::Profile do
it 'has to be tested'
include Travis::Testing::Stubs
let(:access_token) { Travis::Api::App::AccessToken.create(user: user) }
before do
User.stubs(:find_by_login).with(user.login).returns(user)
User.stubs(:find).with(user.id).returns(user)
end
it 'needs to be authenticated' do
get('/profile').should_not be_ok
end
it 'replies with the current user' do
get('/profile', access_token: access_token.to_s).should be_ok
parsed_body["user"].should == {
"login" => user.login,
"name" => user.name,
"email" => user.email,
"gravatar_id" => user.gravatar_id,
"locale" => user.locale,
"is_syncing" => user.is_syncing,
"synced_at" => user.synced_at.strftime('%Y-%m-%dT%H:%M:%SZ')
}
end
end