summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2019-09-11 04:48:21 +0000
committerThong Kuah <tkuah@gitlab.com>2019-09-11 04:48:21 +0000
commit28292d516abb33aeaf7e5bfaf94679d1317bd284 (patch)
tree0acb8ae2d6904b8d779230df7a170f2cd0c2b6bf /spec/lib
parentbb7bbcf7b667197e71f696cc17d8c08677629e8d (diff)
parentf1926b321deb8b922dead991fb4d8bea42699f9f (diff)
downloadgitlab-ce-28292d516abb33aeaf7e5bfaf94679d1317bd284.tar.gz
Merge branch '65988-optimize-snippet-listings' into 'master'
Optimize queries for snippet listings See merge request gitlab-org/gitlab-ce!32576
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/noteable_metadata_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/gitlab/noteable_metadata_spec.rb b/spec/lib/gitlab/noteable_metadata_spec.rb
new file mode 100644
index 00000000000..b12a1825f04
--- /dev/null
+++ b/spec/lib/gitlab/noteable_metadata_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::NoteableMetadata do
+ subject { Class.new { include Gitlab::NoteableMetadata }.new }
+
+ it 'returns an empty Hash if an empty collection is provided' do
+ expect(subject.noteable_meta_data(Snippet.none, 'Snippet')).to eq({})
+ end
+
+ it 'raises an error when given a collection with no limit' do
+ expect { subject.noteable_meta_data(Snippet.all, 'Snippet') }.to raise_error(/must have a limit/)
+ end
+
+ context 'snippets' do
+ let!(:snippet) { create(:personal_snippet) }
+ let!(:other_snippet) { create(:personal_snippet) }
+ let!(:note) { create(:note, noteable: snippet) }
+
+ it 'aggregates stats on snippets' do
+ data = subject.noteable_meta_data(Snippet.all.limit(10), 'Snippet')
+
+ expect(data.count).to eq(2)
+ expect(data[snippet.id].user_notes_count).to eq(1)
+ expect(data[other_snippet.id].user_notes_count).to eq(0)
+ end
+ end
+end