trigger sync in the auth endpoint, not the user model

This commit is contained in:
Sven Fuchs 2016-06-20 16:32:00 +02:00
parent da4c7f26e6
commit 6603990fe4
3 changed files with 6 additions and 5 deletions

View File

@ -289,6 +289,7 @@ class Travis::Api::App
user.update_attributes info
else
self.user = ::User.create! info
Travis.run_service(:sync_user, user)
end
Travis::Github::Oauth.track_scopes(user) # unless Travis.env == 'test'

View File

@ -62,9 +62,9 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
context 'without existing user' do
it 'creates new user' do
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', education: false }.stringify_keys
user = User.create(id: 1, login: 'drogus', github_id: 456)
User.expects(:create!).with(attributes).returns(user)
manager.stubs(:education).returns(false)

View File

@ -17,7 +17,7 @@ class User < Travis::Model
before_create :set_as_recent
after_create :create_a_token
after_commit :sync, on: :create
# after_commit :sync, on: :create
before_save :track_previous_changes
serialize :github_scopes
@ -66,9 +66,9 @@ class User < Travis::Model
synced_at.nil?
end
def sync
Travis.run_service(:sync_user, self) # TODO move to the authentication endpoint, or create a separate service
end
# def sync
# Travis.run_service(:sync_user, self) # TODO move to the authentication endpoint, or create a separate service
# end
def syncing?
is_syncing?