summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/reference_parser/base_parser_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-04-03 15:45:17 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2018-04-11 14:10:19 +0200
commitdaad7144ec7c0173439eeadd61590442e40a6051 (patch)
tree80a738c17196d0235cbc4c5589d6b04f96688b5c /spec/lib/banzai/reference_parser/base_parser_spec.rb
parent23fb465c75d00fd7156a540b7421a79e22df3966 (diff)
downloadgitlab-ce-daad7144ec7c0173439eeadd61590442e40a6051.tar.gz
Support Markdown rendering using multiple projectsrendering-markdown-multiple-projects
This refactors the Markdown pipeline so it supports the rendering of multiple documents that may belong to different projects. An example of where this happens is when displaying the event feed of a group. In this case we retrieve events for all projects in the group. Previously we would group events per project and render these chunks separately, but this would result in many SQL queries being executed. By extending the Markdown pipeline to support this out of the box we can drastically reduce the number of SQL queries. To achieve this we introduce a new object to the pipeline: Banzai::RenderContext. This object simply wraps two other objects: an optional Project instance, and an optional User instance. On its own this wouldn't be very helpful, but a RenderContext can also be used to associate HTML documents with specific Project instances. This work is done in Banzai::ObjectRenderer and allows us to reuse as many queries (and results) as possible.
Diffstat (limited to 'spec/lib/banzai/reference_parser/base_parser_spec.rb')
-rw-r--r--spec/lib/banzai/reference_parser/base_parser_spec.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb
index 6175d4c4ca9..4e6e8eca38a 100644
--- a/spec/lib/banzai/reference_parser/base_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb
@@ -5,13 +5,14 @@ describe Banzai::ReferenceParser::BaseParser do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
+ let(:context) { Banzai::RenderContext.new(project, user) }
subject do
klass = Class.new(described_class) do
self.reference_type = :foo
end
- klass.new(project, user)
+ klass.new(context)
end
describe '.reference_type=' do
@@ -23,6 +24,19 @@ describe Banzai::ReferenceParser::BaseParser do
end
end
+ describe '#project_for_node' do
+ it 'returns the Project for a node' do
+ document = instance_double('document', fragment?: false)
+ project = instance_double('project')
+ object = instance_double('object', project: project)
+ node = instance_double('node', document: document)
+
+ context.associate_document(document, object)
+
+ expect(subject.project_for_node(node)).to eq(project)
+ end
+ end
+
describe '#nodes_visible_to_user' do
let(:link) { empty_html_link }
@@ -164,7 +178,7 @@ describe Banzai::ReferenceParser::BaseParser do
self.reference_type = :test
end
- instance = dummy.new(project, user)
+ instance = dummy.new(Banzai::RenderContext.new(project, user))
document = Nokogiri::HTML.fragment('<a class="gfm"></a><a class="gfm" data-reference-type="test"></a>')
expect(instance).to receive(:gather_references)