2016-05-26 07:16:43 -04:00
|
|
|
module ReferenceParserHelpers
|
|
|
|
def empty_html_link
|
|
|
|
Nokogiri::HTML.fragment('<a></a>').children[0]
|
|
|
|
end
|
2018-04-02 11:14:20 -04:00
|
|
|
|
|
|
|
shared_examples 'no N+1 queries' do
|
|
|
|
it 'avoids N+1 queries in #nodes_visible_to_user', :request_store do
|
2018-04-03 09:45:17 -04:00
|
|
|
context = Banzai::RenderContext.new(project, user)
|
|
|
|
|
2018-04-02 11:14:20 -04:00
|
|
|
record_queries = lambda do |links|
|
|
|
|
ActiveRecord::QueryRecorder.new do
|
2018-04-03 09:45:17 -04:00
|
|
|
described_class.new(context).nodes_visible_to_user(user, links)
|
2018-04-02 11:14:20 -04:00
|
|
|
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
|
2018-04-03 09:45:17 -04:00
|
|
|
context = Banzai::RenderContext.new(project, user)
|
|
|
|
|
2018-04-02 11:14:20 -04:00
|
|
|
record_queries = lambda do |links|
|
|
|
|
ActiveRecord::QueryRecorder.new do
|
2018-04-03 09:45:17 -04:00
|
|
|
described_class.new(context).records_for_nodes(links)
|
2018-04-02 11:14:20 -04:00
|
|
|
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-05-26 07:16:43 -04:00
|
|
|
end
|