stripe 1.58.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.travis.yml +1 -2
  4. data/Gemfile +11 -12
  5. data/History.txt +8 -0
  6. data/README.md +44 -31
  7. data/Rakefile +1 -1
  8. data/VERSION +1 -1
  9. data/lib/stripe.rb +4 -344
  10. data/lib/stripe/account.rb +4 -4
  11. data/lib/stripe/api_operations/create.rb +2 -2
  12. data/lib/stripe/api_operations/delete.rb +2 -2
  13. data/lib/stripe/api_operations/list.rb +2 -2
  14. data/lib/stripe/api_operations/request.rb +9 -3
  15. data/lib/stripe/api_operations/save.rb +4 -6
  16. data/lib/stripe/api_resource.rb +2 -2
  17. data/lib/stripe/bank_account.rb +2 -2
  18. data/lib/stripe/bitcoin_receiver.rb +1 -1
  19. data/lib/stripe/charge.rb +12 -12
  20. data/lib/stripe/customer.rb +6 -6
  21. data/lib/stripe/dispute.rb +2 -3
  22. data/lib/stripe/errors.rb +20 -10
  23. data/lib/stripe/invoice.rb +4 -4
  24. data/lib/stripe/list_object.rb +2 -2
  25. data/lib/stripe/order.rb +4 -4
  26. data/lib/stripe/reversal.rb +1 -1
  27. data/lib/stripe/source.rb +2 -2
  28. data/lib/stripe/stripe_client.rb +396 -0
  29. data/lib/stripe/stripe_response.rb +48 -0
  30. data/lib/stripe/transfer.rb +2 -2
  31. data/lib/stripe/util.rb +6 -6
  32. data/lib/stripe/version.rb +1 -1
  33. data/spec/fixtures.json +0 -0
  34. data/spec/fixtures.yaml +0 -0
  35. data/spec/spec.json +0 -0
  36. data/spec/spec.yaml +0 -0
  37. data/stripe.gemspec +1 -1
  38. data/test/api_fixtures.rb +29 -0
  39. data/test/api_stub_helpers.rb +125 -0
  40. data/test/stripe/account_test.rb +153 -247
  41. data/test/stripe/alipay_account_test.rb +10 -2
  42. data/test/stripe/api_operations_test.rb +3 -3
  43. data/test/stripe/api_resource_test.rb +139 -499
  44. data/test/stripe/apple_pay_domain_test.rb +22 -23
  45. data/test/stripe/application_fee_refund_test.rb +22 -31
  46. data/test/stripe/application_fee_test.rb +6 -17
  47. data/test/stripe/balance_test.rb +3 -3
  48. data/test/stripe/bank_account_test.rb +31 -11
  49. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  50. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  51. data/test/stripe/charge_test.rb +39 -126
  52. data/test/stripe/country_spec_test.rb +7 -30
  53. data/test/stripe/coupon_test.rb +33 -17
  54. data/test/stripe/customer_card_test.rb +25 -46
  55. data/test/stripe/customer_test.rb +86 -81
  56. data/test/stripe/dispute_test.rb +27 -38
  57. data/test/stripe/errors_test.rb +2 -2
  58. data/test/stripe/file_upload_test.rb +32 -24
  59. data/test/stripe/invoice_item_test.rb +46 -10
  60. data/test/stripe/invoice_test.rb +48 -48
  61. data/test/stripe/list_object_test.rb +22 -31
  62. data/test/stripe/order_return_test.rb +11 -15
  63. data/test/stripe/order_test.rb +38 -51
  64. data/test/stripe/plan_test.rb +39 -18
  65. data/test/stripe/product_test.rb +29 -33
  66. data/test/stripe/recipient_card_test.rb +23 -40
  67. data/test/stripe/recipient_test.rb +39 -10
  68. data/test/stripe/refund_test.rb +20 -45
  69. data/test/stripe/reversal_test.rb +27 -31
  70. data/test/stripe/sku_test.rb +36 -19
  71. data/test/stripe/source_test.rb +26 -66
  72. data/test/stripe/stripe_client_test.rb +428 -0
  73. data/test/stripe/stripe_object_test.rb +6 -2
  74. data/test/stripe/stripe_response_test.rb +46 -0
  75. data/test/stripe/subscription_item_test.rb +37 -59
  76. data/test/stripe/subscription_test.rb +40 -176
  77. data/test/stripe/three_d_secure_test.rb +13 -12
  78. data/test/stripe/transfer_test.rb +36 -19
  79. data/test/stripe_test.rb +3 -36
  80. data/test/test_data.rb +5 -931
  81. data/test/test_helper.rb +21 -25
  82. metadata +22 -17
  83. data/test/stripe/charge_refund_test.rb +0 -67
  84. data/test/stripe/metadata_test.rb +0 -129
