Sha256: 280ae9e4c06daed516b2ff8f5c089b6893fe5504bb81a6ea780d06096bcf4d9c

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 KB

Contents

require File.expand_path('../../test_helper', __FILE__)

module Paid
  class ParamsBuilderTest < ::Test::Unit::TestCase

    setup do
      @params = {
        :dog => "dog-value",
        "string" => "str-value"
      }
    end

    context '#clean' do
      setup do
        @built_params = ParamsBuilder.clean(@params)
      end

      should 'convert keys to symbols' do
        assert(@built_params.has_key?(:string))
        assert_equal(@params["string"], @built_params[:string])
      end

      should 'not have any string keys' do
        @built_params.each do |k, v|
          assert(k.is_a?(Symbol))
        end
      end
    end

    context '#merge' do
      setup do
        @to_merge = {
          :string => "other-str-value",
          "cat" => "cat-value"
        }
        @built_params = ParamsBuilder.merge(@params, @to_merge)
      end

      should 'convert keys to symbols' do
        assert(@built_params.has_key?(:cat))
        assert(@built_params.has_key?(:string))
        assert(!@built_params.has_key?("string"))
      end

      should 'merge in all values' do
        assert_equal(@params[:dog], @built_params[:dog])
        assert_equal(@to_merge[:string], @built_params[:string])
        assert_equal(@to_merge["cat"], @built_params[:cat])
      end

      should 'prioritize values in @to_merge' do
        assert_equal(@to_merge[:string], @built_params[:string])
      end
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
paid-1.2.1 test/paid/params_builder_test.rb
paid-1.2.0 test/paid/params_builder_test.rb
paid-1.1.4 test/paid/params_builder_test.rb
paid-1.1.3 test/paid/params_builder_test.rb
paid-1.1.2 test/paid/params_builder_test.rb
paid-1.1.1 test/paid/params_builder_test.rb
paid-1.1.0 test/paid/params_builder_test.rb
paid-1.0.11 test/paid/params_builder_test.rb
paid-1.0.10 test/paid/params_builder_test.rb
paid-1.0.9 test/paid/params_builder_test.rb
paid-1.0.8 test/paid/params_builder_test.rb
paid-1.0.7 test/paid/params_builder_test.rb
paid-1.0.6 test/paid/params_builder_test.rb
paid-1.0.5 test/paid/params_builder_test.rb
paid-1.0.3 test/paid/params_builder_test.rb
paid-1.0.2 test/paid/params_builder_test.rb