diff options
Diffstat (limited to 'spec/services/groups')
-rw-r--r-- | spec/services/groups/import_export/export_service_spec.rb | 14 | ||||
-rw-r--r-- | spec/services/groups/open_issues_count_service_spec.rb | 106 |
2 files changed, 118 insertions, 2 deletions
diff --git a/spec/services/groups/import_export/export_service_spec.rb b/spec/services/groups/import_export/export_service_spec.rb index 690bcb94556..d6ce40f413b 100644 --- a/spec/services/groups/import_export/export_service_spec.rb +++ b/spec/services/groups/import_export/export_service_spec.rb @@ -71,6 +71,16 @@ RSpec.describe Groups::ImportExport::ExportService do service.execute end + it 'compresses and removes tmp files' do + expect(group.import_export_upload).to be_nil + expect(Gitlab::ImportExport::Saver).to receive(:new).and_call_original + + service.execute + + expect(Dir.exist?(shared.archive_path)).to eq false + expect(File.exist?(group.import_export_upload.export_file.path)).to eq true + end + it 'notifies the user' do expect_next_instance_of(NotificationService) do |instance| expect(instance).to receive(:group_was_exported) @@ -134,7 +144,7 @@ RSpec.describe Groups::ImportExport::ExportService do expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) expect(group.import_export_upload).to be_nil - expect(Dir.exist?(shared.base_path)).to eq(false) + expect(Dir.exist?(shared.archive_path)).to eq(false) end it 'notifies the user about failed group export' do @@ -159,7 +169,7 @@ RSpec.describe Groups::ImportExport::ExportService do expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) expect(group.import_export_upload).to be_nil - expect(Dir.exist?(shared.base_path)).to eq(false) + expect(Dir.exist?(shared.archive_path)).to eq(false) end it 'notifies logger' do diff --git a/spec/services/groups/open_issues_count_service_spec.rb b/spec/services/groups/open_issues_count_service_spec.rb new file mode 100644 index 00000000000..8bbb1c90c6b --- /dev/null +++ b/spec/services/groups/open_issues_count_service_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::OpenIssuesCountService, :use_clean_rails_memory_store_caching do + let_it_be(:group) { create(:group, :public)} + let_it_be(:project) { create(:project, :public, namespace: group) } + let_it_be(:user) { create(:user) } + 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) } + + 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) + .with(user, group_id: group.id, state: 'opened', non_archived: true, include_subgroups: true, public_only: true) + + subject.count + end + end + + describe '#count' do + context 'when user is nil' do + it 'does not include confidential issues in the issue count' do + expect(described_class.new(group).count).to eq(1) + end + end + + context 'when user is provided' do + context 'when user can read confidential issues' do + before do + group.add_reporter(user) + end + + it 'returns the right count with confidential issues' do + expect(subject.count).to eq(2) + end + end + + context 'when user cannot read confidential issues' do + before do + group.add_guest(user) + end + + it 'does not include confidential issues' do + expect(subject.count).to eq(1) + end + end + + context 'with different cache values' do + let(:public_count_key) { subject.cache_key(described_class::PUBLIC_COUNT_KEY) } + let(:under_threshold) { described_class::CACHED_COUNT_THRESHOLD - 1 } + let(:over_threshold) { described_class::CACHED_COUNT_THRESHOLD + 1 } + + context 'when cache is empty' do + before do + Rails.cache.delete(public_count_key) + end + + it 'refreshes cache if value over threshold' do + allow(subject).to receive(:uncached_count).and_return(over_threshold) + + expect(subject.count).to eq(over_threshold) + expect(Rails.cache.read(public_count_key)).to eq(over_threshold) + end + + it 'does not refresh cache if value under threshold' do + allow(subject).to receive(:uncached_count).and_return(under_threshold) + + expect(subject.count).to eq(under_threshold) + expect(Rails.cache.read(public_count_key)).to be_nil + end + end + + context 'when cached count is under the threshold value' do + before do + Rails.cache.write(public_count_key, under_threshold) + end + + it 'does not refresh cache' do + expect(Rails.cache).not_to receive(:write) + expect(subject.count).to eq(under_threshold) + end + end + + context 'when cached count is over the threshold value' do + before do + Rails.cache.write(public_count_key, over_threshold) + end + + it 'does not refresh cache' do + expect(Rails.cache).not_to receive(:write) + expect(subject.count).to eq(over_threshold) + end + end + end + end + end +end |