@@ -2,30 +2,51 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class PlanTest < Test::Unit::TestCase
5
- should "plans should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_plan_array))
5
+ FIXTURE = API_FIXTURES.fetch(:plan)
6
+
7
+ should "be listable" do
7
8
  plans = Stripe::Plan.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/plans"
8
10
  assert plans.data.kind_of?(Array)
9
- plans.each do |plan|
10
- assert plan.kind_of?(Stripe::Plan)
11
- end
11
+ assert plans.data[0].kind_of?(Stripe::Plan)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ plan = Stripe::Plan.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
17
+ assert plan.kind_of?(Stripe::Plan)
18
+ end
19
+
20
+ should "be creatable" do
21
+ plan = Stripe::Plan.create(
22
+ amount: 5000,
23
+ interval: "month",
24
+ name: "Sapphire elite",
25
+ currency: "usd",
26
+ id: "sapphire-elite"
27
+ )
28
+ assert_requested :post, "#{Stripe.api_base}/v1/plans"
29
+ assert plan.kind_of?(Stripe::Plan)
30
+ end
31
+
32
+ should "be saveable" do
33
+ plan = Stripe::Plan.retrieve(FIXTURE[:id])
34
+ plan.metadata['key'] = 'value'
35
+ plan.save
36
+ assert_requested :post, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
12
37
  end
13
38
 
14
- should "plans should be saveable" do
15
- @mock.expects(:get).once.returns(make_response(make_plan))
16
- @mock.expects(:post).once.returns(make_response(make_plan))
17
- p = Stripe::Plan.new("test_plan")
18
- p.refresh
19
- p.metadata['foo'] = 'bar'
20
- p.save
39
+ should "be updateable" do
40
+ plan = Stripe::Plan.update(FIXTURE[:id], metadata: {foo: 'bar'})
41
+ assert_requested :post, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
42
+ assert plan.kind_of?(Stripe::Plan)
21
43
  end
22
44
 
23
- should "plans should be updateable" do
24
- @mock.expects(:post).once.
25
- with('https://api.stripe.com/v1/plans/test_plan', nil, 'metadata[foo]=bar').
26
- returns(make_response(make_plan(metadata: {foo: 'bar'})))
27
- p = Stripe::Plan.update("test_plan", metadata: {foo: 'bar'})
28
- assert_equal('bar', p.metadata['foo'])
45
+ should "be deletable" do
46
+ plan = Stripe::Plan.retrieve(FIXTURE[:id])
47
+ plan = plan.delete
48
+ assert_requested :delete, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
49
+ assert plan.kind_of?(Stripe::Plan)
29
50
  end
30
51
  end
31
52
  end
@@ -2,50 +2,46 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ProductTest < Test::Unit::TestCase
5
- should "products should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_product_array))
5
+ FIXTURE = API_FIXTURES.fetch(:product)
6
+
7
+ should "be listable" do
7
8
  products = Stripe::Product.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/products"
8
10
  assert products.data.kind_of?(Array)
9
- products.each do |product|
10
- assert product.kind_of?(Stripe::Product)
11
- end
11
+ assert products.data[0].kind_of?(Stripe::Product)
12
12
  end
13
13
 
14
- should "products should be deletable" do
15
- @mock.expects(:get).once.returns(make_response(make_product))
16
- @mock.expects(:delete).once.
17
- returns(make_response(make_product(:deleted => true)))
18
-
19
- p = Stripe::Product.retrieve("test_product")
20
- p.delete
21
- assert p.deleted
14
+ should "be retrievable" do
15
+ product = Stripe::Product.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
17
+ assert product.kind_of?(Stripe::Product)
22
18
  end
23
19
 
