summaryrefslogtreecommitdiff
path: root/spec/models/ci/runner_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-09-14 15:05:46 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2018-09-14 15:05:46 +0200
commitf0e7b5e7a321383aa847790d36b1328a70c2fe2c (patch)
treea0cabd59ae9d81f5401235ede383dbc39b2fba78 /spec/models/ci/runner_spec.rb
parent197beefc414c34ba9af89b91630f5d3137bf06de (diff)
downloadgitlab-ce-f0e7b5e7a321383aa847790d36b1328a70c2fe2c.tar.gz
Cleaned up CI runner administration code
In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/19625 some changes were introduced that do not meet our abstraction reuse rules. This commit cleans up some of these changes so the requirements are met. Most notably, sorting of the runners in Admin::RunnersFinder has been delegated to Ci::Runner.order_by, similar to how we order data in models that include the Sortable module. If we need more sort orders in the future we can include Sortable and have Ci::Runner.order_by call `super` to delegate to Sortable.order_by.
Diffstat (limited to 'spec/models/ci/runner_spec.rb')
-rw-r--r--spec/models/ci/runner_spec.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index f1d0ed15d29..b545e036aa1 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -797,4 +797,22 @@ describe Ci::Runner do
expect { subject.destroy }.to change { described_class.count }.by(-1)
end
end
+
+ describe '.order_by' do
+ it 'supports ordering by the contact date' do
+ runner1 = create(:ci_runner, contacted_at: 1.year.ago)
+ runner2 = create(:ci_runner, contacted_at: 1.month.ago)
+ runners = described_class.order_by('contacted_asc')
+
+ expect(runners).to eq([runner1, runner2])
+ end
+
+ it 'supports ordering by the creation date' do
+ runner1 = create(:ci_runner, created_at: 1.year.ago)
+ runner2 = create(:ci_runner, created_at: 1.month.ago)
+ runners = described_class.order_by('created_asc')
+
+ expect(runners).to eq([runner2, runner1])
+ end
+ end
end