BigW Consortium Gitlab

repository_cache_spec.rb 927 Bytes
Newer Older
1
require 'spec_helper'
2

Douwe Maan committed
3
describe RepositoryCache, lib: true do
4
  let(:project) { create(:project) }
5
  let(:backend) { double('backend').as_null_object }
6
  let(:cache) { RepositoryCache.new('example', project.id, backend) }
7 8 9

  describe '#cache_key' do
    it 'includes the namespace' do
10
      expect(cache.cache_key(:foo)).to eq "foo:example:#{project.id}"
11 12 13 14 15 16
    end
  end

  describe '#expire' do
    it 'expires the given key from the cache' do
      cache.expire(:foo)
17
      expect(backend).to have_received(:delete).with("foo:example:#{project.id}")
18 19 20 21 22 23
    end
  end

  describe '#fetch' do
    it 'fetches the given key from the cache' do
      cache.fetch(:bar)
24
      expect(backend).to have_received(:fetch).with("bar:example:#{project.id}")
25 26 27 28 29 30
    end

    it 'accepts a block' do
      p = -> {}

      cache.fetch(:baz, &p)
31
      expect(backend).to have_received(:fetch).with("baz:example:#{project.id}", &p)
32 33 34
    end
  end
end