Maintenance: Fixed cache test that is error prone to timezone DST changes.

This commit is contained in:
Thorsten Eckel 2019-03-25 18:41:40 +01:00
parent eb9767278d
commit a1bb61bf56

View file

@ -42,11 +42,19 @@ RSpec.describe Cache do
.to change { Cache.get('123') }.to({ key: 'some valueöäüß' }) .to change { Cache.get('123') }.to({ key: 'some valueöäüß' })
end end
context 'when expiring' do
# we need to travel to a fixed point in time
# to prevent influences of timezone / DST
before do
travel_to '1995-12-21 13:37 +0100'
end
it 'defaults to expires_in: 7.days' do it 'defaults to expires_in: 7.days' do
Cache.write('123', 'some value') Cache.write('123', 'some value')
expect { travel 7.days }.not_to change { Cache.get('123') } expect { travel 7.days - 1.second }.not_to change { Cache.get('123') }
expect { travel 1.second }.to change { Cache.get('123') }.to(nil) expect { travel 2.seconds }.to change { Cache.get('123') }.to(nil)
end end
it 'accepts a custom :expires_in option' do it 'accepts a custom :expires_in option' do
@ -55,6 +63,7 @@ RSpec.describe Cache do
expect { travel 4.seconds }.to change { Cache.get('123') }.to(nil) expect { travel 4.seconds }.to change { Cache.get('123') }.to(nil)
end end
end end
end
describe '.delete' do describe '.delete' do
it 'deletes stored values' do it 'deletes stored values' do