1
0

cache_concern_spec.rb 868 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe CacheConcern do
  4. controller(ApplicationController) do
  5. include CacheConcern
  6. def empty_array
  7. render plain: cache_collection([], Status).size
  8. end
  9. def empty_relation
  10. render plain: cache_collection(Status.none, Status).size
  11. end
  12. end
  13. before do
  14. routes.draw do
  15. get 'empty_array' => 'anonymous#empty_array'
  16. post 'empty_relation' => 'anonymous#empty_relation'
  17. end
  18. end
  19. describe '#cache_collection' do
  20. context 'when given an empty array' do
  21. it 'returns an empty array' do
  22. get :empty_array
  23. expect(response.body).to eq '0'
  24. end
  25. end
  26. context 'when given an empty relation' do
  27. it 'returns an empty array' do
  28. get :empty_relation
  29. expect(response.body).to eq '0'
  30. end
  31. end
  32. end
  33. end