Check for user education status on signin/signup
This commit is contained in:
parent
4546d29508
commit
9b07efa5e9
2
Gemfile
2
Gemfile
|
@ -3,7 +3,7 @@ ruby '2.1.2'
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
gem 'travis-core', github: 'travis-ci/travis-core'
|
gem 'travis-core', github: 'travis-ci/travis-core', branch: 'ps-education-sync'
|
||||||
gem 'travis-support', github: 'travis-ci/travis-support'
|
gem 'travis-support', github: 'travis-ci/travis-support'
|
||||||
gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741'
|
gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741'
|
||||||
gem 'travis-yaml', github: 'travis-ci/travis-yaml'
|
gem 'travis-yaml', github: 'travis-ci/travis-yaml'
|
||||||
|
|
|
@ -37,7 +37,8 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-core.git
|
remote: git://github.com/travis-ci/travis-core.git
|
||||||
revision: 0c4922f7cbf644ccc97677643bb09f26a919e64c
|
revision: 8f2b4add4581f2897ce14edca26aff99cc60f280
|
||||||
|
branch: ps-education-sync
|
||||||
specs:
|
specs:
|
||||||
travis-core (0.0.1)
|
travis-core (0.0.1)
|
||||||
actionmailer (~> 3.2.19)
|
actionmailer (~> 3.2.19)
|
||||||
|
|
|
@ -216,6 +216,7 @@ 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
|
||||||
|
info['education'] = education
|
||||||
info['github_id'] ||= data['id']
|
info['github_id'] ||= data['id']
|
||||||
info
|
info
|
||||||
end
|
end
|
||||||
|
@ -224,6 +225,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)
|
||||||
|
|
|
@ -10,16 +10,18 @@ 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
|
||||||
|
@ -34,8 +36,9 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
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 +49,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 +61,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