summaryrefslogtreecommitdiff
path: root/spec/models/snippet_statistics_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-08 09:09:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-08 09:09:17 +0000
commit21341457a8c422d890a9ec30838b597dea565d62 (patch)
treeaa8aca2a9bce4e16936cc8d7b40aa1c79ca82e35 /spec/models/snippet_statistics_spec.rb
parent0a319374e7784aa5c2d1c30dd832d2a0509edbab (diff)
downloadgitlab-ce-21341457a8c422d890a9ec30838b597dea565d62.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/snippet_statistics_spec.rb')
-rw-r--r--spec/models/snippet_statistics_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/models/snippet_statistics_spec.rb b/spec/models/snippet_statistics_spec.rb
index 57a3f844a8a..ad25bd7b3be 100644
--- a/spec/models/snippet_statistics_spec.rb
+++ b/spec/models/snippet_statistics_spec.rb
@@ -86,4 +86,64 @@ RSpec.describe SnippetStatistics do
subject
end
end
+
+ context 'with a PersonalSnippet' do
+ let!(:snippet) { create(:personal_snippet, :repository) }
+
+ shared_examples 'personal snippet statistics updates' do
+ it 'schedules a namespace statistics worker' do
+ expect(Namespaces::ScheduleAggregationWorker)
+ .to receive(:perform_async).once
+
+ statistics.save!
+ end
+
+ it 'does not try to update project stats' do
+ expect(statistics).not_to receive(:schedule_update_project_statistic)
+
+ statistics.save!
+ end
+ end
+
+ context 'when creating' do
+ let(:statistics) { build(:snippet_statistics, snippet_id: snippet.id, with_data: true) }
+
+ before do
+ snippet.statistics.delete
+ end
+
+ it_behaves_like 'personal snippet statistics updates'
+ end
+
+ context 'when updating' do
+ let(:statistics) { snippet.statistics }
+
+ before do
+ snippet.statistics.repository_size = 123
+ end
+
+ it_behaves_like 'personal snippet statistics updates'
+ end
+ end
+
+ context 'with a ProjectSnippet' do
+ let!(:snippet) { create(:project_snippet) }
+
+ it_behaves_like 'UpdateProjectStatistics' do
+ subject { build(:snippet_statistics, snippet: snippet, id: snippet.id, with_data: true) }
+
+ before do
+ # The shared examples requires the snippet statistics not to be present
+ snippet.statistics.delete
+ snippet.reload
+ end
+ end
+
+ it 'does not call personal snippet callbacks' do
+ expect(snippet.statistics).not_to receive(:update_author_root_storage_statistics)
+ expect(snippet.statistics).to receive(:schedule_update_project_statistic)
+
+ snippet.statistics.update!(repository_size: 123)
+ end
+ end
end