Welcome to mirror list, hosted at ThFree Co, Russian Federation.

repository_cache_spec.rb « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af399f3a7319795710c5052736f1413f2c36baa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'rspec'
require_relative '../../lib/repository_cache'

describe RepositoryCache do
  let(:backend) { double('backend').as_null_object }
  let(:cache) { RepositoryCache.new('example', backend) }

  describe '#cache_key' do
    it 'includes the namespace' do
      expect(cache.cache_key(:foo)).to eq 'foo:example'
    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:example')
    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:example')
    end

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

      cache.fetch(:baz, &p)
      expect(backend).to have_received(:fetch).with('baz:example', &p)
    end
  end
end