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,42 +2,19 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class CountrySpecTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:country_spec)
6
+
5
7
  should "be listable" do
6
- @mock.expects(:get).once.
7
- returns(make_response(country_spec_array))
8
8
  c = Stripe::CountrySpec.list
9
-
10
- assert_equal('/v1/country_specs', c.resource_url)
11
- assert_equal('list', c.object)
12
- assert(c.data.kind_of?(Array))
13
- assert_equal('US', c.data[0].id)
14
- assert(c.data[0].kind_of?(Stripe::CountrySpec))
9
+ assert_requested :get, "#{Stripe.api_base}/v1/country_specs"
10
+ assert c.data.kind_of?(Array)
11
+ assert c.data[0].kind_of?(Stripe::CountrySpec)
15
12
  end
16
13
 
17
14
  should "be retrievable" do
18
- resp = make_country_spec
19
- @mock.expects(:get).once.
20
- with('https://api.stripe.com/v1/country_specs/US', nil, nil).
21
- returns(make_response(resp))
22
- s = Stripe::CountrySpec.retrieve('US')
23
-
24
- assert_equal('/v1/country_specs/US', s.resource_url)
25
- assert_equal('country_spec', s.object)
15
+ s = Stripe::CountrySpec.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/country_specs/#{FIXTURE[:id]}"
26
17
  assert(s.kind_of?(Stripe::CountrySpec))
27
-
28
- s.supported_bank_account_currencies.map{ |k,v| assert v.kind_of?(Array) }
29
- assert_equal(['US'], s.supported_bank_account_currencies['usd'])
30
- assert(s.supported_payment_currencies.include?('usd'))
31
- assert s.supported_payment_currencies.kind_of?(Array)
32
- assert s.supported_payment_methods.kind_of?(Array)
33
-
34
- ['individual', 'company'].map{ |type|
35
- item = s.verification_fields[type]
36
- assert item.minimum.include?('external_account')
37
- assert item.additional.include?('legal_entity.verification.document')
38
- assert item.additional.kind_of?(Array)
39
- assert item.minimum.kind_of?(Array)
40
- }
41
18
  end
42
19
  end
43
20
  end
@@ -2,27 +2,43 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class CouponTest < Test::Unit::TestCase
5
- should "create should return a new coupon" do
6
- @mock.expects(:post).once.returns(make_response(make_coupon))
7
- c = Stripe::Coupon.create
8
- assert_equal "co_test_coupon", c.id
5
+ FIXTURE = API_FIXTURES.fetch(:coupon)
6
+
7
+ should "be listable" do
8
+ coupons = Stripe::Coupon.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/coupons"
10
+ assert coupons.data.kind_of?(Array)
11
+ assert coupons.first.kind_of?(Stripe::Coupon)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ coupon = Stripe::Coupon.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
17
+ assert coupon.kind_of?(Stripe::Coupon)
18
+ end
19
+
20
+ should "be creatable" do
21
+ coupon = Stripe::Coupon.create(
22
+ percent_off: 25,
23
+ duration: 'repeating',
24
+ duration_in_months: 3,
25
+ id: '25OFF'
26
+ )
27
+ assert_requested :post, "#{Stripe.api_base}/v1/coupons"
28
+ assert coupon.kind_of?(Stripe::Coupon)
9
29
  end
10
30
 
11
- should "coupons should be saveable" do
12
- @mock.expects(:get).once.returns(make_response(make_coupon))
13
- @mock.expects(:post).once.returns(make_response(make_coupon))
14
- c = Stripe::Coupon.new("test_coupon")
15
- c.refresh
16
- c.metadata['foo'] = 'bar'
17
- c.save
31
+ should "be saveable" do
32
+ coupon = Stripe::Coupon.retrieve(FIXTURE[:id])
33
+ coupon.metadata['key'] = 'value'
34
+ coupon.save
35
+ assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
18
36
  end
19
37
 
20
- should "coupons should be updateable" do
21
- @mock.expects(:post).once.
22
- with("https://api.stripe.com/v1/coupons/test_coupon", nil, "metadata[foo]=bar").
23
- returns(make_response(make_coupon(metadata: {foo: 'bar'})))
24
- c = Stripe::Coupon.update("test_coupon", metadata: {foo: 'bar'})
25
- assert_equal('bar', c.metadata['foo'])
38
+ should "be updateable" do
39
+ coupon = Stripe::Coupon.update(FIXTURE[:id], metadata: { key: 'value' })
40
+ assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
41
+ assert coupon.kind_of?(Stripe::Coupon)
26
42
  end
27
43
  end
28
44
  end
