Commit cd7b81bd authored by Pedro Pombeiro's avatar Pedro Pombeiro Committed by Adam Hegyi

Address MR review comments

parent 53d0a632
...@@ -4,6 +4,9 @@ module Ci ...@@ -4,6 +4,9 @@ module Ci
class RunnersFinder < UnionFinder class RunnersFinder < UnionFinder
include Gitlab::Allowable include Gitlab::Allowable
ALLOWED_SORTS = %w[contacted_asc contacted_desc created_at_asc created_at_desc].freeze
DEFAULT_SORT = 'created_date'
def initialize(current_user:, group: nil, params:) def initialize(current_user:, group: nil, params:)
@params = params @params = params
@group = group @group = group
...@@ -24,12 +27,7 @@ module Ci ...@@ -24,12 +27,7 @@ module Ci
end end
def sort_key def sort_key
case @params[:sort] ALLOWED_SORTS.include?(@params[:sort]) ? @params[:sort] : DEFAULT_SORT
when 'contacted_asc', 'contacted_desc', 'created_at_asc', 'created_at_desc'
@params[:sort]
else
'created_date'
end
end end
private private
......
...@@ -59,27 +59,23 @@ RSpec.describe Ci::RunnersFinder do ...@@ -59,27 +59,23 @@ RSpec.describe Ci::RunnersFinder do
described_class.new(current_user: admin, params: params).execute described_class.new(current_user: admin, params: params).execute
end end
context 'without sort param' do shared_examples 'sorts by created_at descending' do
let(:params) { {} }
it 'sorts by created_at descending' do it 'sorts by created_at descending' do
is_expected.to eq [runner3, runner2, runner1] is_expected.to eq [runner3, runner2, runner1]
end end
end end
context 'with sort param equal to created_date' do context 'without sort param' do
let(:params) { { sort: 'created_date' } } let(:params) { {} }
it 'sorts by created_at descending' do it_behaves_like 'sorts by created_at descending'
is_expected.to eq [runner3, runner2, runner1]
end
end end
context 'with sort param equal to created_at_desc' do %w(created_date created_at_desc).each do |sort|
let(:params) { { sort: 'created_at_desc' } } context "with sort param equal to #{sort}" do
let(:params) { { sort: sort } }
it 'sorts by created_at descending' do it_behaves_like 'sorts by created_at descending'
is_expected.to eq [runner3, runner2, runner1]
end end
end end
...@@ -91,7 +87,6 @@ RSpec.describe Ci::RunnersFinder do ...@@ -91,7 +87,6 @@ RSpec.describe Ci::RunnersFinder do
end end
end end
context 'by contacted_at' do
context 'with sort param equal to contacted_asc' do context 'with sort param equal to contacted_asc' do
let(:params) { { sort: 'contacted_asc' } } let(:params) { { sort: 'contacted_asc' } }
...@@ -108,7 +103,6 @@ RSpec.describe Ci::RunnersFinder do ...@@ -108,7 +103,6 @@ RSpec.describe Ci::RunnersFinder do
end end
end end
end end
end
context 'non admin user' do context 'non admin user' do
it 'returns no runners' do it 'returns no runners' 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