Welcome to mirror list, hosted at ThFree Co, Russian Federation.

hash_util_spec.rb « import_export « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 467342e6e964f6690c127d81e0630ea11e644b6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::ImportExport::HashUtil do
  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 {
        stringified_array.first.each_key.first
      }.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 {
        stringified_array_with_date.first.each_key.first
      }.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 {
        stringified_array_with_date.first.each_value.first.class
      }.from(String).to(ActiveSupport::TimeWithZone)
    end
  end
end