2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-02-26 11:00:46 +00:00
|
|
|
RSpec.shared_examples 'ApplicationModel::CanAssociations' do
|
|
|
|
subject { create(described_class.name.underscore) }
|
|
|
|
|
|
|
|
describe '#attributes_with_association_ids (for supplying model data to front-end framework)' do
|
|
|
|
describe 'caching' do
|
|
|
|
let(:cache_key) { "#{described_class}::aws::#{subject.id}" }
|
|
|
|
|
|
|
|
context 'with empty cache' do
|
|
|
|
it 'stores the computed value in the cache' do
|
|
|
|
expect { subject.attributes_with_association_ids }
|
|
|
|
.to change { Rails.cache.read(cache_key) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with stored value in cache' do
|
|
|
|
before { Rails.cache.write(cache_key, { foo: 'bar' }) }
|
|
|
|
|
|
|
|
it 'returns the cached value' do
|
|
|
|
expect(subject.attributes_with_association_ids).to include(foo: 'bar')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not modify the cached value' do
|
|
|
|
expect { subject.attributes_with_association_ids }
|
|
|
|
.not_to change { Rails.cache.read(cache_key) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|