Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-05-15 22:55:16 +0300
committerMatija Čupić <matteeyah@gmail.com>2018-05-15 22:55:16 +0300
commit6cc3a07dca635aa61d275eb6803cd986f4c9f967 (patch)
tree398079c866fd6ef146273a15f67ffb7c7c0fc577 /spec/models
parent2c29e80a93dffb1a854f4c63171b1a91eddea8d9 (diff)
Dynamically cast value from cache
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/concerns/redis_cacheable_spec.rb42
1 files changed, 4 insertions, 38 deletions
diff --git a/spec/models/concerns/redis_cacheable_spec.rb b/spec/models/concerns/redis_cacheable_spec.rb
index 2e496cfb439..827629c3180 100644
--- a/spec/models/concerns/redis_cacheable_spec.rb
+++ b/spec/models/concerns/redis_cacheable_spec.rb
@@ -6,6 +6,10 @@ describe RedisCacheable do
def read_attribute(attribute)
attributes[attribute]
end
+
+ def cast_value_from_cache(attribute, cached_value)
+ cached_value
+ end
end
end
@@ -75,42 +79,4 @@ describe RedisCacheable do
expect(instance.name).to eq('new_value')
end
end
-
- describe '#cached_attr_time_reader', :clean_gitlab_redis_shared_state do
- subject { instance.time }
-
- let(:other_time) { Time.zone.parse('May 14 2018') }
-
- before do
- model.cached_attr_time_reader(:time)
- end
-
- context 'when there is no cached value' do
- it 'reads the attribute' do
- expect(instance).to receive(:read_attribute).and_call_original
-
- expect(subject).to be_instance_of(ActiveSupport::TimeWithZone)
- expect(subject).to eq(payload[:time])
- end
- end
-
- context 'when there is a cached value' do
- it 'reads the cached value' do
- expect(instance).not_to receive(:read_attribute)
-
- instance.cache_attributes(time: other_time)
-
- expect(subject).to be_instance_of(ActiveSupport::TimeWithZone)
- expect(subject).to eq(other_time)
- end
- end
-
- it 'always returns the latest values' do
- expect(instance.time).to eq(payload[:time])
-
- instance.cache_attributes(time: other_time)
-
- expect(instance.time).to eq(other_time)
- end
- end
end