Sha256: 17dc83c4933472385a4b908138f3fd62bd2e1a0898e1eb32e817dcfe4f95b4c7

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

require "celsius/hash"

describe Celsius::Hash do
  describe ".deep_find_key" do
    let(:hash) do
      {
        query: {
          bool: [
            {
              query_string: {
                query: "a"
              }
            },
            {
              query_string: {
                query: "b"
              }
            },
            {
              match: {
                some_field: "some_value"
              }
            }
          ]
        },
        facets: {
          creator: {
            terms: {
              field: "facet_creator"
            }
          },
          lang: {
            terms: {
              field: "facet_lang",
            }
          }
        }
      }
    end

    it "returns values matching the given key" do
      expected_result = [
        hash[:query][:bool][0][:query_string],
        hash[:query][:bool][1][:query_string],
      ]

      expect(described_class.deep_find_key(hash, :query_string)).to eq(expected_result)
    end

    context "if given an array of keys" do
      it "tries to find each element based on the former elements result" do
        expected_result = [
          hash[:facets][:creator]
        ]

        expect(described_class.deep_find_key(hash, [:facets, :creator])).to eq(expected_result)
      end
    end
  end

  describe ".smart_store" do
    it "stores a value with the given key" do
      expect(described_class.smart_store({}, :key, "value")).to eq({key: "value"})
    end

    context "if the key allready exists" do
      it "converts the value to an array and pushes the value to it" do
        expect(described_class.smart_store({key: "foo"}, :key, "bar")).to eq({key: ["foo", "bar"]})
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
celsius-0.4.1 spec/celsius/hash_spec.rb