diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-30 18:08:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-30 18:08:48 +0300 |
commit | 340f15b402eec795fca0e0f29709baef0ecf14a7 (patch) | |
tree | 6a7eac5d394f4002b9e5b0c9da12bc12e59ed59c /spec/services/snippets | |
parent | 1e254d9f5a46a85c9bb6f24da8265a30fd388db4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/snippets')
-rw-r--r-- | spec/services/snippets/destroy_service_spec.rb | 13 | ||||
-rw-r--r-- | spec/services/snippets/update_statistics_service_spec.rb | 81 |
2 files changed, 94 insertions, 0 deletions
diff --git a/spec/services/snippets/destroy_service_spec.rb b/spec/services/snippets/destroy_service_spec.rb index 12423ad2d73..70862e0be17 100644 --- a/spec/services/snippets/destroy_service_spec.rb +++ b/spec/services/snippets/destroy_service_spec.rb @@ -105,6 +105,13 @@ RSpec.describe Snippets::DestroyService do it_behaves_like 'a successful destroy' it_behaves_like 'deletes the snippet repository' + + it 'schedules a project cache update for snippet_size' do + expect(ProjectCacheWorker).to receive(:perform_async) + .with(snippet.project_id, [], [:snippets_size]) + + subject + end end context 'when user is not able to admin_project_snippet' do @@ -122,6 +129,12 @@ RSpec.describe Snippets::DestroyService do it_behaves_like 'a successful destroy' it_behaves_like 'deletes the snippet repository' + + it 'does not schedule a project cache update' do + expect(ProjectCacheWorker).not_to receive(:perform_async) + + subject + end end context 'when user is not able to admin_personal_snippet' do diff --git a/spec/services/snippets/update_statistics_service_spec.rb b/spec/services/snippets/update_statistics_service_spec.rb new file mode 100644 index 00000000000..b4c4b067c51 --- /dev/null +++ b/spec/services/snippets/update_statistics_service_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Snippets::UpdateStatisticsService do + describe '#execute' do + subject { described_class.new(snippet).execute } + + shared_examples 'updates statistics' do + it 'returns a successful response' do + expect(subject).to be_success + end + + it 'expires statistics cache' do + expect(snippet.repository).to receive(:expire_statistics_caches) + + subject + end + + it 'schedules project cache worker based on type' do + if snippet.project_id + expect(ProjectCacheWorker).to receive(:perform_async) + .with(snippet.project_id, [], [:snippets_size]) + else + expect(ProjectCacheWorker).not_to receive(:perform_async) + end + + subject + end + + context 'when snippet statistics does not exist' do + it 'creates snippet statistics' do + snippet.statistics.delete + snippet.reload + + expect do + subject + end.to change(SnippetStatistics, :count).by(1) + + expect(snippet.statistics.commit_count).not_to be_zero + expect(snippet.statistics.file_count).not_to be_zero + expect(snippet.statistics.repository_size).not_to be_zero + end + end + + context 'when snippet statistics exists' do + it 'updates snippet statistics' do + expect(snippet.statistics.commit_count).to be_zero + expect(snippet.statistics.file_count).to be_zero + expect(snippet.statistics.repository_size).to be_zero + + subject + + expect(snippet.statistics.commit_count).not_to be_zero + expect(snippet.statistics.file_count).not_to be_zero + expect(snippet.statistics.repository_size).not_to be_zero + end + end + + context 'when snippet does not have a repository' do + it 'returns an error response' do + expect(snippet).to receive(:repository_exists?).and_return(false) + + expect(subject).to be_error + end + end + end + + context 'with PersonalSnippet' do + let!(:snippet) { create(:personal_snippet, :repository) } + + it_behaves_like 'updates statistics' + end + + context 'with ProjectSnippet' do + let!(:snippet) { create(:project_snippet, :repository) } + + it_behaves_like 'updates statistics' + end + end +end |