Skip to content

Commit

Permalink
Don't persist idempotency_key option between API requests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brandur committed Oct 16, 2017
1 parent f628a1e commit 819f8a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Metrics/MethodLength:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 298
Max: 302

# Offense count: 5
# Configuration parameters: CountKeywordArgs.
Expand Down
8 changes: 6 additions & 2 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/stripe/util_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 819f8a0

Please sign in to comment.