summaryrefslogtreecommitdiff
path: root/spec/models/clusters/agent_token_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/clusters/agent_token_spec.rb')
-rw-r--r--spec/models/clusters/agent_token_spec.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/models/clusters/agent_token_spec.rb b/spec/models/clusters/agent_token_spec.rb
index 680b351d24a..bde4798abec 100644
--- a/spec/models/clusters/agent_token_spec.rb
+++ b/spec/models/clusters/agent_token_spec.rb
@@ -9,6 +9,19 @@ RSpec.describe Clusters::AgentToken do
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_presence_of(:name) }
+ describe 'scopes' do
+ describe '.order_last_used_at_desc' do
+ let_it_be(:token_1) { create(:cluster_agent_token, last_used_at: 7.days.ago) }
+ let_it_be(:token_2) { create(:cluster_agent_token, last_used_at: nil) }
+ let_it_be(:token_3) { create(:cluster_agent_token, last_used_at: 2.days.ago) }
+
+ it 'sorts by last_used_at descending, with null values at last' do
+ expect(described_class.order_last_used_at_desc)
+ .to eq([token_3, token_1, token_2])
+ end
+ end
+ end
+
describe '#token' do
it 'is generated on save' do
agent_token = build(:cluster_agent_token, token_encrypted: nil)