2018-03-19 12:11:12 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DeployToken do
|
2018-03-29 18:56:35 -04:00
|
|
|
let(:deploy_token) { create(:deploy_token) }
|
|
|
|
|
2018-03-19 12:11:12 -04:00
|
|
|
it { is_expected.to belong_to :project }
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
context 'with no scopes defined' do
|
|
|
|
it 'should not be valid' do
|
2018-03-29 18:56:35 -04:00
|
|
|
deploy_token.scopes = []
|
2018-03-19 12:11:12 -04:00
|
|
|
|
2018-03-29 18:56:35 -04:00
|
|
|
expect(deploy_token).not_to be_valid
|
|
|
|
expect(deploy_token.errors[:scopes].first).to eq("can't be blank")
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#ensure_token' do
|
|
|
|
it 'should ensure a token' do
|
2018-03-29 18:56:35 -04:00
|
|
|
deploy_token.token = nil
|
|
|
|
deploy_token.save
|
2018-03-19 12:11:12 -04:00
|
|
|
|
2018-03-29 18:56:35 -04:00
|
|
|
expect(deploy_token.token).not_to be_empty
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#revoke!' do
|
|
|
|
it 'should update revoke attribute' do
|
2018-03-29 18:56:35 -04:00
|
|
|
deploy_token.revoke!
|
|
|
|
expect(deploy_token.revoked?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#active?" do
|
|
|
|
context "when it has been revoked" do
|
|
|
|
it 'should return false' do
|
|
|
|
deploy_token.revoke!
|
|
|
|
expect(deploy_token.active?).to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when it hasn't been revoked" do
|
|
|
|
it 'should return true' do
|
|
|
|
expect(deploy_token.active?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#username' do
|
|
|
|
it 'returns Ghost username' do
|
|
|
|
ghost = User.ghost
|
|
|
|
expect(deploy_token.username).to eq(ghost.username)
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|