diff options
author | sujay patel <sujaypatel1996@gmail.com> | 2019-06-13 01:33:21 +0530 |
---|---|---|
committer | sujay <sujay.patel@caavo.com> | 2019-07-05 14:19:28 +0530 |
commit | b71250ca0f1b9df4f728bdb322502e3544058ca5 (patch) | |
tree | 19aecdb71975d81b256c001cd29006ddb198f5a5 /spec | |
parent | 2fec78ead4ce46b9728be02693b6e50cce740726 (diff) | |
download | gitlab-ce-b71250ca0f1b9df4f728bdb322502e3544058ca5.tar.gz |
Adding order by to list runner jobs api.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/runner_jobs_finder_spec.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/finders/runner_jobs_finder_spec.rb b/spec/finders/runner_jobs_finder_spec.rb index 97304170c4e..9ed6f50ddfb 100644 --- a/spec/finders/runner_jobs_finder_spec.rb +++ b/spec/finders/runner_jobs_finder_spec.rb @@ -35,5 +35,42 @@ describe RunnerJobsFinder do end end end + + context 'when order_by and sort are specified' do + context 'when order_by created_at' do + let(:params) { { order_by: 'created_at', sort: 'asc' } } + let!(:jobs) { Array.new(2) { create(:ci_build, runner: runner, project: project, user: create(:user)) } } + + it 'sorts as created_at: :asc' do + is_expected.to match_array(jobs) + end + + context 'when sort is invalid' do + let(:params) { { order_by: 'created_at', sort: 'invalid_sort' } } + + it 'sorts as created_at: :desc' do + is_expected.to eq(jobs.sort_by { |p| -p.user.id }) + end + end + end + + context 'when order_by is invalid' do + let(:params) { { order_by: 'invalid_column', sort: 'asc' } } + let!(:jobs) { Array.new(2) { create(:ci_build, runner: runner, project: project, user: create(:user)) } } + + it 'sorts as id: :asc' do + is_expected.to eq(jobs.sort_by { |p| p.id }) + end + end + + context 'when both are nil' do + let(:params) { { order_by: nil, sort: nil } } + let!(:jobs) { Array.new(2) { create(:ci_build, runner: runner, project: project, user: create(:user)) } } + + it 'sorts as id: :desc' do + is_expected.to eq(jobs.sort_by { |p| -p.id }) + end + end + end end end |