2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Groups::OpenIssuesCountService, :use_clean_rails_memory_store_caching, feature_category: :subgroups do
|
2022-08-27 11:52:29 +05:30
|
|
|
let_it_be(:group) { create(:group, :public) }
|
2021-03-11 19:13:27 +05:30
|
|
|
let_it_be(:project) { create(:project, :public, namespace: group) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2022-07-16 23:28:13 +05:30
|
|
|
let_it_be(:issue) { create(:issue, :opened, project: project) }
|
|
|
|
let_it_be(:confidential) { create(:issue, :opened, confidential: true, project: project) }
|
|
|
|
let_it_be(:closed) { create(:issue, :closed, project: project) }
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
subject { described_class.new(group, user) }
|
|
|
|
|
|
|
|
describe '#relation_for_count' do
|
|
|
|
before do
|
|
|
|
allow(IssuesFinder).to receive(:new).and_call_original
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the IssuesFinder to scope issues' do
|
|
|
|
expect(IssuesFinder)
|
|
|
|
.to receive(:new)
|
2022-07-16 23:28:13 +05:30
|
|
|
.with(user, group_id: group.id, state: 'opened', non_archived: true, include_subgroups: true, public_only: true)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
subject.count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#count' do
|
2021-11-11 11:23:49 +05:30
|
|
|
context 'when user is nil' do
|
2022-07-16 23:28:13 +05:30
|
|
|
it 'does not include confidential issues in the issue count' do
|
|
|
|
expect(described_class.new(group).count).to eq(1)
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
context 'when user is provided' do
|
|
|
|
context 'when user can read confidential issues' do
|
|
|
|
before do
|
|
|
|
group.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
it 'returns the right count with confidential issues' do
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(subject.count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot read confidential issues' do
|
|
|
|
before do
|
|
|
|
group.add_guest(user)
|
|
|
|
end
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
it 'does not include confidential issues' do
|
|
|
|
expect(subject.count).to eq(1)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it_behaves_like 'a counter caching service with threshold'
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
describe '#clear_all_cache_keys' do
|
|
|
|
it 'calls `Rails.cache.delete` with the correct keys' do
|
|
|
|
expect(Rails.cache).to receive(:delete)
|
2022-07-16 23:28:13 +05:30
|
|
|
.with(['groups', 'open_issues_count_service', 1, group.id, described_class::PUBLIC_COUNT_KEY])
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(Rails.cache).to receive(:delete)
|
|
|
|
.with(['groups', 'open_issues_count_service', 1, group.id, described_class::TOTAL_COUNT_KEY])
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
subject.clear_all_cache_keys
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|