summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/renderer_spec.rb
blob: e6f8d2a1fed62bbd0a337e07920e65a8fb9d127e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'spec_helper'

describe Banzai::Renderer do
  def fake_object(fresh:)
    object = double('object')

    allow(object).to receive(:cached_html_up_to_date?).with(:field).and_return(fresh)
    allow(object).to receive(:cached_html_for).with(:field).and_return('field_html')

    object
  end

  describe '#render_field' do
    let(:renderer) { Banzai::Renderer }
    subject { renderer.render_field(object, :field) }

    context 'with a stale cache' do
      let(:object) { fake_object(fresh: false) }

      it 'caches and returns the result' do
        expect(object).to receive(:refresh_markdown_cache!).with(do_update: true)

        is_expected.to eq('field_html')
      end
    end

    context 'with an up-to-date cache' do
      let(:object) { fake_object(fresh: true) }

      it 'uses the cache' do
        expect(object).to receive(:refresh_markdown_cache!).never

        is_expected.to eq('field_html')
      end
    end
  end
end