Sha256: f426a267b83a3159113f4cf6438a5d8f956343bd0073ab704cb53dce7c601cc8

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true
require 'spec_helper'
require 'bitbucket_rest_api/core_ext/hash'

describe BitBucket::ParameterFilter, '#filter!' do
  let(:hash) {  { a: { b: { c: 1 } } } }
  let(:array) { [{ a: { b: { c: 1 } } }, { d: { e: 2 } }] }

  let(:klass) do
    Class.new do
      include BitBucket::ParameterFilter
    end
  end

  subject(:instance) { klass.new }

  it 'removes unwanted keys from hash' do
    instance.filter!([:a], hash)
    expect(hash.has_deep_key?(:a)).to eq(true)
    expect(hash.has_deep_key?(:b)).to eq(false)
    expect(hash.has_deep_key?(:c)).to eq(false)
  end

  it 'removes unwanted keys from array of hashes' do
    instance.filter!(%i[a d], array)
    expect(array[0].has_deep_key?(:a)).to eq(true)
    expect(array[0].has_deep_key?(:b)).to eq(false)
    expect(array[0].has_deep_key?(:c)).to eq(false)
    expect(array[1].has_deep_key?(:d)).to eq(true)
    expect(array[1].has_deep_key?(:e)).to eq(false)
  end

  it 'recursively filters inputs tree' do
    instance.filter!(%i[a b], hash)
    expect(hash.has_deep_key?(:c)).to eq(false)
  end

  it 'filters inputs tree only on top level' do
    instance.filter!(%i[a b], hash, recursive: false)
    expect(hash.has_deep_key?(:c)).to eq(true)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitbuckets-0.2.0 spec/bitbucket_rest_api/parameter_filter_spec.rb