2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
module ReferenceParserHelpers
|
|
|
|
def empty_html_link
|
|
|
|
Nokogiri::HTML.fragment('<a></a>').children[0]
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-02-01 01:16:34 +05:30
|
|
|
def expect_gathered_references(result, visible, not_visible_count)
|
|
|
|
expect(result[:visible]).to eq(visible)
|
|
|
|
expect(result[:not_visible].count).to eq(not_visible_count)
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.shared_examples 'no project N+1 queries' do
|
2018-05-09 12:01:36 +05:30
|
|
|
it 'avoids N+1 queries in #nodes_visible_to_user', :request_store do
|
|
|
|
context = Banzai::RenderContext.new(project, user)
|
|
|
|
|
|
|
|
record_queries = lambda do |links|
|
|
|
|
ActiveRecord::QueryRecorder.new do
|
|
|
|
described_class.new(context).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
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.shared_examples 'no N+1 queries' do
|
2018-12-05 23:21:45 +05:30
|
|
|
it_behaves_like 'no project N+1 queries'
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
it 'avoids N+1 queries in #records_for_nodes', :request_store do
|
|
|
|
context = Banzai::RenderContext.new(project, user)
|
|
|
|
|
|
|
|
record_queries = lambda do |links|
|
|
|
|
ActiveRecord::QueryRecorder.new do
|
|
|
|
described_class.new(context).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
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|