diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb index ea10b06439b736d8bd79da7924bdbfb5f57c2699..910687a7b6a33c0db68cfcd4d796701e801d01b9 100644 --- a/lib/banzai/renderer.rb +++ b/lib/banzai/renderer.rb @@ -61,10 +61,16 @@ module Banzai end cacheable_items, non_cacheable_items = items_collection.partition { |item| item.key?(:cache_key) } - items_in_cache = Rails.cache.read_multi(*cacheable_items.map { |item| item[:cache_key] }) - items_not_in_cache = cacheable_items.reject do |item| - item[:rendered] = items_in_cache[item[:cache_key]] - items_in_cache.key?(item[:cache_key]) + + items_in_cache = [] + items_not_in_cache = [] + + unless cacheable_items.empty? + items_in_cache = Rails.cache.read_multi(*cacheable_items.map { |item| item[:cache_key] }) + items_not_in_cache = cacheable_items.reject do |item| + item[:rendered] = items_in_cache[item[:cache_key]] + items_in_cache.key?(item[:cache_key]) + end end (items_not_in_cache + non_cacheable_items).each do |item| diff --git a/spec/lib/banzai/object_renderer_spec.rb b/spec/lib/banzai/object_renderer_spec.rb index cf6cdd33ebbe93d70ec83dd8ba29971f89c19756..bcdb95250caee162af0ffc151c907ffa832b6add 100644 --- a/spec/lib/banzai/object_renderer_spec.rb +++ b/spec/lib/banzai/object_renderer_spec.rb @@ -109,6 +109,17 @@ describe Banzai::ObjectRenderer do expect(docs[1]).to be_an_instance_of(Nokogiri::HTML::DocumentFragment) expect(docs[1].to_html).to eq('<p>bye</p>') end + + it 'returns when no objects to render' do + objects = [] + renderer = described_class.new(project, user, pipeline: :note) + + expect(Banzai).to receive(:cache_collection_render). + with([]). + and_call_original + + expect(renderer.render_attributes(objects, :note)).to eq([]) + end end describe '#base_context' do