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

69 lines
2.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Projects::UpdateStatisticsService do
2021-06-08 01:23:25 +05:30
using RSpec::Parameterized::TableSyntax
2019-07-31 22:56:46 +05:30
let(:service) { described_class.new(project, nil, statistics: statistics)}
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
[:commit_count] | [:commit_count] # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
[: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