diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-22 18:08:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-22 18:08:47 +0000 |
commit | 3832718d895bf8268f3e3aac85948e2792769345 (patch) | |
tree | 4a322399af568b6203e732ae2e2f3efc39b23a67 /spec/lib/api | |
parent | 180cd023a11c0eb413ad0de124d9758ea25672bd (diff) | |
download | gitlab-ce-3832718d895bf8268f3e3aac85948e2792769345.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/api')
-rw-r--r-- | spec/lib/api/helpers_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb index 81c4563feb6..9980f4d8e23 100644 --- a/spec/lib/api/helpers_spec.rb +++ b/spec/lib/api/helpers_spec.rb @@ -188,4 +188,46 @@ describe API::Helpers do subject.track_event('my_event', category: nil) end end + + describe '#order_options_with_tie_breaker' do + subject { Class.new.include(described_class).new.order_options_with_tie_breaker } + + before do + allow_any_instance_of(described_class).to receive(:params).and_return(params) + end + + context 'with non-id order given' do + context 'with ascending order' do + let(:params) { { order_by: 'name', sort: 'asc' } } + + it 'adds id based ordering with same direction as primary order' do + is_expected.to eq({ 'name' => 'asc', 'id' => 'asc' }) + end + end + + context 'with descending order' do + let(:params) { { order_by: 'name', sort: 'desc' } } + + it 'adds id based ordering with same direction as primary order' do + is_expected.to eq({ 'name' => 'desc', 'id' => 'desc' }) + end + end + end + + context 'with non-id order but no direction given' do + let(:params) { { order_by: 'name' } } + + it 'adds ID ASC order' do + is_expected.to eq({ 'name' => nil, 'id' => 'asc' }) + end + end + + context 'with id order given' do + let(:params) { { order_by: 'id', sort: 'asc' } } + + it 'does not add an additional order' do + is_expected.to eq({ 'id' => 'asc' }) + end + end + end end |