2018-10-23 05:49:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UserPreference do
|
|
|
|
describe '#set_notes_filter' do
|
|
|
|
let(:issuable) { build_stubbed(:issue) }
|
|
|
|
let(:user_preference) { create(:user_preference) }
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(user_preference.set_notes_filter(9999, issuable)).to eq(only_comments)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|