2016-12-15 94 views
0

我正在使用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 
+0

欢迎堆栈溢出。请阅读“[mcve]”。我们需要查看演示问题的最小代码和输入数据。请添加将运行的代码,并将输入减少到可能继续导致消息的最小输入。这可以帮助我们,因为我们不必编写测试工具或减少数据,这会减慢答案。 –

回答

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" 
    } 
    ] 
+0

非常感谢!完美地工作,我用它来解释真正的问题! –