test/stripe/api_resource_test.rb in stripe-1.50.1 vs test/stripe/api_resource_test.rb in stripe-1.51.0
- old
+ new
@@ -172,11 +172,11 @@
context "when specifying per-object credentials" do
context "with no global API key set" do
should "use the per-object credential when creating" do
Stripe.expects(:execute_request).with do |opts|
- opts[:headers][:authorization] == 'Bearer sk_test_local'
+ opts[:headers]['Authorization'] == 'Bearer sk_test_local'
end.returns(make_response(make_charge))
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
'sk_test_local')
end
@@ -191,25 +191,25 @@
Stripe.api_key = nil
end
should "use the per-object credential when creating" do
Stripe.expects(:execute_request).with do |opts|
- opts[:headers][:authorization] == 'Bearer local'
+ opts[:headers]['Authorization'] == 'Bearer local'
end.returns(make_response(make_charge))
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
'local')
end
should "use the per-object credential when retrieving and making other calls" do
Stripe.expects(:execute_request).with do |opts|
opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge" &&
- opts[:headers][:authorization] == 'Bearer local'
+ opts[:headers]['Authorization'] == 'Bearer local'
end.returns(make_response(make_charge))
Stripe.expects(:execute_request).with do |opts|
opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge/refunds" &&
- opts[:headers][:authorization] == 'Bearer local'
+ opts[:headers]['Authorization'] == 'Bearer local'
end.returns(make_response(make_refund))
ch = Stripe::Charge.retrieve('ch_test_charge', 'local')
ch.refunds.create
end
@@ -403,11 +403,11 @@
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'
+ 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
@@ -723,26 +723,32 @@
end
should 'ensure there is always an idempotency_key on POST requests' do
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
Stripe.expects(:execute_request).with do |opts|
- opts[:headers][:idempotency_key] == "random_key"
+ opts[:headers]['Idempotency-Key'] == "random_key"
end.returns(make_response({"id" => "myid"}))
Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
end
should 'ensure there is always an idempotency_key on DELETE requests' do
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
Stripe.expects(:execute_request).with do |opts|
- opts[:headers][:idempotency_key] == "random_key"
+ opts[:headers]['Idempotency-Key'] == "random_key"
end.returns(make_response({"id" => "myid"}))
c = Stripe::Customer.construct_from(make_customer)
c.delete
end
should 'not override a provided idempotency_key' do
+ # Note that this expectation looks like `:idempotency_key` instead of
+ # the header `Idempotency-Key` because it's user provided as seen
+ # below. The ones injected by the library itself look like headers
+ # (`Idempotency-Key`), but rest-client does allow this symbol
+ # formatting and will properly override the system generated one as
+ # expected.
Stripe.expects(:execute_request).with do |opts|
opts[:headers][:idempotency_key] == "provided_key"
end.returns(make_response({"id" => "myid"}))
Stripe::Charge.create({:amount => 50, :currency => 'usd', :card => { :number => nil }}, {:idempotency_key => 'provided_key'})