I'm using Savon to test some WSDL SOAP services, and some of the services need duplicated keys/values in the message. For example the "product" value inside the "products" array:
@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"
}]
}]
}]
}
)
But I'm getting the following error:
tests/suites_soap/test_soap.rb:840: warning: duplicated key at line 22 ignored: :product
You cannot duplicate a key inside a hash, period.
{ a: 1, a: 2 }
will always be equal to {a: 2}
.
According to this issue, you should use an array to represent duplicated keys in Ruby form:
:products => [{
:product => [
{
'id' => "3",
'off_percentage' => "100",
'quantity' => "1"
},
{
'id' => "4",
'off_percentage' => "100",
'quantity' => "1"
}
]