Parse the cached value when the it is false

parent 87b468c2
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
def read(key, klass = nil) def read(key, klass = nil)
value = backend.read(cache_key(key)) value = backend.read(cache_key(key))
value = parse_value(value, klass) if value value = parse_value(value, klass) unless value.nil?
value value
end end
......
...@@ -129,19 +129,52 @@ describe Gitlab::JsonCache do ...@@ -129,19 +129,52 @@ describe Gitlab::JsonCache do
.with(expanded_key) .with(expanded_key)
.and_return(nil) .and_return(nil)
expect(ActiveSupport::JSON).not_to receive(:decode)
expect(cache.read(key)).to be_nil expect(cache.read(key)).to be_nil
end end
context 'when the cached value is a boolean' do context 'when the cached value is true' do
it 'parses the cached value' do it 'parses the cached value' do
allow(backend).to receive(:read) allow(backend).to receive(:read)
.with(expanded_key) .with(expanded_key)
.and_return(true) .and_return(true)
expect(ActiveSupport::JSON).to receive(:decode).with("true").and_call_original
expect(cache.read(key, BroadcastMessage)).to eq(true) expect(cache.read(key, BroadcastMessage)).to eq(true)
end end
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 context 'when the cached value is a hash' do
it 'parses the cached value' do it 'parses the cached value' do
allow(backend).to receive(:read) allow(backend).to receive(:read)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment