Commit b80dca82 authored by Felipe Artur's avatar Felipe Artur Committed by Nick Thomas

Do not save user preferences on read-only mode

parent 2ccd4b36
...@@ -126,6 +126,8 @@ module IssuableCollections ...@@ -126,6 +126,8 @@ module IssuableCollections
sort_param = params[:sort] sort_param = params[:sort]
sort_param ||= user_preference[issuable_sorting_field] sort_param ||= user_preference[issuable_sorting_field]
return sort_param if Gitlab::Database.read_only?
if user_preference[issuable_sorting_field] != sort_param if user_preference[issuable_sorting_field] != sort_param
user_preference.update_attribute(issuable_sorting_field, sort_param) user_preference.update_attribute(issuable_sorting_field, sort_param)
end end
......
...@@ -42,6 +42,8 @@ describe Projects::IssuesController do ...@@ -42,6 +42,8 @@ describe Projects::IssuesController do
it_behaves_like "issuables list meta-data", :issue it_behaves_like "issuables list meta-data", :issue
it_behaves_like 'set sort order from user preference'
it "returns index" do it "returns index" do
get :index, namespace_id: project.namespace, project_id: project get :index, namespace_id: project.namespace, project_id: project
......
...@@ -160,6 +160,8 @@ describe Projects::MergeRequestsController do ...@@ -160,6 +160,8 @@ describe Projects::MergeRequestsController do
it_behaves_like "issuables list meta-data", :merge_request it_behaves_like "issuables list meta-data", :merge_request
it_behaves_like 'set sort order from user preference'
context 'when page param' do context 'when page param' do
let(:last_page) { project.merge_requests.page().total_pages } let(:last_page) { project.merge_requests.page().total_pages }
let!(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let!(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
......
shared_examples 'set sort order from user preference' do
describe '#set_sort_order_from_user_preference' do
# There is no issuable_sorting_field defined in any CE controllers yet,
# however any other field present in user_preferences table can be used for testing.
let(:sorting_field) { :issue_notes_filter }
let(:sorting_param) { 'any' }
before do
allow(controller).to receive(:issuable_sorting_field).and_return(sorting_field)
end
context 'when database is in read-only mode' do
it 'it does not update user preference' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
expect_any_instance_of(UserPreference).not_to receive(:update_attribute).with(sorting_field, sorting_param)
get :index, 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)
expect_any_instance_of(UserPreference).to receive(:update_attribute).with(sorting_field, sorting_param)
get :index, namespace_id: project.namespace, project_id: project, sort: sorting_param
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment