Commit 5e7833d8 authored by Stan Hu's avatar Stan Hu

Merge branch 'da-fix-json-cache-false-values' into 'master'

Parse the cached value when it is false on Gitlab::JsonCache#read

See merge request gitlab-org/gitlab-ce!30061
parents 4633df7b cad8bb18
......@@ -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
......
......@@ -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)
......
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