2021-03-18 10:41:32 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 13:49:53 +10:00
|
|
|
RSpec.describe CacheConcern do
|
2021-03-18 10:41:32 +11:00
|
|
|
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
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when given an empty array' do
|
2021-03-18 10:41:32 +11:00
|
|
|
it 'returns an empty array' do
|
|
|
|
get :empty_array
|
|
|
|
expect(response.body).to eq '0'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when given an empty relation' do
|
2021-03-18 10:41:32 +11:00
|
|
|
it 'returns an empty array' do
|
|
|
|
get :empty_relation
|
|
|
|
expect(response.body).to eq '0'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|