2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-05 14:00:21 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Profiles::PreferencesController do
|
2015-06-05 14:00:21 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
allow(subject).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET show' do
|
|
|
|
it 'renders' do
|
|
|
|
get :show
|
|
|
|
expect(response).to render_template :show
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns user' do
|
|
|
|
get :show
|
|
|
|
expect(assigns[:user]).to eq user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH update' do
|
2021-02-15 16:08:59 -05:00
|
|
|
def go(params: {}, format: :json)
|
2015-06-05 14:00:21 -04:00
|
|
|
params.reverse_merge!(
|
|
|
|
color_scheme_id: '1',
|
2017-09-11 11:44:42 -04:00
|
|
|
dashboard: 'stars',
|
|
|
|
theme_id: '1'
|
2015-06-05 14:00:21 -04:00
|
|
|
)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :update, params: { user: params }, format: format
|
2015-06-05 14:00:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'on successful update' do
|
2021-02-15 16:08:59 -05:00
|
|
|
it 'responds with success' do
|
2015-06-05 14:00:21 -04:00
|
|
|
go
|
2021-02-15 16:08:59 -05:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response.parsed_body['message']).to eq _('Preferences saved.')
|
|
|
|
expect(response.parsed_body['type']).to eq('notice')
|
2015-06-05 14:00:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "changes the user's preferences" do
|
|
|
|
prefs = {
|
|
|
|
color_scheme_id: '1',
|
2017-09-11 11:44:42 -04:00
|
|
|
dashboard: 'stars',
|
2018-11-06 16:16:49 -05:00
|
|
|
theme_id: '2',
|
2019-02-20 17:58:53 -05:00
|
|
|
first_day_of_week: '1',
|
2020-01-06 10:07:26 -05:00
|
|
|
preferred_language: 'jp',
|
2020-02-06 07:10:29 -05:00
|
|
|
tab_width: '5',
|
2020-01-06 10:07:26 -05:00
|
|
|
render_whitespace_in_code: 'true'
|
2015-06-05 14:00:21 -04:00
|
|
|
}.with_indifferent_access
|
|
|
|
|
2018-12-16 07:01:11 -05:00
|
|
|
expect(user).to receive(:assign_attributes).with(ActionController::Parameters.new(prefs).permit!)
|
2017-06-15 09:24:37 -04:00
|
|
|
expect(user).to receive(:save)
|
2015-06-05 14:00:21 -04:00
|
|
|
|
|
|
|
go params: prefs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-10 18:19:06 -04:00
|
|
|
context 'on failed update' do
|
2021-02-15 16:08:59 -05:00
|
|
|
it 'responds with error' do
|
2017-06-15 09:24:37 -04:00
|
|
|
expect(user).to receive(:save).and_return(false)
|
2015-06-10 18:19:06 -04:00
|
|
|
|
|
|
|
go
|
|
|
|
|
2021-02-15 16:08:59 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
expect(response.parsed_body['message']).to eq _('Failed to save preferences.')
|
|
|
|
expect(response.parsed_body['type']).to eq('alert')
|
2015-06-10 18:19:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on invalid dashboard setting' do
|
2021-02-15 16:08:59 -05:00
|
|
|
it 'responds with error' do
|
2015-06-22 14:41:00 -04:00
|
|
|
prefs = { dashboard: 'invalid' }
|
2015-06-10 18:19:06 -04:00
|
|
|
|
|
|
|
go params: prefs
|
|
|
|
|
2021-02-15 16:08:59 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
expect(response.parsed_body['message']).to match(/\AFailed to save preferences \(.+\)\.\z/)
|
|
|
|
expect(response.parsed_body['type']).to eq('alert')
|
2015-06-05 14:00:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|