repository_cache_spec.rb 981 字节
Newer Older
1
require 'spec_helper'
2

3
describe Gitlab::RepositoryCache do
4
  let(:backend) { double('backend').as_null_object }
5 6 7 8
  let(:project) { create(:project) }
  let(:repository) { project.repository }
  let(:namespace) { "#{repository.full_path}:#{project.id}" }
  let(:cache) { described_class.new(repository, backend) }
9 10 11

  describe '#cache_key' do
    it 'includes the namespace' do
12
      expect(cache.cache_key(:foo)).to eq "foo:#{namespace}"
13 14 15 16 17 18
    end
  end

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

  describe '#fetch' do
    it 'fetches the given key from the cache' do
      cache.fetch(:bar)
26
      expect(backend).to have_received(:fetch).with("bar:#{namespace}")
27 28 29 30 31 32
    end

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

      cache.fetch(:baz, &p)
33
      expect(backend).to have_received(:fetch).with("baz:#{namespace}", &p)
34 35 36
    end
  end
end