diff options
author | Mario de la Ossa <mariodelaossa@gmail.com> | 2019-01-06 18:00:48 -0600 |
---|---|---|
committer | Mario de la Ossa <mariodelaossa@gmail.com> | 2019-01-28 12:48:05 -0600 |
commit | 49c74068ae7f0017ebeb8e7daa2c556fef3124e3 (patch) | |
tree | 76200baeb51199910ce81b77736da2491bcd33f5 /spec/controllers/concerns | |
parent | 958a819fce709419c0be76cec8a20c8e8417ab84 (diff) | |
download | gitlab-ce-49c74068ae7f0017ebeb8e7daa2c556fef3124e3.tar.gz |
Save sorting preference for Issues/MRs in BE
In order to let users' sorting preferences transfer between devices, we
save the preference for issues and MRs (one preference for issues, one
for MRs) in the backend inside the UserPreference object
Diffstat (limited to 'spec/controllers/concerns')
-rw-r--r-- | spec/controllers/concerns/issuable_collections_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/controllers/concerns/issuable_collections_spec.rb b/spec/controllers/concerns/issuable_collections_spec.rb index 5a3a7a15f5a..307c5d60c57 100644 --- a/spec/controllers/concerns/issuable_collections_spec.rb +++ b/spec/controllers/concerns/issuable_collections_spec.rb @@ -17,10 +17,55 @@ describe IssuableCollections do controller = klass.new allow(controller).to receive(:params).and_return(ActionController::Parameters.new(params)) + allow(controller).to receive(:current_user).and_return(user) controller end + describe '#set_sort_order_from_user_preference' do + describe 'when sort param given' do + let(:params) { { sort: 'updated_desc' } } + + context 'when issuable_sorting_field is defined' do + before do + controller.class.define_method(:issuable_sorting_field) { :issues_sort} + end + + it 'sets user_preference with the right value' do + controller.send(:set_sort_order_from_user_preference) + + expect(user.user_preference.reload.issues_sort).to eq('updated_desc') + end + end + + context 'when no issuable_sorting_field is defined on the controller' do + it 'does not touch user_preference' do + allow(user).to receive(:user_preference) + + controller.send(:set_sort_order_from_user_preference) + + expect(user).not_to have_received(:user_preference) + end + end + end + + context 'when a user sorting preference exists' do + let(:params) { {} } + + before do + controller.class.define_method(:issuable_sorting_field) { :issues_sort } + end + + it 'returns the set preference' do + user.user_preference.update(issues_sort: 'updated_asc') + + sort_preference = controller.send(:set_sort_order_from_user_preference) + + expect(sort_preference).to eq('updated_asc') + end + end + end + describe '#set_set_order_from_cookie' do describe 'when sort param given' do let(:cookies) { {} } |