summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/utils/safe_inline_hash_spec.rb
blob: 617845332bc008c8f5d5b928582ae8ef861a607e (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
31
32
33
34
35
# frozen_string_literal: true

require 'fast_spec_helper'

describe Gitlab::Utils::SafeInlineHash do
  describe '.merge_keys!' do
    let(:source) { { 'foo' => { 'bar' => 'baz' } } }
    let(:validator) { instance_double(Gitlab::Utils::DeepSize, valid?: valid) }

    subject { described_class.merge_keys!(source, prefix: 'safe', connector: '::') }

    before do
      allow(Gitlab::Utils::DeepSize)
        .to receive(:new)
        .with(source)
        .and_return(validator)
    end

    context 'when hash is too big' do
      let(:valid) { false }

      it 'raises an exception' do
        expect { subject }.to raise_error ArgumentError, 'The Hash is too big'
      end
    end

    context 'when hash has an acceptaable size' do
      let(:valid) { true }

      it 'returns a result of InlineHash' do
        is_expected.to eq('safe::foo::bar' => 'baz')
      end
    end
  end
end