Fix deploy tokens without `expire_at` crashes

This commit is contained in:
Bob Van Landuyt 2018-08-02 19:43:36 +02:00
parent 367e7520b0
commit a6268d3023
2 changed files with 15 additions and 1 deletions

View File

@ -30,7 +30,7 @@ class DeployToken < ActiveRecord::Base
end
def active?
!revoked && expires_at > Date.today
!revoked && !expired?
end
def scopes
@ -63,6 +63,12 @@ class DeployToken < ActiveRecord::Base
private
def expired?
return false unless expires_at
expires_at < Date.today
end
def ensure_at_least_one_scope
errors.add(:base, "Scopes can't be blank") unless read_repository || read_registry
end

View File

@ -74,6 +74,14 @@ describe DeployToken do
expect(deploy_token.active?).to be_falsy
end
end
context "when it hasn't been revoked and has no expiry" do
let(:deploy_token) { create(:deploy_token, expires_at: nil) }
it 'should return true' do
expect(deploy_token.active?).to be_truthy
end
end
end
describe '#username' do