2016-10-06 21:17:11 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Banzai::Renderer do
|
2017-04-10 18:36:30 +00:00
|
|
|
def fake_object(fresh:)
|
|
|
|
object = double('object')
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
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')
|
2016-10-06 21:17:11 +00:00
|
|
|
|
|
|
|
object
|
|
|
|
end
|
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
describe '#render_field' do
|
2016-10-06 21:17:11 +00:00
|
|
|
let(:renderer) { Banzai::Renderer }
|
2017-04-10 18:36:30 +00:00
|
|
|
subject { renderer.render_field(object, :field) }
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
context 'with a stale cache' do
|
|
|
|
let(:object) { fake_object(fresh: false) }
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
it 'caches and returns the result' do
|
|
|
|
expect(object).to receive(:refresh_markdown_cache!).with(do_update: true)
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
is_expected.to eq('field_html')
|
2016-10-06 21:17:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
context 'with an up-to-date cache' do
|
|
|
|
let(:object) { fake_object(fresh: true) }
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
it 'uses the cache' do
|
|
|
|
expect(object).to receive(:refresh_markdown_cache!).never
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2017-04-10 18:36:30 +00:00
|
|
|
is_expected.to eq('field_html')
|
2016-10-06 21:17:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|