2018-10-23 05:49:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe UserPreference do
|
2019-01-06 19:00:48 -05:00
|
|
|
let(:user_preference) { create(:user_preference) }
|
|
|
|
|
2020-01-03 04:07:33 -05:00
|
|
|
describe 'notes filters global keys' do
|
|
|
|
it 'contains expected values' do
|
|
|
|
expect(UserPreference::NOTES_FILTERS.keys).to match_array([:all_notes, :only_comments, :only_activity])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-23 05:49:45 -04:00
|
|
|
describe '#set_notes_filter' do
|
|
|
|
let(:issuable) { build_stubbed(:issue) }
|
|
|
|
|
2018-11-05 07:30:14 -05:00
|
|
|
shared_examples 'setting system notes' do
|
|
|
|
it 'returns updated discussion filter' do
|
|
|
|
filter_name =
|
|
|
|
user_preference.set_notes_filter(filter, issuable)
|
|
|
|
|
|
|
|
expect(filter_name).to eq(filter)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates discussion filter for issuable class' do
|
|
|
|
user_preference.set_notes_filter(filter, issuable)
|
|
|
|
|
|
|
|
expect(user_preference.reload.issue_notes_filter).to eq(filter)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when filter is set to all notes' do
|
|
|
|
let(:filter) { described_class::NOTES_FILTERS[:all_notes] }
|
|
|
|
|
|
|
|
it_behaves_like 'setting system notes'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when filter is set to only comments' do
|
|
|
|
let(:filter) { described_class::NOTES_FILTERS[:only_comments] }
|
2018-10-23 05:49:45 -04:00
|
|
|
|
2018-11-05 07:30:14 -05:00
|
|
|
it_behaves_like 'setting system notes'
|
2018-10-23 05:49:45 -04:00
|
|
|
end
|
|
|
|
|
2018-11-05 07:30:14 -05:00
|
|
|
context 'when filter is set to only activity' do
|
|
|
|
let(:filter) { described_class::NOTES_FILTERS[:only_activity] }
|
2018-10-23 05:49:45 -04:00
|
|
|
|
2018-11-05 07:30:14 -05:00
|
|
|
it_behaves_like 'setting system notes'
|
2018-10-23 05:49:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when notes_filter parameter is invalid' do
|
2018-11-05 07:30:14 -05:00
|
|
|
let(:only_comments) { described_class::NOTES_FILTERS[:only_comments] }
|
|
|
|
|
2018-10-23 05:49:45 -04:00
|
|
|
it 'returns the current notes filter' do
|
|
|
|
user_preference.set_notes_filter(only_comments, issuable)
|
|
|
|
|
2020-04-01 11:07:45 -04:00
|
|
|
expect(user_preference.set_notes_filter(non_existing_record_id, issuable)).to eq(only_comments)
|
2018-10-23 05:49:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-01-06 19:00:48 -05:00
|
|
|
|
|
|
|
describe 'sort_by preferences' do
|
|
|
|
shared_examples_for 'a sort_by preference' do
|
|
|
|
it 'allows nil sort fields' do
|
2021-05-02 20:10:40 -04:00
|
|
|
user_preference.update!(attribute => nil)
|
2019-01-06 19:00:48 -05:00
|
|
|
|
|
|
|
expect(user_preference).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'merge_requests_sort attribute' do
|
|
|
|
let(:attribute) { :merge_requests_sort }
|
|
|
|
|
|
|
|
it_behaves_like 'a sort_by preference'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'issues_sort attribute' do
|
|
|
|
let(:attribute) { :issues_sort }
|
|
|
|
|
|
|
|
it_behaves_like 'a sort_by preference'
|
|
|
|
end
|
|
|
|
end
|
2019-05-07 17:58:16 -04:00
|
|
|
|
|
|
|
describe '#timezone' do
|
|
|
|
it 'returns server time as default' do
|
|
|
|
expect(user_preference.timezone).to eq(Time.zone.tzinfo.name)
|
|
|
|
end
|
|
|
|
end
|
2020-02-06 07:10:29 -05:00
|
|
|
|
|
|
|
describe '#tab_width' do
|
|
|
|
it 'is set to 8 by default' do
|
|
|
|
# Intentionally not using factory here to test the constructor.
|
|
|
|
pref = UserPreference.new
|
|
|
|
expect(pref.tab_width).to eq(8)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to validate_numericality_of(:tab_width)
|
|
|
|
.only_integer
|
|
|
|
.is_greater_than_or_equal_to(1)
|
|
|
|
.is_less_than_or_equal_to(12)
|
|
|
|
end
|
|
|
|
end
|
2018-10-23 05:49:45 -04:00
|
|
|
end
|