Check that responses are set on API resources

This commit is contained in:
Brandur 2017-01-13 14:37:08 -08:00
parent b365189ae9
commit 1412479bf6

View File

@ -167,6 +167,17 @@ module Stripe
assert_equal 'Invalid response object from API: "{\"error\":\"foo\"}" (HTTP response code was 500)', e.message
end
should "set response on error" do
response = make_response('{"error": { "message": "foo"}}', 500)
@mock.expects(:post).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
e = assert_raises Stripe::APIError do
Stripe::Charge.create
end
assert_equal 500, e.response.http_status
end
should "have default open and read timeouts" do
assert_equal Stripe.open_timeout, 30
assert_equal Stripe.read_timeout, 80
@ -366,6 +377,12 @@ module Stripe
c.refresh
end
should "set response on success" do
@mock.expects(:post).once.returns(make_response(make_charge, 200))
charge = Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
assert_equal 200, charge.response.http_status
end
should "using array accessors should be the same as the method interface" do
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
to_return(body: JSON.generate(make_customer))