Commit 4b03c83a authored by Dominic Couture's avatar Dominic Couture Committed by Mayra Cabrera

Implement `deactivated?` for deploy tokens

`PolicyActor` has a `deactivated?` method that returns
`false`. However a `DeployToken` can indeed be deactivated.
parent e9ab64ae
......@@ -54,6 +54,10 @@ class DeployToken < ApplicationRecord
!revoked && !expired?
end
def deactivated?
!active?
end
def scopes
AVAILABLE_SCOPES.select { |token_scope| read_attribute(token_scope) }
end
......
......@@ -124,6 +124,39 @@ RSpec.describe DeployToken do
end
end
# override the default PolicyActor implementation that always returns false
describe "#deactivated?" do
context "when it has been revoked" do
it 'returns true' do
deploy_token.revoke!
expect(deploy_token.deactivated?).to be_truthy
end
end
context "when it hasn't been revoked and is not expired" do
it 'returns false' do
expect(deploy_token.deactivated?).to be_falsy
end
end
context "when it hasn't been revoked and is expired" do
it 'returns false' do
deploy_token.update_attribute(:expires_at, Date.today - 5.days)
expect(deploy_token.deactivated?).to be_truthy
end
end
context "when it hasn't been revoked and has no expiry" do
let(:deploy_token) { create(:deploy_token, expires_at: nil) }
it 'returns false' do
expect(deploy_token.deactivated?).to be_falsy
end
end
end
describe '#username' do
context 'persisted records' do
it 'returns a default username if none is set' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment