Merge branch 'rename-fixes'
Conflicts: Gemfile.lock lib/travis/api/app/endpoint.rb
This commit is contained in:
commit
c4ebb3d922
|
@ -31,7 +31,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-core.git
|
remote: git://github.com/travis-ci/travis-core.git
|
||||||
revision: 6e4fea97354782ea89acc26f1cc291980ee2462c
|
revision: 0a194c97c857a39c03a5a02eec283e751099d402
|
||||||
specs:
|
specs:
|
||||||
travis-core (0.0.1)
|
travis-core (0.0.1)
|
||||||
actionmailer (~> 3.2.12)
|
actionmailer (~> 3.2.12)
|
||||||
|
|
|
@ -196,6 +196,8 @@ class Travis::Api::App
|
||||||
end
|
end
|
||||||
|
|
||||||
class UserManager < Struct.new(:data, :token, :drop_token)
|
class UserManager < Struct.new(:data, :token, :drop_token)
|
||||||
|
include User::Renaming
|
||||||
|
|
||||||
def info(attributes = {})
|
def info(attributes = {})
|
||||||
info = data.to_hash.slice('name', 'login', 'gravatar_id')
|
info = data.to_hash.slice('name', 'login', 'gravatar_id')
|
||||||
info.merge! attributes.stringify_keys
|
info.merge! attributes.stringify_keys
|
||||||
|
@ -207,12 +209,17 @@ class Travis::Api::App
|
||||||
user = ::User.find_by_github_id(data['id'])
|
user = ::User.find_by_github_id(data['id'])
|
||||||
info = drop_token ? info : info(github_oauth_token: token)
|
info = drop_token ? info : info(github_oauth_token: token)
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
if user
|
if user
|
||||||
|
rename_repos_owner(user.login, info['login'])
|
||||||
user.update_attributes info
|
user.update_attributes info
|
||||||
else
|
else
|
||||||
user = ::User.create! info
|
user = ::User.create! info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
nullify_logins(user.github_id, user.login)
|
||||||
|
end
|
||||||
|
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
|
|
||||||
context 'with existing user' do
|
context 'with existing user' do
|
||||||
it 'updates user data' 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)
|
User.expects(:find_by_github_id).with(456).returns(user)
|
||||||
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
|
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
|
||||||
user.expects(:update_attributes).with(attributes)
|
user.expects(:update_attributes).with(attributes)
|
||||||
|
@ -42,7 +42,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
|
|
||||||
context 'without existing user' do
|
context 'without existing user' do
|
||||||
it 'creates new 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)
|
User.expects(:find_by_github_id).with(456).returns(nil)
|
||||||
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
|
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
|
||||||
User.expects(:create!).with(attributes).returns(user)
|
User.expects(:create!).with(attributes).returns(user)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user