Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-05 12:08:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-05 12:08:43 +0300
commit26384c9a61da9922b8fa4b8351d4e42d51661b37 (patch)
treeef3decbed644db3c97dcdbb5b71d4ade77f3155d /spec/services/snippets
parent79cbe31b18159ea394c6f6e3027c1dc69bdabb75 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/snippets')
-rw-r--r--spec/services/snippets/count_service_spec.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/services/snippets/count_service_spec.rb b/spec/services/snippets/count_service_spec.rb
new file mode 100644
index 00000000000..4137e65dcca
--- /dev/null
+++ b/spec/services/snippets/count_service_spec.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Snippets::CountService do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :public) }
+
+ describe '#new' do
+ it 'raises an error if no author or project' do
+ expect { described_class.new(user) }.to raise_error(ArgumentError)
+ end
+
+ it 'uses the SnippetsFinder to scope snippets by user' do
+ expect(SnippetsFinder)
+ .to receive(:new)
+ .with(user, author: user, project: nil)
+
+ described_class.new(user, author: user)
+ end
+
+ it 'allows scoping to project' do
+ expect(SnippetsFinder)
+ .to receive(:new)
+ .with(user, author: nil, project: project)
+
+ described_class.new(user, project: project)
+ end
+ end
+
+ describe '#execute' do
+ subject { described_class.new(user, author: user).execute }
+
+ it 'returns a hash of counts' do
+ expect(subject).to match({
+ are_public: 0,
+ are_internal: 0,
+ are_private: 0,
+ are_public_or_internal: 0,
+ total: 0
+ })
+ end
+
+ it 'only counts snippets the user has access to' do
+ create(:personal_snippet, :private, author: user)
+ create(:project_snippet, :private, author: user)
+ create(:project_snippet, :private, author: create(:user))
+
+ expect(subject).to match({
+ are_public: 0,
+ are_internal: 0,
+ are_private: 1,
+ are_public_or_internal: 0,
+ total: 1
+ })
+ end
+
+ it 'returns an empty hash if select returns nil' do
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:snippet_counts).and_return(nil)
+ end
+
+ expect(subject).to match({})
+ end
+ end
+end