diff options
Diffstat (limited to 'spec/services/namespaces/statistics_refresher_service_spec.rb')
-rw-r--r-- | spec/services/namespaces/statistics_refresher_service_spec.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/services/namespaces/statistics_refresher_service_spec.rb b/spec/services/namespaces/statistics_refresher_service_spec.rb index d3379e843ec..2d5f9235bd4 100644 --- a/spec/services/namespaces/statistics_refresher_service_spec.rb +++ b/spec/services/namespaces/statistics_refresher_service_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Namespaces::StatisticsRefresherService, '#execute' do let(:group) { create(:group) } + let(:subgroup) { create(:group, parent: group) } let(:projects) { create_list(:project, 5, namespace: group) } let(:service) { described_class.new } @@ -23,6 +24,14 @@ RSpec.describe Namespaces::StatisticsRefresherService, '#execute' do service.execute(group) end + + context 'when given a subgroup' do + it 'does not create statistics for the subgroup' do + service.execute(subgroup) + + expect(subgroup.reload.root_storage_statistics).not_to be_present + end + end end context 'with a root storage statistics relation', :sidekiq_might_not_need_inline do @@ -43,6 +52,16 @@ RSpec.describe Namespaces::StatisticsRefresherService, '#execute' do service.execute(group) end + + context 'when given a subgroup' do + it "recalculates the root namespace's statistics" do + expect(Namespace::RootStorageStatistics) + .to receive(:safe_find_or_create_by!).with({ namespace_id: group.id }) + .and_return(group.root_storage_statistics) + + service.execute(subgroup) + end + end end context 'when something goes wrong' do |