diff options
Diffstat (limited to 'spec/services/groups/update_statistics_service_spec.rb')
-rw-r--r-- | spec/services/groups/update_statistics_service_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/services/groups/update_statistics_service_spec.rb b/spec/services/groups/update_statistics_service_spec.rb new file mode 100644 index 00000000000..5bef51c2727 --- /dev/null +++ b/spec/services/groups/update_statistics_service_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::UpdateStatisticsService 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 |