Get requests with arrays of dictionaries to work

This commit is contained in:
Chase Lambert 2015-06-17 17:26:12 -07:00
parent 8c6dc1a838
commit 801dd99318
2 changed files with 20 additions and 1 deletions

View File

@ -110,7 +110,7 @@ module Stripe
result = []
value.each do |elem|
if elem.is_a?(Hash)
result += flatten_params(elem, calculated_key)
result += flatten_params(elem, "#{calculated_key}[]")
elsif elem.is_a?(Array)
result += flatten_params_array(elem, calculated_key)
else

View File

@ -95,5 +95,24 @@ module Stripe
})
assert c.paid
end
should "properly handle an array or dictionaries" do
@mock.expects(:post).with do |url, api_key, params|
url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
'currency' => ['usd'], 'amount' => ['100'],
'source' => ['btcrcv_test_receiver'],
'level3[][red]' => ['firstred', 'another'],
'level3[][one]' => ['fish'],
}
end.once.returns(make_response(make_charge))
c = Stripe::Charge.create({
:amount => 100,
:source => 'btcrcv_test_receiver',
:currency => "usd",
:level3 => [{:red => 'firstred'}, {:one => 'fish', :red => 'another'}]
})
assert c.paid
end
end
end