2016-06-21 07:35:09 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Banzai::ObjectRenderer do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-06-21 07:35:09 -04:00
|
|
|
let(:user) { project.owner }
|
2016-08-24 13:11:48 -04:00
|
|
|
let(:renderer) { described_class.new(project, user, custom_value: 'value') }
|
2017-04-10 14:36:30 -04:00
|
|
|
let(:object) { Note.new(note: 'hello', note_html: '<p dir="auto">hello</p>', cached_markdown_version: CacheMarkdownField::CACHE_VERSION) }
|
2016-10-06 17:52:44 -04:00
|
|
|
|
2016-06-21 07:35:09 -04:00
|
|
|
describe '#render' do
|
|
|
|
it 'renders and redacts an Array of objects' do
|
|
|
|
renderer.render([object], :note)
|
|
|
|
|
2017-04-10 14:36:30 -04:00
|
|
|
expect(object.redacted_note_html).to eq '<p dir="auto">hello</p>'
|
2016-08-24 13:11:48 -04:00
|
|
|
expect(object.user_visible_reference_count).to eq 0
|
2016-06-21 07:35:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
it 'calls Banzai::Redactor to perform redaction' do
|
|
|
|
expect_any_instance_of(Banzai::Redactor).to receive(:redact).and_call_original
|
2016-06-21 07:35:09 -04:00
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
renderer.render([object], :note)
|
2016-07-13 03:23:55 -04:00
|
|
|
end
|
2016-06-21 07:35:09 -04:00
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
it 'retrieves field content using Banzai.render_field' do
|
|
|
|
expect(Banzai).to receive(:render_field).with(object, :note).and_call_original
|
2016-06-21 07:35:09 -04:00
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
renderer.render([object], :note)
|
2016-06-21 07:35:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
it 'passes context to PostProcessPipeline' do
|
|
|
|
another_user = create(:user)
|
2017-08-02 15:55:11 -04:00
|
|
|
another_project = create(:project)
|
2016-08-24 13:11:48 -04:00
|
|
|
object = Note.new(
|
|
|
|
note: 'hello',
|
|
|
|
note_html: 'hello',
|
|
|
|
author: another_user,
|
|
|
|
project: another_project
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(Banzai::Pipeline::PostProcessPipeline).to receive(:to_document).with(
|
|
|
|
anything,
|
|
|
|
hash_including(
|
|
|
|
skip_redaction: true,
|
|
|
|
current_user: user,
|
|
|
|
project: another_project,
|
|
|
|
author: another_user,
|
|
|
|
custom_value: 'value'
|
|
|
|
)
|
|
|
|
).and_call_original
|
2016-06-21 07:35:09 -04:00
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
renderer.render([object], :note)
|
2016-06-21 07:35:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|