stripe-ruby/test/stripe/invoice_test.rb
Brandur 2a9413e155 Move away from rest-client's "symbol header names"
This moves away from rest-client's convention of using symbols as header
names so as to present less obfuscation as to how these are actually
named when they go over the wire.

Because headers can be injected via the bindings' API I was initially
worried that this change might break something, but upon inspection of
rest-client source, I can see now that headers take precedence as
assigned by their insertion order into the header hash, and are
"stringified" in that same loop [1]. This means that even if a user
injects a symbolized header name (`:idempotency_key`), it will still
correctly overwrite the one generated by stripe-ruby despite that using
the string format (`"Idempotency-Key"`).

[1] https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L603,L625
2016-08-25 11:42:44 -07:00

49 lines
1.8 KiB
Ruby

require File.expand_path('../../test_helper', __FILE__)
module Stripe
class InvoiceTest < Test::Unit::TestCase
should "retrieve should retrieve invoices" do
@mock.expects(:get).once.returns(make_response(make_invoice))
i = Stripe::Invoice.retrieve('in_test_invoice')
assert_equal 'in_test_invoice', i.id
end
should "create should create a new invoice" do
@mock.expects(:post).once.returns(make_response(make_invoice))
i = Stripe::Invoice.create
assert_equal "in_test_invoice", i.id
end
should "pay should pay an invoice" do
@mock.expects(:get).once.returns(make_response(make_invoice))
i = Stripe::Invoice.retrieve('in_test_invoice')
@mock.expects(:post).once.with('https://api.stripe.com/v1/invoices/in_test_invoice/pay', nil, '').returns(make_response(make_paid_invoice))
i.pay
assert_equal nil, i.next_payment_attempt
end
should "invoices should be updateable" do
@mock.expects(:post).once.
with("https://api.stripe.com/v1/invoices/test_invoice", nil, "metadata[foo]=bar").
returns(make_response(make_invoice(metadata: {foo: 'bar'})))
i = Stripe::Invoice.update("test_invoice", metadata: {foo: 'bar'})
assert_equal('bar', i.metadata['foo'])
end
should "pay with extra opts should pay an invoice" do
@mock.expects(:get).once.returns(make_response(make_invoice))
i = Stripe::Invoice.retrieve('in_test_invoice', {:api_key => 'foobar'})
Stripe.expects(:execute_request).with do |opts|
opts[:url] == "#{Stripe.api_base}/v1/invoices/in_test_invoice/pay" &&
opts[:method] == :post &&
opts[:headers]['Authorization'] == 'Bearer foobar'
end.returns(make_response(make_paid_invoice))
i.pay
assert_equal nil, i.next_payment_attempt
end
end
end