summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/filter/user_reference_filter_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-05-30 15:56:50 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2016-06-02 14:01:42 +0200
commit01575e9966805fa4c12a7a56361f511b3b61e309 (patch)
treed5120613919d475313e48e87ef19ada3f7cb9475 /spec/lib/banzai/filter/user_reference_filter_spec.rb
parent8a6c3f27e9dfea2c151657045e17fe66ad81b5e5 (diff)
downloadgitlab-ce-01575e9966805fa4c12a7a56361f511b3b61e309.tar.gz
Reduce Namespace queries in UserReferenceFilterbanzai-user-filter-queries
This changes UserReferenceFilter so it operates using the following steps: 1. Grab all username references from the input document. 2. Query the corresponding Namespace objects using a single query. 3. Iterate over all nodes to build links while re-using the objects queried in step 2. The impact of these changes is that a comment mentioning 5 different usernames no longer runs 5 different queries (1 for every username), instead it only runs a single query.
Diffstat (limited to 'spec/lib/banzai/filter/user_reference_filter_spec.rb')
-rw-r--r--spec/lib/banzai/filter/user_reference_filter_spec.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb
index d7dfd6699ef..108b36a97cc 100644
--- a/spec/lib/banzai/filter/user_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb
@@ -136,4 +136,23 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
expect(link.attr('data-user')).to eq user.namespace.owner_id.to_s
end
end
+
+ describe '#namespaces' do
+ it 'returns a Hash containing all Namespaces' do
+ document = Nokogiri::HTML.fragment("<p>#{user.to_reference}</p>")
+ filter = described_class.new(document, project: project)
+ ns = user.namespace
+
+ expect(filter.namespaces).to eq({ ns.path => ns })
+ end
+ end
+
+ describe '#usernames' do
+ it 'returns the usernames mentioned in a document' do
+ document = Nokogiri::HTML.fragment("<p>#{user.to_reference}</p>")
+ filter = described_class.new(document, project: project)
+
+ expect(filter.usernames).to eq([user.username])
+ end
+ end
end