debian-mirror-gitlab/spec/lib/banzai/object_renderer_spec.rb

54 lines
1.6 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
describe Banzai::ObjectRenderer do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-08-24 12:49:21 +05:30
let(:user) { project.owner }
2017-08-17 22:00:37 +05:30
let(:renderer) { described_class.new(project, user, custom_value: 'value') }
let(:object) { Note.new(note: 'hello', note_html: '<p dir="auto">hello</p>', cached_markdown_version: CacheMarkdownField::CACHE_VERSION) }
2016-11-03 12:29:30 +05:30
2016-08-24 12:49:21 +05:30
describe '#render' do
it 'renders and redacts an Array of objects' do
renderer.render([object], :note)
2017-08-17 22:00:37 +05:30
expect(object.redacted_note_html).to eq '<p dir="auto">hello</p>'
expect(object.user_visible_reference_count).to eq 0
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
it 'calls Banzai::Redactor to perform redaction' do
expect_any_instance_of(Banzai::Redactor).to receive(:redact).and_call_original
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
renderer.render([object], :note)
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
it 'retrieves field content using Banzai.render_field' do
expect(Banzai).to receive(:render_field).with(object, :note).and_call_original
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
renderer.render([object], :note)
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
it 'passes context to PostProcessPipeline' do
another_user = create(:user)
2017-09-10 17:25:29 +05:30
another_project = create(:project)
2017-08-17 22:00:37 +05:30
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-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
renderer.render([object], :note)
2016-08-24 12:49:21 +05:30
end
end
end