diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-06-25 19:26:29 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-06-25 19:30:05 -0300 |
commit | cad8bb187deabcb4fc8ee9b58442845658205ee5 (patch) | |
tree | 984a5bba58067d85f06746f2606de5769cd476d1 | |
parent | 87b468c254e3e1e3b6b1d86e003f1f90a39935a2 (diff) | |
download | gitlab-ce-cad8bb187deabcb4fc8ee9b58442845658205ee5.tar.gz |
Parse the cached value when the it is false
-rw-r--r-- | lib/gitlab/json_cache.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/json_cache_spec.rb | 35 |
2 files changed, 35 insertions, 2 deletions
diff --git a/lib/gitlab/json_cache.rb b/lib/gitlab/json_cache.rb index d01183d7845..84c6817f3c7 100644 --- a/lib/gitlab/json_cache.rb +++ b/lib/gitlab/json_cache.rb @@ -34,7 +34,7 @@ module Gitlab def read(key, klass = nil) value = backend.read(cache_key(key)) - value = parse_value(value, klass) if value + value = parse_value(value, klass) unless value.nil? value end diff --git a/spec/lib/gitlab/json_cache_spec.rb b/spec/lib/gitlab/json_cache_spec.rb index 59160741c45..39cdd42088e 100644 --- a/spec/lib/gitlab/json_cache_spec.rb +++ b/spec/lib/gitlab/json_cache_spec.rb @@ -129,19 +129,52 @@ describe Gitlab::JsonCache do .with(expanded_key) .and_return(nil) + expect(ActiveSupport::JSON).not_to receive(:decode) expect(cache.read(key)).to be_nil end - context 'when the cached value is a boolean' do + context 'when the cached value is true' do it 'parses the cached value' do allow(backend).to receive(:read) .with(expanded_key) .and_return(true) + expect(ActiveSupport::JSON).to receive(:decode).with("true").and_call_original expect(cache.read(key, BroadcastMessage)).to eq(true) end end + context 'when the cached value is false' do + it 'parses the cached value' do + allow(backend).to receive(:read) + .with(expanded_key) + .and_return(false) + + expect(ActiveSupport::JSON).to receive(:decode).with("false").and_call_original + expect(cache.read(key, BroadcastMessage)).to eq(false) + end + end + + context 'when the cached value is a JSON true value' do + it 'parses the cached value' do + allow(backend).to receive(:read) + .with(expanded_key) + .and_return("true") + + expect(cache.read(key, BroadcastMessage)).to eq(true) + end + end + + context 'when the cached value is a JSON false value' do + it 'parses the cached value' do + allow(backend).to receive(:read) + .with(expanded_key) + .and_return("false") + + expect(cache.read(key, BroadcastMessage)).to eq(false) + end + end + context 'when the cached value is a hash' do it 'parses the cached value' do allow(backend).to receive(:read) |