try fixing updating github oauth scopes

This commit is contained in:
Sven Fuchs 2016-06-21 13:59:12 +02:00
parent 7250656de0
commit 25f74defe5
4 changed files with 11 additions and 11 deletions

View File

@ -292,7 +292,7 @@ class Travis::Api::App
Travis.run_service(:sync_user, user)
end
Travis::Github::Oauth.track_scopes(user) # unless Travis.env == 'test'
Travis::Github::Oauth.update_scopes(user) # unless Travis.env == 'test'
nullify_logins(user.github_id, user.login)
end

View File

@ -3,7 +3,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
before do
Travis::Features.enable_for_all(:education_data_sync)
Travis::Github::Oauth.stubs(:track_scopes) # TODO test that scopes are being updated
Travis::Github::Oauth.stubs(:update_scopes) # TODO test that scopes are being updated
end
describe '#info' do

View File

@ -20,7 +20,7 @@ describe Travis::Github::Oauth do
end
end
describe 'track_scopes' do
describe 'update_scopes' do
before { user.reload }
describe 'the token did not change' do
@ -28,7 +28,7 @@ describe Travis::Github::Oauth do
it 'does not resolve github scopes' do
Travis::Github::Oauth.expects(:scopes_for).never
described_class.track_scopes(user)
described_class.update_scopes(user)
end
end
@ -42,7 +42,7 @@ describe Travis::Github::Oauth do
it 'updates github scopes' do
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
described_class.track_scopes(user)
described_class.update_scopes(user)
expect(user.reload.github_scopes).to eq ['foo', 'bar']
end
end
@ -57,7 +57,7 @@ describe Travis::Github::Oauth do
it 'updates github scopes' do
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
described_class.track_scopes(user)
described_class.update_scopes(user)
expect(user.reload.github_scopes).to eq ['foo', 'bar']
end
end

View File

@ -1,7 +1,7 @@
module Travis
module Github
module Oauth
class TrackScopes < Struct.new(:user)
class UpdateScopes < Struct.new(:user)
def run
update if update?
end
@ -14,17 +14,17 @@ module Travis
end
def update?
github_oauth_token_changed?(user) or user.github_scopes.blank?
token_changed?(user) or not Oauth.correct_scopes?(user)
end
def github_oauth_token_changed?(user)
def token_changed?(user)
user.github_oauth_token_changed? or user.previous_changes.key?('github_oauth_token')
end
end
class << self
def track_scopes(user)
TrackScopes.new(user).run
def update_scopes(user)
UpdateScopes.new(user).run
end
def correct_scopes?(user)