@@ -2,62 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class CustomerCardTest < Test::Unit::TestCase
5
- CUSTOMER_CARD_URL = '/v1/customers/test_customer/sources/test_card'
5
+ FIXTURE = API_FIXTURES.fetch(:source)
6
6
 
7
- def customer
8
- @mock.expects(:get).once.returns(make_response(make_customer))
9
- Stripe::Customer.retrieve('test_customer')
7
+ setup do
8
+ @customer =
9
+ Stripe::Customer.retrieve(API_FIXTURES.fetch(:customer)[:id])
10
10
  end
11
11
 
12
- should "customer cards should be listable" do
13
- c = customer
14
- @mock.expects(:get).once.returns(make_response(make_customer_card_array(customer.id)))
15
- cards = c.sources.list(:object => "card").data
16
- assert cards.kind_of? Array
17
- assert cards[0].kind_of? Stripe::Card
12
+ should "be listable" do
13
+ sources = @customer.sources.list
14
+ assert sources.data.kind_of?(Array)
15
+ # because of the terrible :wildcard nature of sources, the API stub
16
+ # cannot currently replace this response with anything meaningful so we
17
+ # don't assert on the type of individual items like we do in other tests
18
18
  end
19
19
 
20
- should "customer cards should have the correct resource url" do
21
- c = customer
22
- @mock.expects(:get).once.returns(make_response(make_card(
23
- :id => 'test_card',
24
- :customer => 'test_customer'
25
- )))
26
- card = c.sources.retrieve('card')
27
- assert_equal CUSTOMER_CARD_URL, card.resource_url
20
+ should "be creatable" do
21
+ card = @customer.sources.create(
22
+ source: API_FIXTURES.fetch(:token)[:id]
23
+ )
24
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
25
+ assert card.kind_of?(Stripe::BankAccount)
28
26
  end
29
27
 
30
- should "customer cards should be deletable" do
31
- c = customer
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.sources.retrieve('card')
35
- card.delete
36
- assert card.deleted
28
+ should "be deletable" do
29
+ card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
30
+ card = card.delete
31
+ assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
32
+ assert card.kind_of?(Stripe::Card)
37
33
  end
38
34
 
39
- should "customer cards should be updateable" do
40
- c = customer
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.sources.retrieve('card')
44
- assert_equal "2000", card.exp_year
45
- card.exp_year = "2100"
35
+ should "be saveable" do
36
+ card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
37
+ card.metadata['key'] = 'value'
46
38
  card.save
47
- assert_equal "2100", card.exp_year
48
- end
49
-
50
- should "create should return a new customer card" do
51
- c = customer
52
- @mock.expects(:post).once.returns(make_response(make_card(:id => "test_card")))
53
- card = c.sources.create(:source => "tok_41YJ05ijAaWaFS")
54
- assert_equal "test_card", card.id
55
- end
56
-
57
- should "raise if accessing Stripe::Card.retrieve directly" do
58
- assert_raises NotImplementedError do
59
- Stripe::Card.retrieve "card_12345"
60
- end
39
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
61
40
  end
62
41
  end
63
42
  end
@@ -2,109 +2,114 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class CustomerTest < Test::Unit::TestCase
5
- should "customers should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_customer_array))
7
- c = Stripe::Customer.list.data
8
- assert c.kind_of? Array
9
- assert c[0].kind_of? Stripe::Customer
10
- end
5
+ FIXTURE = API_FIXTURES.fetch(:customer)
11
6
 
12
- should "customers should be deletable" do
13
- @mock.expects(:delete).once.returns(make_response(make_customer({:deleted => true})))
14
- c = Stripe::Customer.new("test_customer")
15
- c.delete
16
- assert c.deleted
7
+ should "be listable" do
8
+ customers = Stripe::Customer.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/customers"
10
+ assert customers.data.kind_of?(Array)
11
+ assert customers.first.kind_of?(Stripe::Customer)
17
12
  end
18
13
 
19
- should "customers should be saveable" do
20
- @mock.expects(:get).once.returns(make_response(make_customer({:mnemonic => "foo"})))
21
- @mock.expects(:post).once.returns(make_response(make_customer({:mnemonic => "bar"})))
22
- c = Stripe::Customer.new("test_customer").refresh
23
- assert_equal "foo", c.mnemonic
24
- c.mnemonic = "bar"
25
- c.save
26
- assert_equal "bar", c.mnemonic
14
+ should "be retrievable" do
15
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
17
+ assert customer.kind_of?(Stripe::Customer)
27
18
  end
28
19
 