24
- should "products should be saveable" do
25
- @mock.expects(:get).once.returns(make_response(make_product))
26
- @mock.expects(:post).once.returns(make_response(make_product))
27
- p = Stripe::Product.new("test_product")
28
- p.refresh
29
- p.description = "New product description"
30
- p.save
20
+ should "be creatable" do
21
+ _ = Stripe::Product.create(
22
+ name: "My Product"
23
+ )
24
+ assert_requested :post, "#{Stripe.api_base}/v1/products"
31
25
  end
32
26
 
33
- should "products should be updateable" do
34
- @mock.expects(:post).once.
35
- with('https://api.stripe.com/v1/products/test_product', nil, 'description=update').
36
- returns(make_response(make_product(description: 'update')))
37
- p = Stripe::Product.update("test_product", description: 'update')
38
- assert_equal('update', p.description)
27
+ should "be saveable" do
28
+ product = Stripe::Product.retrieve(FIXTURE[:id])
29
+ product.metadata['key'] = 'value'
30
+ product.save
31
+ assert_requested :post, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
39
32
  end
40
33
 
41
- should "products should allow metadata updates" do
42
- @mock.expects(:get).once.returns(make_response(make_product))
43
- @mock.expects(:post).once.returns(make_response(make_product))
44
- p = Stripe::Product.new("test_product")
45
- p.refresh
46
- p.metadata['key'] = 'value'
47
- p.save
34
+ should "be updateable" do
35
+ product = Stripe::Product.update(FIXTURE[:id], metadata: {foo: 'bar'})
36
+ assert_requested :post, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
37
+ assert product.kind_of?(Stripe::Product)
48
38
  end
49
39
 
40
+ should "be deletable" do
41
+ product = Stripe::Product.retrieve(FIXTURE[:id])
42
+ product = product.delete
43
+ assert_requested :delete, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
44
+ assert product.kind_of?(Stripe::Product)
45
+ end
50
46
  end
51
47
  end
@@ -2,56 +2,39 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class RecipientCardTest < Test::Unit::TestCase
5
- RECIPIENT_CARD_URL = '/v1/recipients/test_recipient/cards/test_card'
5
+ FIXTURE = API_FIXTURES.fetch(:source)
6
6
 
7
- def recipient
8
- @mock.expects(:get).once.returns(make_response(make_recipient))
9
- Stripe::Recipient.retrieve('test_recipient')
7
+ setup do
8
+ @recipient =
9
+ Stripe::Recipient.retrieve(API_FIXTURES.fetch(:transfer_recipient)[:id])
10
10
  end
11
11
 
12
- should "recipient cards should be listable" do
13
- c = recipient
14
- @mock.expects(:get).once.returns(make_response(make_recipient_card_array(recipient.id)))
15
- cards = c.cards.list.data
16
- assert cards.kind_of? Array
17
- assert cards[0].kind_of? Stripe::Card
12
+ should "be listable" do
13
+ cards = @recipient.cards.list
14
+ assert cards.data.kind_of?(Array)
15
+ assert cards.data[0].kind_of?(Stripe::Token)
18
16
  end
19
17
 
20
- should "recipient cards should have the correct resource url" do
21
- c = recipient
22
- @mock.expects(:get).once.returns(make_response(make_card(
23
- :id => 'test_card',
24
- :recipient => 'test_recipient'
25
- )))
26
- card = c.cards.retrieve('card')
27
- assert_equal RECIPIENT_CARD_URL, card.resource_url
18
+ should "be creatable" do
19
+ card = @recipient.cards.create(
20
+ card: API_FIXTURES.fetch(:token)[:id]
21
+ )
22
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards"
23
+ assert card.kind_of?(Stripe::Token)
28
24
  end
29
25
 
30
- should "recipient cards should be deletable" do
31
- c = recipient
32
- @mock.expects(:get).once.returns(make_response(make_card))
33
- @mock.expects(:delete).once.returns(make_response(make_card(:deleted => true)))
34
- card = c.cards.retrieve('card')
35
- card.delete
36
- assert card.deleted
26
+ should "be deletable" do
27
+ card = Stripe::Card.construct_from(FIXTURE.merge(recipient: @recipient.id))
28
+ card = card.delete
29
+ assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/#{FIXTURE[:id]}"
30
+ assert card.kind_of?(Stripe::Card)
37
31
  end
38
32
 
