test/stripe/api_resource_test.rb in stripe-1.40.0 vs test/stripe/api_resource_test.rb in stripe-1.41.0
- old
+ new
@@ -443,11 +443,11 @@
Stripe.expects(:execute_request).with do |opts|
opts[:method] == :get &&
opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
opts[:headers][:stripe_account] == 'acct_abc'
end.once.returns(make_response(make_customer))
- c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
+ Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
end
should "passing in a stripe_account header should pass it through on save" do
Stripe.expects(:execute_request).with do |opts|
opts[:method] == :get &&
@@ -691,9 +691,22 @@
err = Errno::ECONNREFUSED.new
@mock.expects(:post).times(2).with('https://api.stripe.com/v1/charges', nil, 'amount=50¤cy=usd').raises(err).then.returns(response)
result = Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
assert_equal "myid", result.id
+ end
+
+ # We retry the request if we receive SSL errors, since these can be caused
+ # by transient network issues, in addition to compatibility issues between
+ # the client and server.
+ should 'retry failed network requests if they fail with OpenSSL::SSL::SSLError' do
+ Stripe.expects(:sleep_time).at_least_once.returns(0)
+ @mock.expects(:post).times(3).with('https://api.stripe.com/v1/charges', nil, 'amount=50¤cy=usd').raises(OpenSSL::SSL::SSLError.new('message'))
+
+ err = assert_raises Stripe::APIConnectionError do
+ Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
+ end
+ assert_match(/Request was retried 2 times/, err.message)
end
should 'not retry a SSLCertificateNotVerified error' do
@mock.expects(:post).times(1).with('https://api.stripe.com/v1/charges', nil, 'amount=50¤cy=usd').raises(RestClient::SSLCertificateNotVerified.new('message'))