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:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-03-07 03:12:29 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-03-07 03:12:29 +0300
commit5171e2f3d4fdc681a58e11f9615afa968324a278 (patch)
tree256a12ed77a7a6aabff58bc267a70d476cc4dfa7 /spec/lib/gitlab/repository_cache_spec.rb
parent35f6efaee05835b75e605e1f269e57a8d6daf3fa (diff)
Refactor RepositoryCache to make it usable in other classes
Diffstat (limited to 'spec/lib/gitlab/repository_cache_spec.rb')
-rw-r--r--spec/lib/gitlab/repository_cache_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/gitlab/repository_cache_spec.rb b/spec/lib/gitlab/repository_cache_spec.rb
new file mode 100644
index 00000000000..f4789421663
--- /dev/null
+++ b/spec/lib/gitlab/repository_cache_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Gitlab::RepositoryCache do
+ let(:backend) { double('backend').as_null_object }
+ let(:project) { create(:project) }
+ let(:repository) { project.repository }
+ let(:namespace) { "#{repository.full_path}:#{project.id}" }
+ let(:cache) { described_class.new(repository, backend) }
+
+ describe '#cache_key' do
+ it 'includes the namespace' do
+ expect(cache.cache_key(:foo)).to eq "foo:#{namespace}"
+ end
+ end
+
+ describe '#expire' do
+ it 'expires the given key from the cache' do
+ cache.expire(:foo)
+ expect(backend).to have_received(:delete).with("foo:#{namespace}")
+ end
+ end
+
+ describe '#fetch' do
+ it 'fetches the given key from the cache' do
+ cache.fetch(:bar)
+ expect(backend).to have_received(:fetch).with("bar:#{namespace}")
+ end
+
+ it 'accepts a block' do
+ p = -> {}
+
+ cache.fetch(:baz, &p)
+ expect(backend).to have_received(:fetch).with("baz:#{namespace}", &p)
+ end
+ end
+end