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