diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/controllers/concerns | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/controllers/concerns')
-rw-r--r-- | spec/controllers/concerns/sorting_preference_spec.rb | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/spec/controllers/concerns/sorting_preference_spec.rb b/spec/controllers/concerns/sorting_preference_spec.rb index c0091e8b694..82a920215ca 100644 --- a/spec/controllers/concerns/sorting_preference_spec.rb +++ b/spec/controllers/concerns/sorting_preference_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe SortingPreference do let(:user) { create(:user) } + let(:params) { {} } let(:controller_class) do Class.new do @@ -23,6 +24,46 @@ RSpec.describe SortingPreference do allow(controller).to receive(:sorting_field).and_return(:issues_sort) end + describe '#set_sort_order' do + let(:group) { build(:group) } + let(:issue_weights_available) { true } + + before do + allow(controller).to receive(:default_sort_order).and_return('updated_desc') + allow(controller).to receive(:action_name).and_return('issues') + allow(controller).to receive(:can_sort_by_issue_weight?).and_return(issue_weights_available) + user.user_preference.update!(issues_sort: sorting_field) + end + + subject { controller.send(:set_sort_order) } + + context 'when user preference contains allowed sorting' do + let(:sorting_field) { 'updated_asc' } + + it 'sets sort order from user_preference' do + is_expected.to eq('updated_asc') + end + end + + context 'when user preference contains weight sorting' do + let(:sorting_field) { 'weight_desc' } + + context 'when user can sort by issue weight' do + it 'sets sort order from user_preference' do + is_expected.to eq('weight_desc') + end + end + + context 'when user cannot sort by issue weight' do + let(:issue_weights_available) { false } + + it 'sets default sort order' do + is_expected.to eq('updated_desc') + end + end + end + end + describe '#set_sort_order_from_user_preference' do subject { controller.send(:set_sort_order_from_user_preference) } @@ -49,8 +90,6 @@ RSpec.describe SortingPreference do end context 'when a user sorting preference exists' do - let(:params) { {} } - before do user.user_preference.update!(issues_sort: 'updated_asc') end @@ -81,7 +120,6 @@ RSpec.describe SortingPreference do context 'when cookie exists' do let(:cookies) { { 'issue_sort' => 'id_asc' } } - let(:params) { {} } it 'sets the cookie with the right values and flags' do subject |