2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-02 10:35:15 -04:00
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
describe Serializers::JSON do
|
|
|
|
describe '.dump' do
|
|
|
|
let(:obj) { { key: "value" } }
|
|
|
|
|
|
|
|
subject { described_class.dump(obj) }
|
|
|
|
|
2019-06-13 09:12:28 -04:00
|
|
|
it 'returns a hash' do
|
|
|
|
is_expected.to eq(obj)
|
2018-09-02 10:35:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.load' do
|
|
|
|
let(:data_string) { '{"key":"value","variables":[{"key":"VAR1","value":"VALUE1"}]}' }
|
|
|
|
let(:data_hash) { JSON.parse(data_string) }
|
|
|
|
|
2019-06-13 09:12:28 -04:00
|
|
|
context 'when loading a hash' do
|
|
|
|
subject { described_class.load(data_hash) }
|
|
|
|
|
|
|
|
it 'decodes a string' do
|
|
|
|
is_expected.to be_a(Hash)
|
|
|
|
end
|
|
|
|
|
2018-09-02 10:35:15 -04:00
|
|
|
it 'allows to access with symbols' do
|
|
|
|
expect(subject[:key]).to eq('value')
|
|
|
|
expect(subject[:variables].first[:key]).to eq('VAR1')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows to access with strings' do
|
|
|
|
expect(subject["key"]).to eq('value')
|
|
|
|
expect(subject["variables"].first["key"]).to eq('VAR1')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-13 09:12:28 -04:00
|
|
|
context 'when loading a nil' do
|
|
|
|
subject { described_class.load(nil) }
|
2018-09-02 10:35:15 -04:00
|
|
|
|
2019-06-13 09:12:28 -04:00
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
2018-09-02 10:35:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|