29
- should "customers should be updateable" do
30
- @mock.expects(:post).once.
31
- with("https://api.stripe.com/v1/customers/test_customer", nil, "metadata[foo]=bar").
32
- returns(make_response(make_customer(metadata: {foo: 'bar'})))
33
- c = Stripe::Customer.update("test_customer", metadata: {foo: 'bar'})
34
- assert_equal('bar', c.metadata['foo'])
20
+ should "be creatable" do
21
+ customer = Stripe::Customer.create
22
+ assert_requested :post, "#{Stripe.api_base}/v1/customers"
23
+ assert customer.kind_of?(Stripe::Customer)
35
24
  end
36
25
 
37
- should "create should return a new customer" do
38
- @mock.expects(:post).once.returns(make_response(make_customer))
39
- c = Stripe::Customer.create
40
- assert_equal "c_test_customer", c.id
26
+ should "be saveable" do
27
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
28
+ customer.metadata['key'] = 'value'
29
+ customer.save
30
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
41
31
  end
42
32
 
43
- should "create_upcoming_invoice should create a new invoice" do
44
- @mock.expects(:post).once.returns(make_response(make_invoice))
45
- i = Stripe::Customer.new("test_customer").create_upcoming_invoice
46
- assert_equal "c_test_customer", i.customer
33
+ should "be updateable" do
34
+ customer = Stripe::Customer.update(FIXTURE[:id], metadata: { key: 'value' })
35
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
36
+ assert customer.kind_of?(Stripe::Customer)
47
37
  end
48
38
 
49
- should "be able to update a customer's subscription" do
50
- @mock.expects(:get).once.returns(make_response(make_customer))
51
- c = Stripe::Customer.retrieve("test_customer")
52
-
53
- @mock.expects(:post).once.with do |url, api_key, params|
54
- url == "#{Stripe.api_base}/v1/customers/c_test_customer/subscription" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
55
- end.returns(make_response(make_subscription(:plan => 'silver')))
56
- s = c.update_subscription({:plan => 'silver'})
57
-
58
- assert_equal 'subscription', s.object
59
- assert_equal 'silver', s.plan.identifier
39
+ should "be deletable" do
40
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
41
+ customer = customer.delete
42
+ assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
43
+ assert customer.kind_of?(Stripe::Customer)
60
44
  end
61
45
 
62
- should "be able to cancel a customer's subscription" do
63
- @mock.expects(:get).once.returns(make_response(make_customer))
64
- c = Stripe::Customer.retrieve("test_customer")
65
-
66
- # Not an accurate response, but whatever
67
-
68
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription?at_period_end=true", nil, nil).returns(make_response(make_subscription(:plan => 'silver')))
69
- c.cancel_subscription({:at_period_end => 'true'})
70
-
71
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription", nil, nil).returns(make_response(make_subscription(:plan => 'silver')))
72
- c.cancel_subscription
46
+ context "#create_subscription" do
47
+ should "create a new subscription" do
48
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
49
+ subscription = customer.create_subscription({:plan => 'silver'})
50
+ assert subscription.kind_of?(Stripe::Subscription)
51
+ end
73
52
  end
74
53
 
75
- should "be able to create a subscription for a customer" do
76
- c = Stripe::Customer.new("test_customer")
77
-
78
- @mock.expects(:post).once.with do |url, api_key, params|
79
- url == "#{Stripe.api_base}/v1/customers/test_customer/subscriptions" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
80
- end.returns(make_response(make_subscription(:plan => 'silver')))
81
- s = c.create_subscription({:plan => 'silver'})
82
-
83
- assert_equal 'subscription', s.object
84
- assert_equal 'silver', s.plan.identifier
54
+ context "#create_upcoming_invoice" do
55
+ should "create a new invoice" do
56
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
57
+ invoice = customer.create_upcoming_invoice
58
+ assert invoice.kind_of?(Stripe::Invoice)
59
+ end
85
60
  end
86
61
 
87
- should "be able to delete a customer's discount" do
88
- @mock.expects(:get).once.returns(make_response(make_customer))
89
- c = Stripe::Customer.retrieve("test_customer")
62
+ context "#update_subscription" do
63
+ should "update a subscription" do
64
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
65
+
66
+ # deprecated API and not in schema
67
+ stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
68
+ with(body: { plan: "silver" }).
69
+ to_return(body: JSON.generate(API_FIXTURES[:subscription]))
70
+ subscription = customer.update_subscription({:plan => 'silver'})
71
+ assert subscription.kind_of?(Stripe::Subscription)
72
+ end
73
+ end
90
74
 
91
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/discount", nil, nil).returns(make_response(make_delete_discount_response))
92
- c.delete_discount
93
- assert_equal nil, c.discount
75
+ context "#cancel_subscription" do
76
+ should "cancel a subscription" do
77
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
78
+
79
+ # deprecated API and not in schema
80
+ stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
81
+ with(query: { at_period_end: "true" }).
82
+ to_return(body: JSON.generate(API_FIXTURES[:subscription]))
83
+ subscription = customer.cancel_subscription({:at_period_end => 'true'})
84
+ assert subscription.kind_of?(Stripe::Subscription)
85
+ end
94
86
  end
