You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
877 B

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe CacheConcern, type: :controller 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 '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 '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