debian-mirror-gitlab/spec/support/shared_examples/controllers/issuable_notes_filter_shared_examples.rb

85 lines
2.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2020-03-13 15:44:24 +05:30
RSpec.shared_examples 'issuable notes filter' do
2019-03-02 22:35:43 +05:30
let(:params) do
if issuable_parent.is_a?(Project)
{ namespace_id: issuable_parent.namespace, project_id: issuable_parent, id: issuable.iid }
else
{ group_id: issuable_parent, id: issuable.to_param }
end
end
2018-12-13 13:39:08 +05:30
it 'sets discussion filter' do
notes_filter = UserPreference::NOTES_FILTERS[:only_comments]
2019-03-02 22:35:43 +05:30
get :discussions, params: params.merge(notes_filter: notes_filter)
2018-12-13 13:39:08 +05:30
expect(user.reload.notes_filter_for(issuable)).to eq(notes_filter)
expect(UserPreference.count).to eq(1)
end
it 'expires notes e-tag cache for issuable if filter changed' do
notes_filter = UserPreference::NOTES_FILTERS[:only_comments]
expect_any_instance_of(issuable.class).to receive(:expire_note_etag_cache)
2019-03-02 22:35:43 +05:30
get :discussions, params: params.merge(notes_filter: notes_filter)
2018-12-13 13:39:08 +05:30
end
it 'does not expires notes e-tag cache for issuable if filter did not change' do
notes_filter = UserPreference::NOTES_FILTERS[:only_comments]
user.set_notes_filter(notes_filter, issuable)
expect_any_instance_of(issuable.class).not_to receive(:expire_note_etag_cache)
2019-03-02 22:35:43 +05:30
get :discussions, params: params.merge(notes_filter: notes_filter)
2018-12-13 13:39:08 +05:30
end
2021-06-08 01:23:25 +05:30
it 'does not set notes filter when database is in read-only mode' do
2018-12-13 13:39:08 +05:30
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
notes_filter = UserPreference::NOTES_FILTERS[:only_comments]
2019-03-02 22:35:43 +05:30
get :discussions, params: params.merge(notes_filter: notes_filter)
2018-12-13 13:39:08 +05:30
2019-10-12 21:52:04 +05:30
expect(user.reload.notes_filter_for(issuable)).to eq(UserPreference::NOTES_FILTERS[:all_notes])
end
it 'does not set notes filter when persist_filter param is false' do
notes_filter = UserPreference::NOTES_FILTERS[:only_comments]
get :discussions, params: params.merge(notes_filter: notes_filter, persist_filter: false)
expect(user.reload.notes_filter_for(issuable)).to eq(UserPreference::NOTES_FILTERS[:all_notes])
2018-12-13 13:39:08 +05:30
end
it 'returns only user comments' do
user.set_notes_filter(UserPreference::NOTES_FILTERS[:only_comments], issuable)
2019-03-02 22:35:43 +05:30
get :discussions, params: params
2019-09-30 21:07:59 +05:30
discussions = json_response
2018-12-13 13:39:08 +05:30
expect(discussions.count).to eq(1)
expect(discussions.first["notes"].first["system"]).to be(false)
end
it 'returns only activity notes' do
user.set_notes_filter(UserPreference::NOTES_FILTERS[:only_activity], issuable)
2019-03-02 22:35:43 +05:30
get :discussions, params: params
2019-09-30 21:07:59 +05:30
discussions = json_response
2018-12-13 13:39:08 +05:30
expect(discussions.count).to eq(1)
expect(discussions.first["notes"].first["system"]).to be(true)
end
context 'when filter is set to "only_comments"' do
it 'does not merge label event notes' do
user.set_notes_filter(UserPreference::NOTES_FILTERS[:only_comments], issuable)
expect(ResourceEvents::MergeIntoNotesService).not_to receive(:new)
2019-03-02 22:35:43 +05:30
get :discussions, params: params
2018-12-13 13:39:08 +05:30
end
end
end