From 6603990fe4aa43beb932e90d7071b3e2894f4646 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 20 Jun 2016 16:32:00 +0200 Subject: [PATCH] trigger sync in the auth endpoint, not the user model --- lib/travis/api/app/endpoint/authorization.rb | 1 + spec/unit/endpoint/authorization/user_manager_spec.rb | 2 +- vendor/travis-core/lib/travis/model/user.rb | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index f89a9bd6..2343c2d5 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -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' diff --git a/spec/unit/endpoint/authorization/user_manager_spec.rb b/spec/unit/endpoint/authorization/user_manager_spec.rb index 0954c131..9f3acf40 100644 --- a/spec/unit/endpoint/authorization/user_manager_spec.rb +++ b/spec/unit/endpoint/authorization/user_manager_spec.rb @@ -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) diff --git a/vendor/travis-core/lib/travis/model/user.rb b/vendor/travis-core/lib/travis/model/user.rb index 9cfe0fcf..d2dedc8d 100644 --- a/vendor/travis-core/lib/travis/model/user.rb +++ b/vendor/travis-core/lib/travis/model/user.rb @@ -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?