debian-mirror-gitlab/spec/controllers/profiles/preferences_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3.1 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Profiles::PreferencesController do
2015-09-11 14:41:01 +05:30
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-03-11 19:13:27 +05:30
def go(params: {}, format: :json)
2015-09-11 14:41:01 +05:30
params.reverse_merge!(
color_scheme_id: '1',
2018-03-17 18:26:18 +05:30
dashboard: 'stars',
theme_id: '1'
2015-09-11 14:41:01 +05:30
)
2019-02-15 15:39:39 +05:30
patch :update, params: { user: params }, format: format
2015-09-11 14:41:01 +05:30
end
context 'on successful update' do
2021-03-11 19:13:27 +05:30
it 'responds with success' do
2015-09-11 14:41:01 +05:30
go
2021-03-11 19:13:27 +05:30
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-09-11 14:41:01 +05:30
end
it "changes the user's preferences" do
prefs = {
color_scheme_id: '1',
2022-06-21 17:19:12 +05:30
diffs_deletion_color: '#123456',
diffs_addition_color: '#abcdef',
2018-03-17 18:26:18 +05:30
dashboard: 'stars',
2019-03-02 22:35:43 +05:30
theme_id: '2',
2019-07-07 11:18:12 +05:30
first_day_of_week: '1',
2020-03-13 15:44:24 +05:30
preferred_language: 'jp',
tab_width: '5',
render_whitespace_in_code: 'true'
2015-09-11 14:41:01 +05:30
}.with_indifferent_access
2019-02-15 15:39:39 +05:30
expect(user).to receive(:assign_attributes).with(ActionController::Parameters.new(prefs).permit!)
2017-09-10 17:25:29 +05:30
expect(user).to receive(:save)
2015-09-11 14:41:01 +05:30
go params: prefs
end
end
context 'on failed update' do
2021-03-11 19:13:27 +05:30
it 'responds with error' do
2017-09-10 17:25:29 +05:30
expect(user).to receive(:save).and_return(false)
2015-09-11 14:41:01 +05:30
go
2021-03-11 19:13:27 +05:30
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-09-11 14:41:01 +05:30
end
end
context 'on invalid dashboard setting' do
2021-03-11 19:13:27 +05:30
it 'responds with error' do
2015-09-11 14:41:01 +05:30
prefs = { dashboard: 'invalid' }
go params: prefs
2021-03-11 19:13:27 +05:30
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-09-11 14:41:01 +05:30
end
end
2022-06-21 17:19:12 +05:30
context 'on invalid diffs colors setting' do
it 'responds with error for diffs_deletion_color' do
prefs = { diffs_deletion_color: '#1234567' }
go params: prefs
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')
end
it 'responds with error for diffs_addition_color' do
prefs = { diffs_addition_color: '#1234567' }
go params: prefs
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')
end
end
2015-09-11 14:41:01 +05:30
end
end