Check for exact time matches
This commit is contained in:
parent
13f68f55b3
commit
2c29e80a93
1 changed files with 8 additions and 6 deletions
|
@ -79,6 +79,8 @@ describe RedisCacheable do
|
||||||
describe '#cached_attr_time_reader', :clean_gitlab_redis_shared_state do
|
describe '#cached_attr_time_reader', :clean_gitlab_redis_shared_state do
|
||||||
subject { instance.time }
|
subject { instance.time }
|
||||||
|
|
||||||
|
let(:other_time) { Time.zone.parse('May 14 2018') }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
model.cached_attr_time_reader(:time)
|
model.cached_attr_time_reader(:time)
|
||||||
end
|
end
|
||||||
|
@ -88,7 +90,7 @@ describe RedisCacheable do
|
||||||
expect(instance).to receive(:read_attribute).and_call_original
|
expect(instance).to receive(:read_attribute).and_call_original
|
||||||
|
|
||||||
expect(subject).to be_instance_of(ActiveSupport::TimeWithZone)
|
expect(subject).to be_instance_of(ActiveSupport::TimeWithZone)
|
||||||
expect(subject).to be_within(1.minute).of(Time.zone.now)
|
expect(subject).to eq(payload[:time])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -96,19 +98,19 @@ describe RedisCacheable do
|
||||||
it 'reads the cached value' do
|
it 'reads the cached value' do
|
||||||
expect(instance).not_to receive(:read_attribute)
|
expect(instance).not_to receive(:read_attribute)
|
||||||
|
|
||||||
instance.cache_attributes(time: Time.zone.now)
|
instance.cache_attributes(time: other_time)
|
||||||
|
|
||||||
expect(subject).to be_instance_of(ActiveSupport::TimeWithZone)
|
expect(subject).to be_instance_of(ActiveSupport::TimeWithZone)
|
||||||
expect(subject).to be_within(1.minute).of(Time.zone.now)
|
expect(subject).to eq(other_time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'always returns the latest values' do
|
it 'always returns the latest values' do
|
||||||
expect(instance.time).to be_within(1.minute).of(Time.zone.now)
|
expect(instance.time).to eq(payload[:time])
|
||||||
|
|
||||||
instance.cache_attributes(time: 1.hour.ago)
|
instance.cache_attributes(time: other_time)
|
||||||
|
|
||||||
expect(instance.time).to be_within(1.minute).of(1.hour.ago)
|
expect(instance.time).to eq(other_time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue