BigW Consortium Gitlab

object_renderer_spec.rb 1.6 KB
Newer Older
1 2 3
require 'spec_helper'

describe Banzai::ObjectRenderer do
4
  let(:project) { create(:project) }
5
  let(:user) { project.owner }
6
  let(:renderer) { described_class.new(project, user, custom_value: 'value') }
7
  let(:object) { Note.new(note: 'hello', note_html: '<p dir="auto">hello</p>', cached_markdown_version: CacheMarkdownField::CACHE_VERSION) }
8

9 10 11 12
  describe '#render' do
    it 'renders and redacts an Array of objects' do
      renderer.render([object], :note)

13
      expect(object.redacted_note_html).to eq '<p dir="auto">hello</p>'
14
      expect(object.user_visible_reference_count).to eq 0
15 16
    end

17 18
    it 'calls Banzai::Redactor to perform redaction' do
      expect_any_instance_of(Banzai::Redactor).to receive(:redact).and_call_original
19

20
      renderer.render([object], :note)
21
    end
22

23 24
    it 'retrieves field content using Banzai.render_field' do
      expect(Banzai).to receive(:render_field).with(object, :note).and_call_original
25

26
      renderer.render([object], :note)
27 28
    end

29 30
    it 'passes context to PostProcessPipeline' do
      another_user = create(:user)
31
      another_project = create(:project)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
      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
49

50
      renderer.render([object], :note)
51 52 53
    end
  end
end