2016-12-15 93 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

非常感謝!完美地工作,我用它來解釋真正的問題! –