Sha256: 1f4a7bfad14649f079236c31ed2821e0366c932f1445fdd07dbcacf2a8141039

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

require 'contest'
require 'swirl/helpers'

class ExpanderTest < Test::Unit::TestCase
  include Swirl::Helpers

  test "leaves params as is by default" do
    request = { "foo" => "bar" }

    assert_equal request, Expander.expand(request)
  end

  test "ignores non-String keys" do
    request = { "foo" => "bar", :ignore => "test" }
    expected = { "foo" => "bar" }

    assert_equal expected, Expander.expand(request)
  end

  test "expands Array values to .n key-values" do
    request = { "group" => ["foo", "bar", "baz"] }

    expected = {
      "group.1" => "foo",
      "group.2" => "bar",
      "group.3" => "baz"
    }

    assert_equal expected, Expander.expand(request)
  end

  test "expands keys with # and Array values to .n. key-values" do
    request = { "foo.#.bar" => ["foo", "bar", "baz"] }

    expected = {
      "foo.1.bar" => "foo",
      "foo.2.bar" => "bar",
      "foo.3.bar" => "baz"
    }

    assert_equal expected, Expander.expand(request)
  end

  test "ignores empty Array values" do
    request = { "group" => [] }
    expected = {}

    assert_equal expected, Expander.expand(request)
  end

  test "converts Key of Range to FromKey ToKey" do
    request = { "Port" => 1..3 }
    expected = { "FromPort" => 1, "ToPort" => 3 }

    assert_equal expected, Expander.expand(request)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
swirl-1.7.5 test/expander_test.rb
swirl-1.7.4 test/expander_test.rb
swirl-1.7.3 test/expander_test.rb
swirl-1.7.2 test/expander_test.rb