2016-07-24 13:39:28 -04:00
|
|
|
require 'spec_helper'
|
2015-01-28 23:08:28 -05:00
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe RepositoryCache do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2015-01-28 23:08:28 -05:00
|
|
|
let(:backend) { double('backend').as_null_object }
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:cache) { described_class.new('example', project.id, backend) }
|
2015-01-28 23:08:28 -05:00
|
|
|
|
|
|
|
describe '#cache_key' do
|
|
|
|
it 'includes the namespace' do
|
2016-07-24 13:39:28 -04:00
|
|
|
expect(cache.cache_key(:foo)).to eq "foo:example:#{project.id}"
|
2015-01-28 23:08:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#expire' do
|
|
|
|
it 'expires the given key from the cache' do
|
|
|
|
cache.expire(:foo)
|
2016-07-24 13:39:28 -04:00
|
|
|
expect(backend).to have_received(:delete).with("foo:example:#{project.id}")
|
2015-01-28 23:08:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#fetch' do
|
|
|
|
it 'fetches the given key from the cache' do
|
|
|
|
cache.fetch(:bar)
|
2016-07-24 13:39:28 -04:00
|
|
|
expect(backend).to have_received(:fetch).with("bar:example:#{project.id}")
|
2015-01-28 23:08:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts a block' do
|
|
|
|
p = -> {}
|
|
|
|
|
|
|
|
cache.fetch(:baz, &p)
|
2016-07-24 13:39:28 -04:00
|
|
|
expect(backend).to have_received(:fetch).with("baz:example:#{project.id}", &p)
|
2015-01-28 23:08:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|