mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-06-17 00:00:50 -04:00
Fix URL building for when the base URL already has query parameters, and add test.
This commit is contained in:
parent
a1ab276487
commit
7ddf3ea42b
@ -124,7 +124,7 @@ module Stripe
|
|||||||
# Make params into GET parameters
|
# Make params into GET parameters
|
||||||
if params && params.count > 0
|
if params && params.count > 0
|
||||||
query_string = Util.flatten_params(params).collect{|key, value| "#{key}=#{Util.url_encode(value)}"}.join('&')
|
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
|
end
|
||||||
payload = nil
|
payload = nil
|
||||||
else
|
else
|
||||||
|
@ -189,6 +189,14 @@ def test_paid_invoice
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_invoice_array
|
||||||
|
{
|
||||||
|
:data => [test_invoice],
|
||||||
|
:object => 'list',
|
||||||
|
:url => '/v1/invoices/upcoming?customer=test_customer'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_invalid_api_key_error
|
def test_invalid_api_key_error
|
||||||
{
|
{
|
||||||
"error" => {
|
"error" => {
|
||||||
|
@ -120,6 +120,15 @@ class TestStripeRuby < Test::Unit::TestCase
|
|||||||
assert charges.kind_of? Array
|
assert charges.kind_of? Array
|
||||||
end
|
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
|
should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
|
||||||
response = test_response(test_missing_id_error, 400)
|
response = test_response(test_missing_id_error, 400)
|
||||||
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user