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

null_request_store_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 66700313c9ae2845795aff9164e65991a6b8223b (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::NullRequestStore do
  let(:null_store) { described_class.new }

  describe '#store' do
    it 'returns an empty hash' do
      expect(null_store.store).to eq({})
    end
  end

  describe '#active?' do
    it 'returns falsey' do
      expect(null_store.active?).to be_falsey
    end
  end

  describe '#read' do
    it 'returns nil' do
      expect(null_store.read('foo')).to be nil
    end
  end

  describe '#[]' do
    it 'returns nil' do
      expect(null_store['foo']).to be nil
    end
  end

  describe '#write' do
    it 'returns the same value' do
      expect(null_store.write('key', 'value')).to eq('value')
    end
  end

  describe '#[]=' do
    it 'returns the same value' do
      expect(null_store['key'] = 'value').to eq('value')
    end
  end

  describe '#exist?' do
    it 'returns falsey' do
      expect(null_store.exist?('foo')).to be_falsey
    end
  end

  describe '#fetch' do
    it 'returns the block result' do
      expect(null_store.fetch('key') { 'block result' }).to eq('block result') # rubocop:disable Style/RedundantFetchBlock
    end
  end

  describe '#delete' do
    context 'when a block is given' do
      it 'yields the key to the block' do
        expect do |b|
          null_store.delete('foo', &b)
        end.to yield_with_args('foo')
      end

      it 'returns the block result' do
        expect(null_store.delete('foo') { |key| 'block result' }).to eq('block result')
      end
    end

    context 'when a block is not given' do
      it 'returns nil' do
        expect(null_store.delete('foo')).to be nil
      end
    end
  end
end