mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-12-08 00:01:02 -05:00
Allow options (headers) to be passed into .save
in the same manner as is already possible for .create.
This commit is contained in:
parent
b2db930f6a
commit
db3059a3c0
@ -13,7 +13,11 @@ module Stripe
|
|||||||
# and includes them in the create or update. If +:req_url:+ is included
|
# and includes them in the create or update. If +:req_url:+ is included
|
||||||
# in the list, it overrides the update URL used for the create or
|
# in the list, it overrides the update URL used for the create or
|
||||||
# update.
|
# update.
|
||||||
def save(params={})
|
# * +opts+ - A Hash of additional options (separate from the params /
|
||||||
|
# object values) to be added to the request. E.g. to allow for an
|
||||||
|
# idempotency_key to be passed in the request headers, or for the
|
||||||
|
# api_key to be overwritten. See {APIOperations::Request.request}.
|
||||||
|
def save(params={}, opts={})
|
||||||
# We started unintentionally (sort of) allowing attributes sent to
|
# We started unintentionally (sort of) allowing attributes sent to
|
||||||
# +save+ to override values used during the update. So as not to break
|
# +save+ to override values used during the update. So as not to break
|
||||||
# the API, this makes that official here.
|
# the API, this makes that official here.
|
||||||
@ -28,7 +32,7 @@ module Stripe
|
|||||||
# generated a uri for this object with an identifier baked in
|
# generated a uri for this object with an identifier baked in
|
||||||
values.delete(:id)
|
values.delete(:id)
|
||||||
|
|
||||||
response, opts = request(:post, save_url, values)
|
response, opts = request(:post, save_url, values, opts)
|
||||||
initialize_from(response, opts)
|
initialize_from(response, opts)
|
||||||
|
|
||||||
self
|
self
|
||||||
|
|||||||
@ -387,6 +387,31 @@ module Stripe
|
|||||||
assert_equal false, c.livemode
|
assert_equal false, c.livemode
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "updating should send along the idempotency-key header" do
|
||||||
|
Stripe.expects(:execute_request).with do |opts|
|
||||||
|
opts[:headers][:idempotency_key] == 'bar'
|
||||||
|
end.returns(make_response(make_customer))
|
||||||
|
c = Stripe::Customer.new
|
||||||
|
c.save({}, { :idempotency_key => 'bar' })
|
||||||
|
assert_equal false, c.livemode
|
||||||
|
end
|
||||||
|
|
||||||
|
should "updating should fail if api_key is overwritten with nil" do
|
||||||
|
c = Stripe::Customer.new
|
||||||
|
assert_raises TypeError do
|
||||||
|
c.save({}, { :api_key => nil })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "updating should use the supplied api_key" do
|
||||||
|
Stripe.expects(:execute_request).with do |opts|
|
||||||
|
opts[:headers][:authorization] == 'Bearer sk_test_local'
|
||||||
|
end.returns(make_response(make_customer))
|
||||||
|
c = Stripe::Customer.new
|
||||||
|
c.save({}, { :api_key => 'sk_test_local' })
|
||||||
|
assert_equal false, c.livemode
|
||||||
|
end
|
||||||
|
|
||||||
should "deleting should send no props and result in an object that has no props other deleted" do
|
should "deleting should send no props and result in an object that has no props other deleted" do
|
||||||
@mock.expects(:get).never
|
@mock.expects(:get).never
|
||||||
@mock.expects(:post).never
|
@mock.expects(:post).never
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user