2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-06-27 10:01:40 +00:00
|
|
|
RSpec.shared_examples 'ApplicationModel::CanLatestChange' do
|
|
|
|
subject { create(described_class.name.underscore) }
|
|
|
|
|
|
|
|
describe '#latest_change' do
|
|
|
|
describe 'caching updated_at' do
|
|
|
|
context 'with empty cache' do
|
|
|
|
it 'stores updated_at in the cache and returns it' do
|
|
|
|
expect(subject.updated_at).to eq(described_class.latest_change)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with valid cache' do
|
|
|
|
before { described_class.latest_change_set(subject.updated_at) }
|
|
|
|
|
|
|
|
it 'return updated_at from cache' do
|
|
|
|
expect(subject.updated_at).to eq(described_class.latest_change)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'delete valid cache' do
|
|
|
|
before do
|
|
|
|
subject.touch
|
|
|
|
described_class.latest_change_set(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'stores new updated_at in the cache and returns it' do
|
|
|
|
expect(subject.updated_at).to eq(described_class.latest_change)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|