debian-mirror-gitlab/spec/services/projects/open_issues_count_service_spec.rb

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

94 lines
2.9 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Projects::OpenIssuesCountService, :use_clean_rails_memory_store_caching, feature_category: :team_planning do
2019-12-04 20:38:33 +05:30
let(:project) { create(:project) }
2020-01-01 13:55:28 +05:30
2022-07-16 23:28:13 +05:30
subject { described_class.new(project) }
2019-12-04 20:38:33 +05:30
it_behaves_like 'a counter caching service'
2018-03-17 18:26:18 +05:30
2019-12-04 20:38:33 +05:30
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
create(:issue, :opened, project: project)
create(:issue, :opened, confidential: true, project: project)
2021-11-11 11:23:49 +05:30
2022-07-16 23:28:13 +05:30
expect(described_class.new(project).count).to eq(1)
end
2021-11-11 11:23:49 +05:30
end
2018-11-08 19:23:39 +05:30
2021-11-11 11:23:49 +05:30
context 'when user is provided' do
2022-07-16 23:28:13 +05:30
let(:user) { create(:user) }
2018-11-08 19:23:39 +05:30
context 'when user can read confidential issues' do
before do
project.add_reporter(user)
end
2022-07-16 23:28:13 +05:30
it 'returns the right count with confidential issues' do
create(:issue, :opened, project: project)
create(:issue, :opened, confidential: true, project: project)
expect(described_class.new(project, user).count).to eq(2)
2018-11-08 19:23:39 +05:30
end
2022-07-16 23:28:13 +05:30
it 'uses total_open_issues_count cache key' do
expect(described_class.new(project, user).cache_key_name).to eq('total_open_issues_count')
2018-11-08 19:23:39 +05:30
end
end
2022-07-16 23:28:13 +05:30
context 'when user cannot read confidential issues' do
2018-11-08 19:23:39 +05:30
before do
project.add_guest(user)
end
2022-07-16 23:28:13 +05:30
it 'does not include confidential issues' do
create(:issue, :opened, project: project)
create(:issue, :opened, confidential: true, project: project)
2018-11-08 19:23:39 +05:30
2022-07-16 23:28:13 +05:30
expect(described_class.new(project, user).count).to eq(1)
2018-11-08 19:23:39 +05:30
end
2022-07-16 23:28:13 +05:30
it 'uses public_open_issues_count cache key' do
expect(described_class.new(project, user).cache_key_name).to eq('public_open_issues_count')
2018-11-08 19:23:39 +05:30
end
end
2018-03-17 18:26:18 +05:30
end
2018-11-08 19:23:39 +05:30
2022-07-16 23:28:13 +05:30
describe '#refresh_cache' do
before do
create(:issue, :opened, project: project)
2021-11-11 11:23:49 +05:30
create(:issue, :opened, project: project)
create(:issue, :opened, confidential: true, project: project)
2022-07-16 23:28:13 +05:30
end
2018-03-17 18:26:18 +05:30
2022-07-16 23:28:13 +05:30
context 'when cache is empty' do
it 'refreshes cache keys correctly' do
subject.refresh_cache
2018-03-17 18:26:18 +05:30
2022-07-16 23:28:13 +05:30
expect(Rails.cache.read(subject.cache_key(described_class::PUBLIC_COUNT_KEY))).to eq(2)
expect(Rails.cache.read(subject.cache_key(described_class::TOTAL_COUNT_KEY))).to eq(3)
end
end
context 'when cache is outdated' do
before do
subject.refresh_cache
end
it 'refreshes cache keys correctly' do
create(:issue, :opened, project: project)
create(:issue, :opened, confidential: true, project: project)
subject.refresh_cache
expect(Rails.cache.read(subject.cache_key(described_class::PUBLIC_COUNT_KEY))).to eq(3)
expect(Rails.cache.read(subject.cache_key(described_class::TOTAL_COUNT_KEY))).to eq(5)
end
2018-11-08 19:23:39 +05:30
end
2018-03-17 18:26:18 +05:30
end
end
end