1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::UpdateStatisticsService, feature_category: :groups_and_projects do
let_it_be(:group, reload: true) { create(:group) }
let(:statistics) { %w[wiki_size] }
subject(:service) { described_class.new(group, statistics: statistics) }
describe '#execute', :aggregate_failures do
context 'when group is nil' do
let(:group) { nil }
it 'does nothing' do
expect(NamespaceStatistics).not_to receive(:new)
result = service.execute
expect(result).to be_error
end
end
context 'with an existing group' do
context 'when namespace statistics exists for the group' do
it 'uses the existing statistics and refreshes them' do
namespace_statistics = create(:namespace_statistics, namespace: group)
expect(namespace_statistics).to receive(:refresh!).with(only: statistics.map(&:to_sym)).and_call_original
result = service.execute
expect(result).to be_success
end
end
context 'when namespace statistics does not exist for the group' do
it 'creates the statistics and refreshes them' do
expect_next_instance_of(NamespaceStatistics) do |instance|
expect(instance).to receive(:refresh!).with(only: statistics.map(&:to_sym)).and_call_original
end
result = nil
expect do
result = service.execute
end.to change { NamespaceStatistics.count }.by(1)
expect(result).to be_success
end
end
end
end
end
|