can_associations_examples.rb 994 B

1234567891011121314151617181920212223242526272829
  1. RSpec.shared_examples 'ApplicationModel::CanAssociations' do
  2. subject { create(described_class.name.underscore) }
  3. describe '#attributes_with_association_ids (for supplying model data to front-end framework)' do
  4. describe 'caching' do
  5. let(:cache_key) { "#{described_class}::aws::#{subject.id}" }
  6. context 'with empty cache' do
  7. it 'stores the computed value in the cache' do
  8. expect { subject.attributes_with_association_ids }
  9. .to change { Rails.cache.read(cache_key) }
  10. end
  11. end
  12. context 'with stored value in cache' do
  13. before { Rails.cache.write(cache_key, { foo: 'bar' }) }
  14. it 'returns the cached value' do
  15. expect(subject.attributes_with_association_ids).to include(foo: 'bar')
  16. end
  17. it 'does not modify the cached value' do
  18. expect { subject.attributes_with_association_ids }
  19. .not_to change { Rails.cache.read(cache_key) }
  20. end
  21. end
  22. end
  23. end
  24. end