Gitlab::JsonCache#parse_value ensure string

This commit is contained in:
Ash McKenzie 2019-06-20 18:00:44 +10:00
parent adeccba136
commit 03220c00d9
No known key found for this signature in database
GPG Key ID: A1253B4953E8D3E6
2 changed files with 11 additions and 1 deletions

View File

@ -58,7 +58,7 @@ module Gitlab
private
def parse_value(raw, klass)
value = ActiveSupport::JSON.decode(raw)
value = ActiveSupport::JSON.decode(raw.to_s)
case value
when Hash then parse_entry(value, klass)

View File

@ -106,6 +106,16 @@ describe Gitlab::JsonCache do
expect(cache.read(key)).to be_nil
end
context 'when the cached value is a boolean' 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 hash' do
it 'parses the cached value' do
allow(backend).to receive(:read)