39
- should "recipient cards should be updateable" do
40
- c = recipient
41
- @mock.expects(:get).once.returns(make_response(make_card(:exp_year => "2000")))
42
- @mock.expects(:post).once.returns(make_response(make_card(:exp_year => "2100")))
43
- card = c.cards.retrieve('card')
44
- assert_equal "2000", card.exp_year
45
- card.exp_year = "2100"
33
+ should "be saveable" do
34
+ card = Stripe::Card.construct_from(FIXTURE.merge(recipient: @recipient.id))
35
+ card.metadata['key'] = 'value'
46
36
  card.save
47
- assert_equal "2100", card.exp_year
48
- end
49
-
50
- should "create should return a new recipient card" do
51
- c = recipient
52
- @mock.expects(:post).once.returns(make_response(make_card(:id => "test_card")))
53
- card = c.cards.create(:card => "tok_41YJ05ijAaWaFS")
54
- assert_equal "test_card", card.id
37
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/#{FIXTURE[:id]}"
55
38
  end
56
39
  end
57
40
  end
@@ -2,19 +2,48 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class RecipientTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:transfer_recipient)
5
6
 
6
- should "recipient should be retrievable" do
7
- @mock.expects(:get).once.returns(make_response(make_recipient))
8
- r = Stripe::Recipient.retrieve('test_recipient')
9
- assert_equal 'rp_test_recipient', r.id
7
+ should "be listable" do
8
+ recipients = Stripe::Recipient.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/recipients"
10
+ assert recipients.data.kind_of?(Array)
11
+ assert recipients.data[0].kind_of?(Stripe::Recipient)
10
12
  end
11
13
 
12
- should "recipient should be updateable" do
13
- @mock.expects(:post).once.
14
- with("https://api.stripe.com/v1/recipients/test_recipient", nil, "metadata[foo]=bar").
15
- returns(make_response(make_recipient(metadata: {foo: 'bar'})))
16
- r = Stripe::Recipient.update('test_recipient', metadata: {foo: 'bar'})
17
- assert_equal 'bar', r.metadata['foo']
14
+ should "be retrievable" do
15
+ recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
17
+ assert recipient.kind_of?(Stripe::Recipient)
18
+ end
19
+
20
+ should "be creatable" do
21
+ recipient = Stripe::Recipient.create(
22
+ name: "Noah Jackson",
23
+ type: "individual"
24
+ )
25
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients"
26
+ assert recipient.kind_of?(Stripe::Recipient)
27
+ end
28
+
29
+ should "be saveable" do
30
+ recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
31
+ recipient.metadata['key'] = 'value'
32
+ recipient.save
33
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
34
+ end
35
+
36
+ should "be updateable" do
37
+ recipient = Stripe::Recipient.update(FIXTURE[:id], metadata: {foo: 'bar'})
38
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
39
+ assert recipient.kind_of?(Stripe::Recipient)
40
+ end
41
+
42
+ should "be deletable" do
43
+ recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
44
+ recipient = recipient.delete
45
+ assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
46
+ assert recipient.kind_of?(Stripe::Recipient)
18
47
  end
19
48
  end
20
49
  end
@@ -2,63 +2,38 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class RefundTest < Test::Unit::TestCase
5
- should "refunds should be listable" do
6
- @mock.expects(:get).
7
- with("#{Stripe.api_base}/v1/refunds", nil, nil).
8
- once.returns(make_response(make_refund_array))
5
+ FIXTURE = API_FIXTURES.fetch(:refund)
9
6
 
7
+ should "be listable" do
10
8
  refunds = Stripe::Refund.list
11
-
9
+ assert_requested :get, "#{Stripe.api_base}/v1/refunds"
10
+ assert refunds.data.kind_of?(Array)
12
11
  assert refunds.first.kind_of?(Stripe::Refund)
13
12
  end
14
13
 
15
- should "refunds should be refreshable" do
16
- @mock.expects(:get).
17
- with("#{Stripe.api_base}/v1/refunds/test_refund", nil, nil).
18
- twice.returns(make_response(make_refund(:id => 'test_refund')),
19
- make_response(make_refund(:id => 'refreshed_refund')))
20
-
21
- refund = Stripe::Refund.retrieve('test_refund')
22
- refund.refresh
23
-
24
- assert_equal 'refreshed_refund', refund.id
14
+ should "be retrievable" do
15
+ refund = Stripe::Refund.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
17
+ assert refund.kind_of?(Stripe::Refund)
25
18
  end
