can_latest_change_examples.rb 953 B

1234567891011121314151617181920212223242526272829303132
  1. RSpec.shared_examples 'ApplicationModel::CanLatestChange' do
  2. subject { create(described_class.name.underscore) }
  3. describe '#latest_change' do
  4. describe 'caching updated_at' do
  5. context 'with empty cache' do
  6. it 'stores updated_at in the cache and returns it' do
  7. expect(subject.updated_at).to eq(described_class.latest_change)
  8. end
  9. end
  10. context 'with valid cache' do
  11. before { described_class.latest_change_set(subject.updated_at) }
  12. it 'return updated_at from cache' do
  13. expect(subject.updated_at).to eq(described_class.latest_change)
  14. end
  15. end
  16. context 'delete valid cache' do
  17. before do
  18. subject.touch
  19. described_class.latest_change_set(nil)
  20. end
  21. it 'stores new updated_at in the cache and returns it' do
  22. expect(subject.updated_at).to eq(described_class.latest_change)
  23. end
  24. end
  25. end
  26. end
  27. end