From 819f8a03fffe460f4d957712c4aad704541d0ac9 Mon Sep 17 00:00:00 2001 From: Brandur Date: Mon, 16 Oct 2017 11:51:37 -0700 Subject: [PATCH] Don't persist `idempotency_key` option between API requests Excludes `idempotency_key` from opts to persist between API requests. Obviously the same idempotency key is not something that we ever want to use again. Fixes #598. --- .rubocop_todo.yml | 2 +- lib/stripe/util.rb | 8 ++++++-- test/stripe/util_test.rb | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a0788feab..ceb15eb3d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -38,7 +38,7 @@ Metrics/MethodLength: # Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 298 + Max: 302 # Offense count: 5 # Configuration parameters: CountKeywordArgs. diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index d8c2a5f26..3a6e20d6b 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -12,11 +12,15 @@ module Util # Options that should be copyable from one StripeObject to another # including options that may be internal. - OPTS_COPYABLE = (OPTS_USER_SPECIFIED + Set[:api_base]).freeze + OPTS_COPYABLE = ( + OPTS_USER_SPECIFIED + Set[:api_base] + ).freeze # Options that should be persisted between API requests. This includes # client, which is an object containing an HTTP client to reuse. - OPTS_KEYS_TO_PERSIST = (OPTS_USER_SPECIFIED + Set[:client]).freeze + OPTS_PERSISTABLE = ( + OPTS_USER_SPECIFIED + Set[:client] - Set[:idempotency_key] + ).freeze def self.objects_to_ids(h) case h diff --git a/test/stripe/util_test.rb b/test/stripe/util_test.rb index dbcd721da..90b115ab6 100644 --- a/test/stripe/util_test.rb +++ b/test/stripe/util_test.rb @@ -2,6 +2,22 @@ module Stripe class UtilTest < Test::Unit::TestCase + context "OPTS_COPYABLE" do + should "include :apibase" do + assert_include Stripe::Util::OPTS_COPYABLE, :api_base + end + end + + context "OPTS_PERSISTABLE" do + should "include :client" do + assert_include Stripe::Util::OPTS_PERSISTABLE, :client + end + + should "not include :idempotency_key" do + refute_includes Stripe::Util::OPTS_PERSISTABLE, :idempotency_key + end + end + should "#encode_parameters should prepare parameters for an HTTP request" do params = { a: 3,