Sha256: 1a1e9e88b3422209716a1306efb69921efc817aa537e99f3d071871eb6ceba31

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

require "spec_helper"

module CFoundry
  module V2
    describe ModelMagic do
      describe "params_from" do
        describe "query" do
          it "filters by a single key and value" do
            params = ModelMagic.params_from({query: ['key', 'value']})
            expect(params[:q]).to eq("key:value")
          end

          it "filters by a list of values for a key" do
            params = ModelMagic.params_from({query: {key: ['value1', 'value2']}})
            expect(params[:q]).to eq("key IN value1,value2")
          end

          it "filters by complex QueryValue" do
            params = ModelMagic.params_from({query: {key: ModelMagic::QueryValue.new(comparator: '>', value:'value1')}})
            expect(params[:q]).to eq("key>value1")
          end

          it "filters by multiple fields" do
            params = ModelMagic.params_from({query: {key1: ModelMagic::QueryValue.new(comparator: '>=', value:'value1'), key2: 'value2', key3: ['value3a', 'value3b']}})
            expect(params[:q]).to eq("key1>=value1;key2:value2;key3 IN value3a,value3b")
          end

          it "filters by multiple QueryValues" do
            params = ModelMagic.params_from({query: {key: ModelMagic::QueryMultiValue.new({comparator: '>', value: 'value1'},{comparator: '<', value: 'value2'})}})
            expect(params[:q]).to eq("key>value1;key<value2")
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cfoundry-4.7.1.rc1 spec/cfoundry/v2/model_magic_spec.rb
cfoundry-4.7.0 spec/cfoundry/v2/model_magic_spec.rb
cfoundry-4.6.3.rc3 spec/cfoundry/v2/model_magic_spec.rb
cfoundry-4.6.3.rc2 spec/cfoundry/v2/model_magic_spec.rb
cfoundry-4.6.3.rc1 spec/cfoundry/v2/model_magic_spec.rb
cfoundry-4.6.2 spec/cfoundry/v2/model_magic_spec.rb