Merge pull request #133 from travis-ci/ps-education
Check for user education status on signin/signup
This commit is contained in:
commit
b0684fa988
|
@ -37,7 +37,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-core.git
|
remote: git://github.com/travis-ci/travis-core.git
|
||||||
revision: 0c4922f7cbf644ccc97677643bb09f26a919e64c
|
revision: c33c0d40306e2493d4b65ca00be6731a4e614bed
|
||||||
specs:
|
specs:
|
||||||
travis-core (0.0.1)
|
travis-core (0.0.1)
|
||||||
actionmailer (~> 3.2.19)
|
actionmailer (~> 3.2.19)
|
||||||
|
|
|
@ -216,6 +216,10 @@ class Travis::Api::App
|
||||||
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
|
||||||
|
if Travis::Features.feature_active?(:education_data_sync) ||
|
||||||
|
(user && Travis::Features.owner_active?(:education_data_sync, user))
|
||||||
|
info['education'] = education
|
||||||
|
end
|
||||||
info['github_id'] ||= data['id']
|
info['github_id'] ||= data['id']
|
||||||
info
|
info
|
||||||
end
|
end
|
||||||
|
@ -224,6 +228,10 @@ class Travis::Api::App
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def education
|
||||||
|
Travis::Github::Education.new(token.to_s).student?
|
||||||
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
retried ||= false
|
retried ||= false
|
||||||
info = drop_token ? self.info : self.info(github_oauth_token: token)
|
info = drop_token ? self.info : self.info(github_oauth_token: token)
|
||||||
|
|
|
@ -3,6 +3,10 @@ require 'spec_helper'
|
||||||
describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
let(:manager) { described_class.new(data, 'abc123') }
|
let(:manager) { described_class.new(data, 'abc123') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Travis::Features.enable_for_all(:education_data_sync)
|
||||||
|
end
|
||||||
|
|
||||||
describe '#info' do
|
describe '#info' do
|
||||||
let(:data) {
|
let(:data) {
|
||||||
{
|
{
|
||||||
|
@ -10,32 +14,35 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
}.stringify_keys
|
}.stringify_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
before { manager.stubs(:education).returns(false) }
|
||||||
|
|
||||||
it 'gets data from github payload' do
|
it 'gets data from github payload' do
|
||||||
manager.info.should == {
|
manager.info.should == {
|
||||||
name: 'Piotr Sarnacki', login: 'drogus', gravatar_id: '123', github_id: 456
|
name: 'Piotr Sarnacki', login: 'drogus', gravatar_id: '123', github_id: 456, education: false
|
||||||
}.stringify_keys
|
}.stringify_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allows to overwrite existing keys' do
|
it 'allows to overwrite existing keys' do
|
||||||
manager.info({login: 'piotr.sarnacki', bar: 'baz'}.stringify_keys).should == {
|
manager.info({login: 'piotr.sarnacki', bar: 'baz'}.stringify_keys).should == {
|
||||||
name: 'Piotr Sarnacki', login: 'piotr.sarnacki', gravatar_id: '123',
|
name: 'Piotr Sarnacki', login: 'piotr.sarnacki', gravatar_id: '123',
|
||||||
github_id: 456, bar: 'baz'
|
github_id: 456, bar: 'baz', education: false
|
||||||
}.stringify_keys
|
}.stringify_keys
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#fetch' do
|
describe '#fetch' do
|
||||||
let(:data) {
|
let(:data) {
|
||||||
{ login: 'drogus', id: 456 }.stringify_keys
|
{ login: 'drogus', id: 456 }.stringify_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
it 'drops the token when drop_token is set to true' do
|
it 'drops the token when drop_token is set to true' do
|
||||||
user = stub('user', login: 'drogus', github_id: 456)
|
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)
|
||||||
|
|
||||||
manager = described_class.new(data, 'abc123', true)
|
manager = described_class.new(data, 'abc123', true)
|
||||||
|
manager.stubs(:education).returns(false)
|
||||||
|
|
||||||
attributes = { login: 'drogus', github_id: 456 }.stringify_keys
|
attributes = { login: 'drogus', github_id: 456, education: false }.stringify_keys
|
||||||
|
|
||||||
user.expects(:update_attributes).with(attributes)
|
user.expects(:update_attributes).with(attributes)
|
||||||
|
|
||||||
|
@ -46,8 +53,9 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
it 'updates user data' do
|
it 'updates user data' do
|
||||||
user = stub('user', login: 'drogus', github_id: 456)
|
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', education: false }.stringify_keys
|
||||||
user.expects(:update_attributes).with(attributes)
|
user.expects(:update_attributes).with(attributes)
|
||||||
|
manager.stubs(:education).returns(false)
|
||||||
|
|
||||||
manager.fetch.should == user
|
manager.fetch.should == user
|
||||||
end
|
end
|
||||||
|
@ -57,11 +65,23 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
it 'creates new user' do
|
it 'creates new user' do
|
||||||
user = stub('user', login: 'drogus', github_id: 456)
|
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', education: false }.stringify_keys
|
||||||
User.expects(:create!).with(attributes).returns(user)
|
User.expects(:create!).with(attributes).returns(user)
|
||||||
|
manager.stubs(:education).returns(false)
|
||||||
|
|
||||||
manager.fetch.should == user
|
manager.fetch.should == user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#education' do
|
||||||
|
let(:data) { {} }
|
||||||
|
it 'runs students check with token' do
|
||||||
|
education = stub(:education)
|
||||||
|
education.expects(:student?).returns(true)
|
||||||
|
Travis::Github::Education.expects(:new).with('abc123').returns(education)
|
||||||
|
|
||||||
|
manager.education.should be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user