2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::ImportExport::HashUtil do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:stringified_array) { [{ 'test' => 1 }] }
|
|
|
|
let(:stringified_array_with_date) { [{ 'test_date' => '2016-04-06 06:17:44 +0200' }] }
|
|
|
|
|
|
|
|
describe '.deep_symbolize_array!' do
|
|
|
|
it 'symbolizes keys' do
|
|
|
|
expect { described_class.deep_symbolize_array!(stringified_array) }.to change {
|
2020-03-13 15:44:24 +05:30
|
|
|
stringified_array.first.each_key.first
|
2017-08-17 22:00:37 +05:30
|
|
|
}.from('test').to(:test)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.deep_symbolize_array_with_date!' do
|
|
|
|
it 'symbolizes keys' do
|
|
|
|
expect { described_class.deep_symbolize_array_with_date!(stringified_array_with_date) }.to change {
|
2020-03-13 15:44:24 +05:30
|
|
|
stringified_array_with_date.first.each_key.first
|
2017-08-17 22:00:37 +05:30
|
|
|
}.from('test_date').to(:test_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'transforms date strings into Time objects' do
|
|
|
|
expect { described_class.deep_symbolize_array_with_date!(stringified_array_with_date) }.to change {
|
2020-03-13 15:44:24 +05:30
|
|
|
stringified_array_with_date.first.each_value.first.class
|
2017-08-17 22:00:37 +05:30
|
|
|
}.from(String).to(ActiveSupport::TimeWithZone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|