mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-15 00:00:44 -04:00
Moves away from Committee and towards stripe-mock, an external self-contained executable API stub server based on OpenAPI [1]. The motivation here is that instead of making stripe-ruby a special snowflake, we can use a single well-tested and feature-rich mock implementation to drive every API's test suite. [1] https://github.com/stripe/stripe-mock
69 lines
1.9 KiB
Ruby
69 lines
1.9 KiB
Ruby
require File.expand_path('../../test_helper', __FILE__)
|
|
|
|
module Stripe
|
|
class SourceTest < Test::Unit::TestCase
|
|
should "be retrievable" do
|
|
source = Stripe::Source.retrieve("src_123")
|
|
assert_requested :get, "#{Stripe.api_base}/v1/sources/src_123"
|
|
assert source.kind_of?(Stripe::Source)
|
|
end
|
|
|
|
should "be creatable" do
|
|
source = Stripe::Source.create(
|
|
type: 'card',
|
|
token: "tok_123"
|
|
)
|
|
assert_requested :post, "#{Stripe.api_base}/v1/sources"
|
|
assert source.kind_of?(Stripe::Source)
|
|
end
|
|
|
|
should "be saveable" do
|
|
source = Stripe::Source.retrieve("src_123")
|
|
source.metadata['key'] = 'value'
|
|
source.save
|
|
assert_requested :post, "#{Stripe.api_base}/v1/sources/#{source.id}"
|
|
end
|
|
|
|
should "be updateable" do
|
|
source = Stripe::Source.update("src_123", metadata: {foo: 'bar'})
|
|
assert_requested :post, "#{Stripe.api_base}/v1/sources/src_123"
|
|
assert source.kind_of?(Stripe::Source)
|
|
end
|
|
|
|
context "#delete" do
|
|
should "not be deletable when unattached" do
|
|
source = Stripe::Source.retrieve("src_123")
|
|
|
|
assert_raises NotImplementedError do
|
|
source.delete
|
|
end
|
|
end
|
|
|
|
should "be deletable when attached to a customer" do
|
|
source = Stripe::Source.construct_from({
|
|
customer: "cus_123",
|
|
id: "src_123",
|
|
object: "source"
|
|
})
|
|
source = source.delete
|
|
assert_requested :delete, "#{Stripe.api_base}/v1/customers/cus_123/sources/src_123"
|
|
assert source.kind_of?(Stripe::Source)
|
|
end
|
|
end
|
|
|
|
should 'not be listable' do
|
|
assert_raises NoMethodError do
|
|
Stripe::Source.list
|
|
end
|
|
end
|
|
|
|
context "#verify" do
|
|
should "verify the source" do
|
|
source = Stripe::Source.retrieve("src_123")
|
|
source = source.verify(:values => [1,2])
|
|
assert source.kind_of?(Stripe::Source)
|
|
end
|
|
end
|
|
end
|
|
end
|