Fix URL building for when the base URL already has query parameters, and add test.

This commit is contained in:
Amber Feng 2013-03-11 13:19:28 -07:00
parent a1ab276487
commit 7ddf3ea42b
3 changed files with 18 additions and 1 deletions

View File

@ -124,7 +124,7 @@ module Stripe
# Make params into GET parameters
if params && params.count > 0
query_string = Util.flatten_params(params).collect{|key, value| "#{key}=#{Util.url_encode(value)}"}.join('&')
url += "?#{query_string}"
url += "#{URI.parse(url).query ? '&' : '?'}#{query_string}"
end
payload = nil
else

View File

@ -189,6 +189,14 @@ def test_paid_invoice
})
end
def test_invoice_array
{
:data => [test_invoice],
:object => 'list',
:url => '/v1/invoices/upcoming?customer=test_customer'
}
end
def test_invalid_api_key_error
{
"error" => {

View File

@ -120,6 +120,15 @@ class TestStripeRuby < Test::Unit::TestCase
assert charges.kind_of? Array
end
should "construct URL properly with base query parameters" do
response = test_response(test_invoice_array)
@mock.expects(:get).with("#{Stripe.api_base}/v1/invoices/upcoming?customer=test_customer", nil, nil).returns(response)
invoices = Stripe::Invoice.upcoming(:customer => 'test_customer')
@mock.expects(:get).with("#{Stripe.api_base}/v1/invoices/upcoming?customer=test_customer&paid=true", nil, nil).returns(response)
invoices.all(:paid => true)
end
should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
response = test_response(test_missing_id_error, 400)
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))