daad7144ec
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.
22 lines
716 B
Ruby
22 lines
716 B
Ruby
require 'spec_helper'
|
|
|
|
describe Banzai::CommitRenderer do
|
|
describe '.render' do
|
|
it 'renders a commit description and title' do
|
|
user = build(:user)
|
|
project = create(:project, :repository)
|
|
|
|
expect(Banzai::ObjectRenderer)
|
|
.to receive(:new)
|
|
.with(user: user, default_project: project)
|
|
.and_call_original
|
|
|
|
described_class::ATTRIBUTES.each do |attr|
|
|
expect_any_instance_of(Banzai::ObjectRenderer).to receive(:render).with([project.commit], attr).once.and_call_original
|
|
expect(Banzai::Renderer).to receive(:cacheless_render_field).with(project.commit, attr, {})
|
|
end
|
|
|
|
described_class.render([project.commit], project, user)
|
|
end
|
|
end
|
|
end
|