26
19
 
27
- should "refunds should be saveable" do
28
- @mock.expects(:get).
29
- with("#{Stripe.api_base}/v1/refunds/get_refund", nil, nil).
30
- once.returns(make_response(make_refund(:id => 'save_refund')))
31
-
32
- @mock.expects(:post).
33
- with("#{Stripe.api_base}/v1/refunds/save_refund", nil, 'metadata[key]=value').
34
- once.returns(make_response(make_refund(:metadata => {'key' => 'value'})))
35
-
36
- refund = Stripe::Refund.retrieve('get_refund')
37
-
38
- assert_equal nil, refund.metadata['key']
20
+ should "be creatable" do
21
+ refund = Stripe::Refund.create(:charge => API_FIXTURES[:charge][:id])
22
+ assert_requested :post, "#{Stripe.api_base}/v1/refunds"
23
+ assert refund.kind_of?(Stripe::Refund)
24
+ end
39
25
 
26
+ should "be saveable" do
27
+ refund = Stripe::Refund.retrieve(FIXTURE[:id])
40
28
  refund.metadata['key'] = 'value'
41
29
  refund.save
42
-
43
- assert_equal 'value', refund.metadata['key']
44
- end
45
-
46
- should "refunds should be updateable" do
47
- @mock.expects(:post).
48
- with("#{Stripe.api_base}/v1/refunds/update_refund", nil, 'metadata[key]=value').
49
- once.returns(make_response(make_refund(:metadata => {'key' => 'value'})))
50
-
51
- refund = Stripe::Refund.update('update_refund', metadata: {key: 'value'})
52
- assert_equal 'value', refund.metadata['key']
30
+ assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
53
31
  end
54
32
 
55
- should "create should return a new refund" do
56
- @mock.expects(:post).
57
- with("#{Stripe.api_base}/v1/refunds", nil, 'charge=test_charge').
58
- once.returns(make_response(make_refund(:id => 'test_new_refund')))
59
-
60
- refund = Stripe::Refund.create(:charge => 'test_charge')
61
- assert_equal 'test_new_refund', refund.id
33
+ should "be updateable" do
34
+ refund = Stripe::Refund.update(FIXTURE[:id], metadata: { key: 'value' })
35
+ assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
36
+ assert refund.kind_of?(Stripe::Refund)
62
37
  end
63
38
  end
64
39
  end
@@ -2,46 +2,42 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ReversalTest < Test::Unit::TestCase
5
- should "reversals should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_transfer))
5
+ FIXTURE = API_FIXTURES.fetch(:transfer_reversal)
7
6
 
8
- transfer = Stripe::Transfer.retrieve('test_transfer')
9
-
10
- assert transfer.reversals.first.kind_of?(Stripe::Reversal)
7
+ setup do
8
+ @transfer = Stripe::Transfer.retrieve(API_FIXTURES.fetch(:transfer)[:id])
11
9
  end
12
10
 
13
- should "reversals should be refreshable" do
14
- @mock.expects(:get).twice.returns(make_response(make_transfer), make_response(make_reversal(:id => 'refreshed_reversal')))
15
-
16
- transfer = Stripe::Transfer.retrieve('test_transfer')
17
- reversal = transfer.reversals.first
18
- reversal.refresh
19
-
20
- assert_equal 'refreshed_reversal', reversal.id
11
+ should "be listable" do
12
+ reversals = @transfer.reversals.list
13
+ assert_requested :get,
14
+ "#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals"
15
+ assert reversals.data.kind_of?(Array)
16
+ assert reversals.data[0].kind_of?(Stripe::Reversal)
21
17
  end
22
18
 
23
- should "reversals should be updateable" do
24
- @mock.expects(:get).once.returns(make_response(make_transfer))
25
- @mock.expects(:post).once.returns(make_response(make_reversal(:metadata => {'key' => 'value'})))
26
-
27
- transfer = Stripe::Transfer.retrieve('test_transfer')
28
- reversal = transfer.reversals.first
19
+ should "be retrievable" do
20
+ reversal = @transfer.reversals.retrieve(FIXTURE[:id])
21
+ assert_requested :get,
22
+ "#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/#{FIXTURE[:id]}"
23
+ assert reversal.kind_of?(Stripe::Reversal)
24
+ end
29
25
 
