Fix deploy tokens without `expire_at` crashes
This commit is contained in:
parent
367e7520b0
commit
a6268d3023
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue