0
0
Fork 0

Fix cache_collection crashing when given an empty collection (#15921)

* Fix cache_collection crashing when given an empty collection

* Add tests
This commit is contained in:
Claire 2021-03-18 00:41:32 +01:00 committed by GitHub
parent 43eff898a0
commit 5027abecd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 2 deletions

View file

@ -0,0 +1,40 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe CacheConcern, type: :controller do
controller(ApplicationController) do
include CacheConcern
def empty_array
render plain: cache_collection([], Status).size
end
def empty_relation
render plain: cache_collection(Status.none, Status).size
end
end
before do
routes.draw do
get 'empty_array' => 'anonymous#empty_array'
post 'empty_relation' => 'anonymous#empty_relation'
end
end
describe '#cache_collection' do
context 'given an empty array' do
it 'returns an empty array' do
get :empty_array
expect(response.body).to eq '0'
end
end
context 'given an empty relation' do
it 'returns an empty array' do
get :empty_relation
expect(response.body).to eq '0'
end
end
end
end