diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-06 18:09:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-06 18:09:13 +0000 |
commit | 691ed55a053853e58f36635524d2615ac60e445e (patch) | |
tree | 923c7097cfe2c4beaee82d0b5227f443b760bbed /spec/models/namespace | |
parent | ce06ce825b9ef5204a84aaa37d0dfc7742da5037 (diff) | |
download | gitlab-ce-691ed55a053853e58f36635524d2615ac60e445e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/namespace')
-rw-r--r-- | spec/models/namespace/root_storage_statistics_spec.rb | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/spec/models/namespace/root_storage_statistics_spec.rb b/spec/models/namespace/root_storage_statistics_spec.rb index 9d516dc5ec2..ce6f875ee09 100644 --- a/spec/models/namespace/root_storage_statistics_spec.rb +++ b/spec/models/namespace/root_storage_statistics_spec.rb @@ -70,7 +70,16 @@ RSpec.describe Namespace::RootStorageStatistics, type: :model do end end + shared_examples 'does not include personal snippets' do + specify do + expect(root_storage_statistics).not_to receive(:from_personal_snippets) + + root_storage_statistics.recalculate! + end + end + it_behaves_like 'data refresh' + it_behaves_like 'does not include personal snippets' context 'with subgroups' do let(:subgroup1) { create(:group, parent: namespace)} @@ -80,12 +89,45 @@ RSpec.describe Namespace::RootStorageStatistics, type: :model do let(:project2) { create(:project, namespace: subgroup2) } it_behaves_like 'data refresh' + it_behaves_like 'does not include personal snippets' end context 'with a personal namespace' do - let(:namespace) { create(:user).namespace } + let_it_be(:user) { create(:user) } + let(:namespace) { user.namespace } it_behaves_like 'data refresh' + + context 'when user has personal snippets' do + let(:total_project_snippets_size) { stat1.snippets_size + stat2.snippets_size } + + it 'aggregates personal and project snippets size' do + # This is just a a snippet authored by other user + # to ensure we only pick snippets from the namespace + # user + create(:personal_snippet, :repository).statistics.refresh! + + snippets = create_list(:personal_snippet, 3, :repository, author: user) + snippets.each { |s| s.statistics.refresh! } + + total_personal_snippets_size = snippets.map { |s| s.statistics.repository_size }.sum + + root_storage_statistics.recalculate! + + expect(root_storage_statistics.snippets_size).to eq(total_personal_snippets_size + total_project_snippets_size) + end + + context 'when personal snippets do not have statistics' do + it 'does not raise any error' do + snippets = create_list(:personal_snippet, 2, :repository, author: user) + snippets.last.statistics.refresh! + + root_storage_statistics.recalculate! + + expect(root_storage_statistics.snippets_size).to eq(total_project_snippets_size + snippets.last.statistics.repository_size) + end + end + end end end end |