Commit 4ec6d4d4 authored by Max Woolf's avatar Max Woolf

Merge branch 'sort-by-runner-token-expires-at' into 'master'

CI Runners: Support sorting by token_expires_at

See merge request gitlab-org/gitlab!78939
parents 34e8bde2 a4182be4
......@@ -179,6 +179,8 @@ module Ci
scope :order_contacted_at_desc, -> { order(contacted_at: :desc) }
scope :order_created_at_asc, -> { order(created_at: :asc) }
scope :order_created_at_desc, -> { order(created_at: :desc) }
scope :order_token_expires_at_asc, -> { order(token_expires_at: :asc) }
scope :order_token_expires_at_desc, -> { order(token_expires_at: :desc) }
scope :with_tags, -> { preload(:tags) }
validate :tag_constraints
......@@ -247,6 +249,10 @@ module Ci
order_contacted_at_desc
when 'created_at_asc'
order_created_at_asc
when 'token_expires_at_asc'
order_token_expires_at_asc
when 'token_expires_at_desc'
order_token_expires_at_desc
else
order_created_at_desc
end
......
......@@ -1303,6 +1303,18 @@ RSpec.describe Ci::Runner do
expect(runners).to eq([runner2, runner1])
end
it 'supports ordering by the token expiration' do
runner1 = create(:ci_runner, token_expires_at: 1.year.from_now)
runner2 = create(:ci_runner)
runner3 = create(:ci_runner, token_expires_at: 1.month.from_now)
runners = described_class.order_by('token_expires_at_asc')
expect(runners).to eq([runner3, runner1, runner2])
runners = described_class.order_by('token_expires_at_desc')
expect(runners).to eq([runner2, runner1, runner3])
end
end
describe '.runner_matchers' 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