2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
shared_examples 'set sort order from user preference' do
|
|
|
|
describe '#set_sort_order_from_user_preference' do
|
2019-12-04 20:38:33 +05:30
|
|
|
# There is no sorting_field defined in any CE controllers yet,
|
2019-02-15 15:39:39 +05:30
|
|
|
# however any other field present in user_preferences table can be used for testing.
|
|
|
|
|
|
|
|
context 'when database is in read-only mode' do
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'does not update user preference' do
|
2019-02-15 15:39:39 +05:30
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect_any_instance_of(UserPreference).not_to receive(:update).with({ controller.send(:sorting_field) => sorting_param })
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
get :index, params: { namespace_id: project.namespace, project_id: project, sort: sorting_param }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when database is not in read-only mode' do
|
|
|
|
it 'updates user preference' do
|
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(false)
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect_any_instance_of(UserPreference).to receive(:update).with({ controller.send(:sorting_field) => sorting_param })
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
get :index, params: { namespace_id: project.namespace, project_id: project, sort: sorting_param }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|