30
- assert_equal nil, reversal.metadata['key']
26
+ should "be creatable" do
27
+ reversal = @transfer.reversals.create(
28
+ amount: 100
29
+ )
30
+ assert_requested :post,
31
+ "#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals"
32
+ assert reversal.kind_of?(Stripe::Reversal)
33
+ end
31
34
 
35
+ should "be saveable" do
36
+ reversal = @transfer.reversals.retrieve(FIXTURE[:id])
32
37
  reversal.metadata['key'] = 'value'
33
38
  reversal.save
34
-
35
- assert_equal 'value', reversal.metadata['key']
36
- end
37
-
38
- should "create should return a new reversal" do
39
- @mock.expects(:get).once.returns(make_response(make_transfer))
40
- @mock.expects(:post).once.returns(make_response(make_reversal(:id => 'test_new_reversal')))
41
-
42
- transfer = Stripe::Transfer.retrieve('test_transfer')
43
- reversals = transfer.reversals.create(:amount => 20)
44
- assert_equal 'test_new_reversal', reversals.id
39
+ assert_requested :post,
40
+ "#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/#{FIXTURE[:id]}"
45
41
  end
46
42
  end
47
43
  end
@@ -2,32 +2,49 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class SKUTest < Test::Unit::TestCase
5
- should "SKUs should be listable" do
6
- @mock.expects(:get).once.
7
- returns(make_response(make_sku_array("test_product")))
5
+ FIXTURE = API_FIXTURES.fetch(:sku)
6
+
7
+ should "be listable" do
8
8
  skus = Stripe::SKU.list
9
- assert skus.data.kind_of? Array
10
- skus.each do |sku|
11
- assert sku.kind_of?(Stripe::SKU)
12
- end
9
+ assert_requested :get, "#{Stripe.api_base}/v1/skus"
10
+ assert skus.data.kind_of?(Array)
11
+ assert skus.data[0].kind_of?(Stripe::SKU)
13
12
  end
14
13
 
15
- should "SKUs should be updateable" do
16
- @mock.expects(:post).once.
17
- with("#{Stripe.api_base}/v1/skus/test_sku", nil, 'metadata[foo]=bar').
18
- returns(make_response(make_sku(:metadata => {foo: 'bar'})))
19
- s = Stripe::SKU.update("test_sku", metadata: {foo: 'bar'})
20
- assert_equal 'bar', s.metadata['foo']
14
+ should "be retrievable" do
15
+ sku = Stripe::SKU.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
17
+ assert sku.kind_of?(Stripe::SKU)
21
18
  end
22
19
 
23
- should "SKUs should be deletable" do
24
- @mock.expects(:get).once.returns(make_response(make_sku))
25
- @mock.expects(:delete).once.returns(make_response(make_sku(:deleted => true)))
20
+ should "be creatable" do
21
+ _ = Stripe::SKU.create(
22
+ currency: "USD",
23
+ inventory: { type: "finite", quantity: 500 },
24
+ price: 100,
25
+ product: API_FIXTURES.fetch(:product)[:id]
26
+ )
27
+ assert_requested :post, "#{Stripe.api_base}/v1/skus"
28
+ end
26
29
 
27
- s = Stripe::SKU.retrieve("test_sku")
28
- s.delete
29
- assert s.deleted
30
+ should "be saveable" do
31
+ sku = Stripe::SKU.retrieve(FIXTURE[:id])
32
+ sku.metadata['key'] = 'value'
33
+ sku.save
34
+ assert_requested :post, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
30
35
  end
31
36
 
37
+ should "be updateable" do
38
+ sku = Stripe::SKU.update(FIXTURE[:id], metadata: {foo: 'bar'})
39
+ assert_requested :post, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
40
+ assert sku.kind_of?(Stripe::SKU)
41
+ end
42
+
43
+ should "be deletable" do
44
+ sku = Stripe::SKU.retrieve(FIXTURE[:id])
45
+ sku = sku.delete
46
+ assert_requested :delete, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
47
+ assert sku.kind_of?(Stripe::SKU)
48
+ end
32
49
  end
33
50
  end