debian-mirror-gitlab/spec/lib/repository_cache_spec.rb

35 lines
927 B
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
2015-04-26 12:48:37 +05:30
2015-12-23 02:04:40 +05:30
describe RepositoryCache, lib: true do
2016-08-24 12:49:21 +05:30
let(:project) { create(:project) }
2015-04-26 12:48:37 +05:30
let(:backend) { double('backend').as_null_object }
2016-08-24 12:49:21 +05:30
let(:cache) { RepositoryCache.new('example', project.id, backend) }
2015-04-26 12:48:37 +05:30
describe '#cache_key' do
it 'includes the namespace' do
2016-08-24 12:49:21 +05:30
expect(cache.cache_key(:foo)).to eq "foo:example:#{project.id}"
2015-04-26 12:48:37 +05:30
end
end
describe '#expire' do
it 'expires the given key from the cache' do
cache.expire(:foo)
2016-08-24 12:49:21 +05:30
expect(backend).to have_received(:delete).with("foo:example:#{project.id}")
2015-04-26 12:48:37 +05:30
end
end
describe '#fetch' do
it 'fetches the given key from the cache' do
cache.fetch(:bar)
2016-08-24 12:49:21 +05:30
expect(backend).to have_received(:fetch).with("bar:example:#{project.id}")
2015-04-26 12:48:37 +05:30
end
it 'accepts a block' do
p = -> {}
cache.fetch(:baz, &p)
2016-08-24 12:49:21 +05:30
expect(backend).to have_received(:fetch).with("baz:example:#{project.id}", &p)
2015-04-26 12:48:37 +05:30
end
end
end