95
87
 
96
- should "can have a token source set" do
97
- c = Stripe::Customer.new("test_customer")
98
- c.source = "tok_123"
99
- assert_equal "tok_123", c.source
88
+ context "#delete_discount" do
89
+ should "delete a discount" do
90
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
91
+
92
+ stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/discount").
93
+ to_return(body: JSON.generate(API_FIXTURES[:discount]))
94
+ discount = customer.delete_discount
95
+ assert discount.kind_of?(Stripe::Customer)
96
+ end
100
97
  end
101
98
 
102
- should "set a flag if given an object source" do
103
- c = Stripe::Customer.new("test_customer")
104
- c.source = {
105
- :object => 'card'
106
- }
107
- assert_equal true, c.source.save_with_parent
99
+ context "source field" do
100
+ should "allow setting source with token" do
101
+ c = Stripe::Customer.new("test_customer")
102
+ c.source = "tok_123"
103
+ assert_equal "tok_123", c.source
104
+ end
105
+
106
+ should "allow setting source with hash and set flag" do
107
+ c = Stripe::Customer.new("test_customer")
108
+ c.source = {
109
+ :object => 'card'
110
+ }
111
+ assert_equal true, c.source.save_with_parent
112
+ end
108
113
  end
109
114
  end
110
115
  end
@@ -2,52 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class DisputeTest < Test::Unit::TestCase
5
- should "disputes should be retrievable" do
6
- @mock.expects(:get).once.returns(make_response(make_dispute))
7
- d = Stripe::Dispute.retrieve('dp_test_dispute')
8
- assert d.kind_of?(Stripe::Dispute)
9
- end
5
+ FIXTURE = API_FIXTURES.fetch(:dispute)
10
6
 
11
- should "disputes should be listable" do
12
- @mock.expects(:get).once.returns(make_response(make_dispute_array))
13
- d = Stripe::Dispute.list
14
- assert d.data.kind_of? Array
15
- d.each do |dispute|
16
- assert dispute.kind_of?(Stripe::Dispute)
17
- end
7
+ should "be listable" do
8
+ disputes = Stripe::Dispute.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/disputes"
10
+ assert disputes.data.kind_of?(Array)
11
+ assert disputes.first.kind_of?(Stripe::Dispute)
18
12
  end
19
13
 
20
- should "disputes should be closeable" do
21
- @mock.expects(:get).never
22
- @mock.expects(:post).with(
23
- "#{Stripe.api_base}/v1/disputes/test_dispute/close",
24
- nil,
25
- ''
26
- ).once.returns(make_response({:id => 'dp_test_dispute', :status => 'lost'}))
27
- d = Stripe::Dispute.new('test_dispute')
28
- d.close
14
+ should "be retrievable" do
15
+ dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
17
+ assert dispute.kind_of?(Stripe::Dispute)
29
18
  end
30
19
 
31
- should "disputes should be updateable" do
32
- @mock.expects(:post).once.
33
- with("https://api.stripe.com/v1/disputes/test_dispute", nil, "metadata[foo]=bar").
34
- returns(make_response(make_dispute(metadata: {foo: 'bar'})))
35
- d = Stripe::Dispute.update("test_dispute", metadata: {foo: 'bar'})
36
- assert_equal('bar', d.metadata['foo'])
20
+ should "be saveable" do
21
+ dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
22
+ dispute.metadata['key'] = 'value'
23
+ dispute.save
24
+ assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
37
25
  end
38
26
 
39
- should "disputes should be saveable" do
40
- @mock.expects(:get).once.returns(make_response(make_dispute))
41
- @mock.expects(:post).with(
42
- "#{Stripe.api_base}/v1/disputes/dp_test_dispute",
43
- nil,
44
- 'evidence[customer_name]=customer'
45
- ).once.returns(make_response(make_dispute))
27
+ should "be updateable" do
28
+ dispute = Stripe::Dispute.update(FIXTURE[:id], metadata: { key: 'value' })
29
+ assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
30
+ assert dispute.kind_of?(Stripe::Dispute)
31
+ end
46
32
 
47
- d = Stripe::Dispute.new('test_dispute')
48
- d.refresh
49
- d.evidence['customer_name'] = 'customer'
50
- d.save
33
+ context "#close" do
34
+ should "be closeable" do
35
+ dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
36
+ dispute.close
37
+ assert_requested :post,
38
+ "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}/close"
39
+ end
51
40
  end
52
41
  end
53
42
  end