Merge branch 'rename-fixes'

Conflicts:
	Gemfile.lock
	lib/travis/api/app/endpoint.rb
This commit is contained in:
Piotr Sarnacki 2013-07-23 17:08:17 +02:00
commit c4ebb3d922
3 changed files with 14 additions and 7 deletions

View File

@ -31,7 +31,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: 6e4fea97354782ea89acc26f1cc291980ee2462c
revision: 0a194c97c857a39c03a5a02eec283e751099d402
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.12)

View File

@ -196,6 +196,8 @@ class Travis::Api::App
end
class UserManager < Struct.new(:data, :token, :drop_token)
include User::Renaming
def info(attributes = {})
info = data.to_hash.slice('name', 'login', 'gravatar_id')
info.merge! attributes.stringify_keys
@ -207,10 +209,15 @@ class Travis::Api::App
user = ::User.find_by_github_id(data['id'])
info = drop_token ? info : info(github_oauth_token: token)
if user
user.update_attributes info
else
user = ::User.create! info
ActiveRecord::Base.transaction do
if user
rename_repos_owner(user.login, info['login'])
user.update_attributes info
else
user = ::User.create! info
end
nullify_logins(user.github_id, user.login)
end
user

View File

@ -31,7 +31,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
context 'with existing user' do
it 'updates user data' do
user = mock('user')
user = stub('user', login: 'drogus', github_id: 456)
User.expects(:find_by_github_id).with(456).returns(user)
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
user.expects(:update_attributes).with(attributes)
@ -42,7 +42,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
context 'without existing user' do
it 'creates new user' do
user = mock('user')
user = stub('user', login: 'drogus', github_id: 456)
User.expects(:find_by_github_id).with(456).returns(nil)
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
User.expects(:create!).with(attributes).returns(user)