summaryrefslogtreecommitdiff
path: root/spec/support/reference_parser_helpers.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-04-11 00:55:02 +0100
committerNick Thomas <nick@gitlab.com>2018-04-11 00:55:02 +0100
commit3f73bdd837f9803b75eca484a0a0615db6c58c80 (patch)
tree0bd2c99d9198bfa22e7a29f375131f940033da7b /spec/support/reference_parser_helpers.rb
parentb594ab949d1a2ceb9d949ff2641679fbdf273452 (diff)
parent37a5632483b67ddcfa4c535cc911319b25f01fb5 (diff)
downloadgitlab-ce-xterm-npm.tar.gz
Merge branch 'master' into xterm-npmxterm-npm
Diffstat (limited to 'spec/support/reference_parser_helpers.rb')
-rw-r--r--spec/support/reference_parser_helpers.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/support/reference_parser_helpers.rb b/spec/support/reference_parser_helpers.rb
index 01689194eac..5d5e80851e6 100644
--- a/spec/support/reference_parser_helpers.rb
+++ b/spec/support/reference_parser_helpers.rb
@@ -2,4 +2,34 @@ module ReferenceParserHelpers
def empty_html_link
Nokogiri::HTML.fragment('<a></a>').children[0]
end
+
+ shared_examples 'no N+1 queries' do
+ it 'avoids N+1 queries in #nodes_visible_to_user', :request_store do
+ record_queries = lambda do |links|
+ ActiveRecord::QueryRecorder.new do
+ described_class.new(project, user).nodes_visible_to_user(user, links)
+ end
+ end
+
+ control = record_queries.call(control_links)
+ actual = record_queries.call(actual_links)
+
+ expect(actual.count).to be <= control.count
+ expect(actual.cached_count).to be <= control.cached_count
+ end
+
+ it 'avoids N+1 queries in #records_for_nodes', :request_store do
+ record_queries = lambda do |links|
+ ActiveRecord::QueryRecorder.new do
+ described_class.new(project, user).records_for_nodes(links)
+ end
+ end
+
+ control = record_queries.call(control_links)
+ actual = record_queries.call(actual_links)
+
+ expect(actual.count).to be <= control.count
+ expect(actual.cached_count).to be <= control.cached_count
+ end
+ end
end