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

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

69 lines
2.3 KiB
Ruby
Raw Permalink Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Projects::UpdateStatisticsService, feature_category: :projects do
2021-06-08 01:23:25 +05:30
using RSpec::Parameterized::TableSyntax
2022-08-27 11:52:29 +05:30
let(:service) { described_class.new(project, nil, statistics: statistics) }
2019-07-31 22:56:46 +05:30
let(:statistics) { %w(repository_size) }
describe '#execute' do
context 'with a non-existing project' do
let(:project) { nil }
it 'does nothing' do
expect_any_instance_of(ProjectStatistics).not_to receive(:refresh!)
service.execute
end
end
2019-09-04 21:01:54 +05:30
context 'with an existing project' do
2021-06-08 01:23:25 +05:30
let_it_be(:project) { create(:project) }
where(:statistics, :method_caches) do
[] | %i(size commit_count)
['repository_size'] | [:size]
[:repository_size] | [:size]
[:lfs_objects_size] | nil
2023-07-09 08:55:56 +05:30
[:commit_count] | [:commit_count]
2021-06-08 01:23:25 +05:30
[:repository_size, :commit_count] | %i(size commit_count)
[:repository_size, :commit_count, :lfs_objects_size] | %i(size commit_count)
end
with_them do
it 'refreshes the project statistics' do
expect(project.statistics).to receive(:refresh!).with(only: statistics.map(&:to_sym)).and_call_original
service.execute
end
it 'invalidates the method caches after a refresh' do
expect(project.wiki.repository).not_to receive(:expire_method_caches)
if method_caches.present?
expect(project.repository).to receive(:expire_method_caches).with(method_caches).and_call_original
else
expect(project.repository).not_to receive(:expire_method_caches)
end
service.execute
end
end
end
context 'with an existing project with a Wiki' do
let(:project) { create(:project, :repository, :wiki_enabled) }
let(:statistics) { [:wiki_size] }
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
it 'invalidates and refreshes Wiki size' do
expect(project.statistics).to receive(:refresh!).with(only: statistics).and_call_original
expect(project.wiki.repository).to receive(:expire_method_caches).with(%i(size)).and_call_original
2019-07-31 22:56:46 +05:30
service.execute
end
end
end
end