travis-api/spec/lib/github/oauth_spec.rb
Aakriti Gupta 65f1a29d86 Move travis-core files from /vendor to /lib.
- Re-factor
- Remove code for notifications
- Remove addons
- Remove travis-core gem.
- Ignore logs directory only
- Move core tests to spec/lib
2016-07-20 11:22:25 +02:00

66 lines
1.6 KiB
Ruby

describe Travis::Github::Oauth do
let(:user) { Factory(:user, github_oauth_token: 'token', github_scopes: scopes) }
describe 'correct_scopes?' do
let(:scopes) { ['public_repo', 'user:email'] }
subject { described_class.correct_scopes?(user) }
it 'accepts correct scopes' do
should eq true
end
it 'complains about missing scopes' do
user.github_scopes.pop
should eq false
end
it 'accepts additional scopes' do
user.github_scopes << 'foo'
should eq true
end
end
describe 'update_scopes' do
before { user.reload }
describe 'the token did not change' do
let(:scopes) { ['public_repo', 'user:email'] }
it 'does not resolve github scopes' do
Travis::Github::Oauth.expects(:scopes_for).never
described_class.update_scopes(user)
end
end
describe 'the token has changed' do
let(:scopes) { ['public_repo', 'user:email'] }
before do
user.github_oauth_token = 'changed'
user.save!
end
it 'updates github scopes' do
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
described_class.update_scopes(user)
expect(user.reload.github_scopes).to eq ['foo', 'bar']
end
end
describe 'no scopes have been set so far' do
let(:scopes) { nil }
before do
user.github_oauth_token = 'changed'
user.save!
end
it 'updates github scopes' do
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
described_class.update_scopes(user)
expect(user.reload.github_scopes).to eq ['foo', 'bar']
end
end
end
end