如何修复"忽略重复的密钥"在消息中

时间:2016-12-15 17:36:56

标签: ruby soap savon

我使用Savon测试一些WSDL SOAP服务,并且一些服务需要消息中的重复键/值。例如"产品"产品内部的价值"阵列:

@client.call(
  :create_template, message: {
    :item => [{
      'promotion_id'      => "1",
      'code_is_unique'    => "0",
      'name'          => "qasusc1",
      'description'     => "Automation suscription",
      'basecode'        => "qasusc1",
      'total_redemptions'   => "30",
      'valid_from'      => "2016-12-12 00:00:00",
      'valid_to'        => "2017-12-12 00:00:00",
      'duration_quantity'   => "1",
      'duration_unit'     => "M",
      'operator_code'     => "NAME",
      'initial_quantity'    => "30",
      :products => [{
        :product => [{
          'id'          => "3",
          'off_percentage'    => "100",
          'quantity'        => "1"
        }],
        :product => [{
          'id'          => "4",
          'off_percentage'    => "100",
          'quantity'        => "1"
        }]
      }],
      :lists => [{
        'list'          => "1"
      }],
      :promotion_rules => [{
        :promotion_rule => [{
          'code'    => "HAS_PAYMENT_GATEWAY_RULE",
          'value'   => "1"
        }]
      }]
    }]
  }
)

但我收到以下错误:

tests/suites_soap/test_soap.rb:840: warning: duplicated key at line 22 ignored: :product

1 个答案:

答案 0 :(得分:2)

您无法复制哈希值内的键。

{ a: 1, a: 2 } 总是等于{a: 2}

根据this issue,您应该使用数组来表示Ruby形式的重复键:

:products => [{
  :product => [
    {
      'id'                    => "3",
      'off_percentage'        => "100",
      'quantity'              => "1"
    },
    {
      'id'                    => "4",
      'off_percentage'        => "100",
      'quantity'              => "1"
    }
  ]
相关问题