diff options
author | Michael Kozono <mkozono@gmail.com> | 2018-09-20 21:49:58 +0300 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2018-09-24 22:11:26 +0300 |
commit | 45cf64c827270d66a88d483bb3f9043a90301255 (patch) | |
tree | b71d4455decb58e5d429b8e5299896a70fc7c20a /spec/lib/gitlab/null_request_store_spec.rb | |
parent | 00bb83f7fc6d52583d56fb0f0ea4c9d951535b52 (diff) |
Use a null object with RequestStore
Makes it easier and safer to use RequestStore because you don't need to
check `RequestStore.active?` before using it. You just have to use
`Gitlab::SafeRequestStore` instead.
Diffstat (limited to 'spec/lib/gitlab/null_request_store_spec.rb')
-rw-r--r-- | spec/lib/gitlab/null_request_store_spec.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/lib/gitlab/null_request_store_spec.rb b/spec/lib/gitlab/null_request_store_spec.rb new file mode 100644 index 00000000000..c023dac53ad --- /dev/null +++ b/spec/lib/gitlab/null_request_store_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require 'spec_helper' + +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') + 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 |