Sha256: a0338b940468122c123b1833cc5e1ae18b615cdc25ab0889ed5905d1eb7e6b91

Contents?: true

Size: 1.83 KB

Versions: 5

Compression:

Stored size: 1.83 KB

Contents

require 'test_helper'

module Garb
  class FilterParametersTest < MiniTest::Unit::TestCase
    def self.should_define_operators(*operators)
      operators.each do |operator|
        should "create an operator and add to parameters for the #{operator} method" do
          new_operator = stub
          symbol = :foo

          SymbolOperator.expects(:new).with(:bar, operator).returns(new_operator)
          @filter_parameters.filters do
            send(operator.to_sym, :bar, 100)
          end

          parameter = {new_operator => 100}
          assert_equal parameter, @filter_parameters.parameters.last
        end
      end
    end

    context "A FilterParameters" do
      setup do
        @filter_parameters = FilterParameters.new
      end

      should_define_operators :eql, :not_eql, :gt, :gte, :lt, :lte,
        :matches, :does_not_match, :contains, :does_not_contain, :substring, :not_substring

      should "instance eval for filters" do
        blk = lambda {"in a block"}

        @filter_parameters.expects(:instance_eval)
        @filter_parameters.filters(&blk)
      end

      context "when converting parameters hash into query string parameters" do
        should "parameterize hash operators and join elements with AND" do
          @filter_parameters.filters do
            eql(:city, 'New York City')
            eql(:state, 'New York')
          end

          params = ['ga:city%3D%3DNew+York+City', 'ga:state%3D%3DNew+York']
          assert_equal params, @filter_parameters.to_params['filters'].split(';').sort
        end

        should "properly encode operators" do
          @filter_parameters.filters do
            contains(:page_path, 'New York')
          end

          params = {'filters' => 'ga:pagePath%3D~New+York'}
          assert_equal params, @filter_parameters.to_params
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
garb-0.8.3 test/unit/garb/filter_parameters_test.rb
garb-0.8.2 test/unit/garb/filter_parameters_test.rb
garb-0.8.1 test/unit/garb/filter_parameters_test.rb
garb-0.8.0 test/unit/garb/filter_parameters_test.rb
garb-0.7.6 test/unit/garb/filter_parameters_test.rb