summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-02-05 00:33:29 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-02-05 00:33:29 +0100
commit509c1f01cc9541e6eb6a0315a5cf5d76a99b61d9 (patch)
tree42c7f6916e35054489a62c249f34306f02fd7c6f
parent18af7fab9457db742cba89d9a075ed95bc2f6846 (diff)
downloadgitlab-ce-attribute-caching-concern.tar.gz
Add specs for AttributeCacheableattribute-caching-concern
-rw-r--r--app/models/concerns/attribute_cacheable.rb10
-rw-r--r--spec/models/concerns/attribute_cacheable_spec.rb35
2 files changed, 41 insertions, 4 deletions
diff --git a/app/models/concerns/attribute_cacheable.rb b/app/models/concerns/attribute_cacheable.rb
index 34617489ac5..9ddef3c033b 100644
--- a/app/models/concerns/attribute_cacheable.rb
+++ b/app/models/concerns/attribute_cacheable.rb
@@ -11,10 +11,6 @@ module AttributeCacheable
end
end
- def cache_attribute_key(key)
- "#{self.class.name}:attributes:#{self.id}:#{key}"
- end
-
def cached_attribute(key)
Gitlab::Redis::SharedState.with do |redis|
redis.get(cache_attribute_key(key))
@@ -28,4 +24,10 @@ module AttributeCacheable
end
end
end
+
+ private
+
+ def cache_attribute_key(key)
+ "#{self.class.name}:attributes:#{self.id}:#{key}"
+ end
end
diff --git a/spec/models/concerns/attribute_cacheable_spec.rb b/spec/models/concerns/attribute_cacheable_spec.rb
new file mode 100644
index 00000000000..738c3a9ca8c
--- /dev/null
+++ b/spec/models/concerns/attribute_cacheable_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe AttributeCacheable do
+ let(:runner) { create(:ci_runner) }
+
+ describe '#cached_attribute' do
+ let(:key) { 'test_key' }
+
+ subject { runner.cached_attribute(key) }
+
+ it 'gets the cache attribute' do
+ Gitlab::Redis::SharedState.with do |redis|
+ expect(redis).to receive(:get).with(runner.send(:cache_attribute_key, key))
+ end
+
+ subject
+ end
+ end
+
+ describe '#cache_attributes' do
+ let(:values) { { name: 'new_name' } }
+
+ subject { runner.cache_attributes(values) }
+
+ it 'sets the cache attributes' do
+ Gitlab::Redis::SharedState.with do |redis|
+ values.each do |key, value|
+ expect(redis).to receive(:set).with(runner.send(:cache_attribute_key, key), value, anything)
+ end
+ end
+
+ subject
+ end
+ end
+end