2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
describe Serializers::JSON do
|
|
|
|
describe '.dump' do
|
|
|
|
let(:obj) { { key: "value" } }
|
|
|
|
|
|
|
|
subject { described_class.dump(obj) }
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns a hash' do
|
|
|
|
is_expected.to eq(obj)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.load' do
|
|
|
|
let(:data_string) { '{"key":"value","variables":[{"key":"VAR1","value":"VALUE1"}]}' }
|
|
|
|
let(:data_hash) { JSON.parse(data_string) }
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
context 'when loading a hash' do
|
|
|
|
subject { described_class.load(data_hash) }
|
|
|
|
|
|
|
|
it 'decodes a string' do
|
|
|
|
is_expected.to be_a(Hash)
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
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-10-12 21:52:04 +05:30
|
|
|
context 'when loading a nil' do
|
|
|
|
subject { described_class.load(nil) }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|