stripe 3.3.2 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +20 -0
  4. data/.rubocop_todo.yml +62 -0
  5. data/.travis.yml +1 -1
  6. data/Gemfile +19 -12
  7. data/History.txt +10 -0
  8. data/README.md +5 -1
  9. data/Rakefile +8 -5
  10. data/VERSION +1 -1
  11. data/bin/stripe-console +2 -2
  12. data/lib/stripe.rb +72 -74
  13. data/lib/stripe/account.rb +15 -17
  14. data/lib/stripe/alipay_account.rb +10 -7
  15. data/lib/stripe/api_operations/create.rb +1 -1
  16. data/lib/stripe/api_operations/delete.rb +1 -1
  17. data/lib/stripe/api_operations/list.rb +2 -2
  18. data/lib/stripe/api_operations/request.rb +5 -12
  19. data/lib/stripe/api_operations/save.rb +6 -6
  20. data/lib/stripe/api_resource.rb +7 -9
  21. data/lib/stripe/apple_pay_domain.rb +2 -2
  22. data/lib/stripe/application_fee.rb +5 -5
  23. data/lib/stripe/application_fee_refund.rb +5 -5
  24. data/lib/stripe/balance.rb +1 -1
  25. data/lib/stripe/balance_transaction.rb +2 -2
  26. data/lib/stripe/bank_account.rb +7 -7
  27. data/lib/stripe/bitcoin_receiver.rb +4 -2
  28. data/lib/stripe/bitcoin_transaction.rb +3 -1
  29. data/lib/stripe/card.rb +5 -5
  30. data/lib/stripe/charge.rb +18 -18
  31. data/lib/stripe/country_spec.rb +2 -2
  32. data/lib/stripe/coupon.rb +1 -1
  33. data/lib/stripe/customer.rb +23 -23
  34. data/lib/stripe/dispute.rb +3 -3
  35. data/lib/stripe/ephemeral_key.rb +4 -4
  36. data/lib/stripe/errors.rb +4 -4
  37. data/lib/stripe/event.rb +1 -1
  38. data/lib/stripe/file_upload.rb +5 -5
  39. data/lib/stripe/invoice.rb +7 -7
  40. data/lib/stripe/invoice_item.rb +1 -1
  41. data/lib/stripe/invoice_line_item.rb +1 -1
  42. data/lib/stripe/list_object.rb +14 -18
  43. data/lib/stripe/login_link.rb +3 -3
  44. data/lib/stripe/oauth.rb +15 -13
  45. data/lib/stripe/order.rb +5 -5
  46. data/lib/stripe/order_return.rb +1 -1
  47. data/lib/stripe/payout.rb +3 -3
  48. data/lib/stripe/plan.rb +1 -1
  49. data/lib/stripe/product.rb +1 -1
  50. data/lib/stripe/recipient.rb +3 -2
  51. data/lib/stripe/recipient_transfer.rb +1 -2
  52. data/lib/stripe/refund.rb +1 -1
  53. data/lib/stripe/reversal.rb +5 -5
  54. data/lib/stripe/singleton_api_resource.rb +3 -3
  55. data/lib/stripe/sku.rb +1 -1
  56. data/lib/stripe/source.rb +13 -10
  57. data/lib/stripe/stripe_client.rb +149 -169
  58. data/lib/stripe/stripe_object.rb +77 -76
  59. data/lib/stripe/subscription.rb +5 -5
  60. data/lib/stripe/subscription_item.rb +2 -2
  61. data/lib/stripe/three_d_secure.rb +1 -1
  62. data/lib/stripe/token.rb +1 -1
  63. data/lib/stripe/transfer.rb +3 -3
  64. data/lib/stripe/util.rb +77 -62
  65. data/lib/stripe/version.rb +1 -1
  66. data/lib/stripe/webhook.rb +14 -10
  67. data/stripe.gemspec +14 -14
  68. data/test/stripe/account_test.rb +69 -81
  69. data/test/stripe/alipay_account_test.rb +19 -1
  70. data/test/stripe/api_operations_test.rb +7 -7
  71. data/test/stripe/api_resource_test.rb +224 -260
  72. data/test/stripe/apple_pay_domain_test.rb +8 -8
  73. data/test/stripe/application_fee_refund_test.rb +8 -8
  74. data/test/stripe/application_fee_test.rb +3 -3
  75. data/test/stripe/balance_test.rb +2 -2
  76. data/test/stripe/bank_account_test.rb +9 -11
  77. data/test/stripe/charge_test.rb +11 -11
  78. data/test/stripe/country_spec_test.rb +4 -4
  79. data/test/stripe/coupon_test.rb +10 -10
  80. data/test/stripe/customer_card_test.rb +11 -15
  81. data/test/stripe/customer_test.rb +26 -27
  82. data/test/stripe/dispute_test.rb +8 -8
  83. data/test/stripe/ephemeral_key_test.rb +14 -14
  84. data/test/stripe/errors_test.rb +2 -2
  85. data/test/stripe/file_upload_test.rb +26 -28
  86. data/test/stripe/invoice_item_test.rb +14 -14
  87. data/test/stripe/invoice_line_item_test.rb +1 -1
  88. data/test/stripe/invoice_test.rb +37 -37
  89. data/test/stripe/list_object_test.rb +60 -76
  90. data/test/stripe/login_link_test.rb +14 -14
  91. data/test/stripe/oauth_test.rb +42 -50
  92. data/test/stripe/order_return_test.rb +5 -5
  93. data/test/stripe/order_test.rb +12 -12
  94. data/test/stripe/payout_test.rb +9 -9
  95. data/test/stripe/plan_test.rb +9 -9
  96. data/test/stripe/product_test.rb +8 -8
  97. data/test/stripe/recipient_test.rb +9 -10
  98. data/test/stripe/refund_test.rb +9 -9
  99. data/test/stripe/reversal_test.rb +10 -10
  100. data/test/stripe/sku_test.rb +8 -8
  101. data/test/stripe/source_test.rb +14 -16
  102. data/test/stripe/stripe_client_test.rb +235 -266
  103. data/test/stripe/stripe_object_test.rb +163 -147
  104. data/test/stripe/stripe_response_test.rb +4 -3
  105. data/test/stripe/subscription_item_test.rb +11 -11
  106. data/test/stripe/subscription_test.rb +14 -14
  107. data/test/stripe/three_d_secure_test.rb +2 -2
  108. data/test/stripe/transfer_test.rb +8 -8
  109. data/test/stripe/util_test.rb +59 -57
  110. data/test/stripe/webhook_test.rb +18 -16
  111. data/test/stripe_test.rb +4 -4
  112. data/test/test_data.rb +26 -26
  113. data/test/test_helper.rb +29 -25
  114. metadata +6 -10
  115. data/test/stripe/bitcoin_receiver_test.rb +0 -67
  116. data/test/stripe/bitcoin_transaction_test.rb +0 -19
  117. data/test/stripe/recipient_card_test.rb +0 -44
@@ -1,31 +1,31 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class DisputeTest < Test::Unit::TestCase
5
5
  should "be listable" do
6
6
  disputes = Stripe::Dispute.list
7
7
  assert_requested :get, "#{Stripe.api_base}/v1/disputes"
8
- assert disputes.data.kind_of?(Array)
9
- assert disputes.first.kind_of?(Stripe::Dispute)
8
+ assert disputes.data.is_a?(Array)
9
+ assert disputes.first.is_a?(Stripe::Dispute)
10
10
  end
11
11
 
12
12
  should "be retrievable" do
13
13
  dispute = Stripe::Dispute.retrieve("dp_123")
14
14
  assert_requested :get, "#{Stripe.api_base}/v1/disputes/dp_123"
15
- assert dispute.kind_of?(Stripe::Dispute)
15
+ assert dispute.is_a?(Stripe::Dispute)
16
16
  end
17
17
 
18
18
  should "be saveable" do
19
19
  dispute = Stripe::Dispute.retrieve("dp_123")
20
- dispute.metadata['key'] = 'value'
20
+ dispute.metadata["key"] = "value"
21
21
  dispute.save
22
22
  assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{dispute.id}"
23
23
  end
24
24
 
25
25
  should "be updateable" do
26
- dispute = Stripe::Dispute.update("dp_123", metadata: { key: 'value' })
26
+ dispute = Stripe::Dispute.update("dp_123", metadata: { key: "value" })
27
27
  assert_requested :post, "#{Stripe.api_base}/v1/disputes/dp_123"
28
- assert dispute.kind_of?(Stripe::Dispute)
28
+ assert dispute.is_a?(Stripe::Dispute)
29
29
  end
30
30
 
31
31
  context "#close" do
@@ -33,7 +33,7 @@ module Stripe
33
33
  dispute = Stripe::Dispute.retrieve("dp_123")
34
34
  dispute.close
35
35
  assert_requested :post,
36
- "#{Stripe.api_base}/v1/disputes/#{dispute.id}/close"
36
+ "#{Stripe.api_base}/v1/disputes/#{dispute.id}/close"
37
37
  end
38
38
  end
39
39
  end
@@ -1,37 +1,37 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class EphemeralKeyTest < Test::Unit::TestCase
5
5
  context "#create" do
6
6
  should "succeed" do
7
7
  key = Stripe::EphemeralKey.create(
8
- {customer:"cus_123"},
9
- {stripe_version:"2017-05-25"}
8
+ { customer: "cus_123" },
9
+ stripe_version: "2017-05-25"
10
10
  )
11
11
 
12
12
  assert_requested(
13
13
  :post,
14
14
  "#{Stripe.api_base}/v1/ephemeral_keys",
15
- headers: {'Stripe-Version' => '2017-05-25'}
15
+ headers: { "Stripe-Version" => "2017-05-25" }
16
16
  )
17
17
 
18
- assert key.kind_of?(Stripe::EphemeralKey)
18
+ assert key.is_a?(Stripe::EphemeralKey)
19
19
  end
20
20
 
21
21
  context "#no global version" do
22
22
  should "use the correct api version" do
23
23
  key = Stripe::EphemeralKey.create(
24
- {customer: "cus_123"},
25
- {stripe_version: "2017-06-05"}
24
+ { customer: "cus_123" },
25
+ stripe_version: "2017-06-05"
26
26
  )
27
27
 
28
28
  assert_requested(
29
29
  :post,
30
30
  "#{Stripe.api_base}/v1/ephemeral_keys",
31
- headers: {'Stripe-Version' => '2017-06-05'}
31
+ headers: { "Stripe-Version" => "2017-06-05" }
32
32
  )
33
33
 
34
- assert key.kind_of?(Stripe::EphemeralKey)
34
+ assert key.is_a?(Stripe::EphemeralKey)
35
35
  end
36
36
 
37
37
  should "error without an explicit api version" do
@@ -53,11 +53,11 @@ module Stripe
53
53
 
54
54
  should "use the correct api version" do
55
55
  key = Stripe::EphemeralKey.create(
56
- {customer: "cus_123"},
57
- {stripe_version: "2017-05-25"}
56
+ { customer: "cus_123" },
57
+ stripe_version: "2017-05-25"
58
58
  )
59
59
 
60
- assert key.kind_of?(Stripe::EphemeralKey)
60
+ assert key.is_a?(Stripe::EphemeralKey)
61
61
  end
62
62
 
63
63
  should "error without an explicit api version" do
@@ -72,8 +72,8 @@ module Stripe
72
72
  context "#delete" do
73
73
  should "succeed" do
74
74
  key = Stripe::EphemeralKey.create(
75
- {customer: 'cus_123'},
76
- {stripe_version: '2017-05-25'}
75
+ { customer: "cus_123" },
76
+ stripe_version: "2017-05-25"
77
77
  )
78
78
 
79
79
  key.delete
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class StripeErrorTest < Test::Unit::TestCase
@@ -10,7 +10,7 @@ module Stripe
10
10
  e = StripeError.new("message", http_status: 200)
11
11
  assert_equal "(Status 200) message", e.to_s
12
12
 
13
- e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { :request_id => "request-id" })
13
+ e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { request_id: "request-id" })
14
14
  assert_equal "(Request request-id) message", e.to_s
15
15
  end
16
16
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class FileUploadTest < Test::Unit::TestCase
@@ -13,54 +13,52 @@ module Stripe
13
13
  }.freeze
14
14
 
15
15
  should "be listable" do
16
- stub_request(:get, "#{Stripe.uploads_base}/v1/files").
17
- to_return(body: JSON.generate({
18
- data: [FIXTURE],
19
- object: 'list',
20
- resource_url: '/v1/files'
21
- }))
16
+ stub_request(:get, "#{Stripe.uploads_base}/v1/files")
17
+ .to_return(body: JSON.generate(data: [FIXTURE],
18
+ object: "list",
19
+ resource_url: "/v1/files"))
22
20
 
23
21
  files = Stripe::FileUpload.list
24
- assert files.data.kind_of?(Array)
25
- assert files.data[0].kind_of?(Stripe::FileUpload)
22
+ assert files.data.is_a?(Array)
23
+ assert files.data[0].is_a?(Stripe::FileUpload)
26
24
  end
27
25
 
28
26
  should "be retrievable" do
29
- stub_request(:get, "#{Stripe.uploads_base}/v1/files/file_123").
30
- to_return(body: JSON.generate(FIXTURE))
27
+ stub_request(:get, "#{Stripe.uploads_base}/v1/files/file_123")
28
+ .to_return(body: JSON.generate(FIXTURE))
31
29
 
32
30
  file = Stripe::FileUpload.retrieve("file_123")
33
- assert file.kind_of?(Stripe::FileUpload)
31
+ assert file.is_a?(Stripe::FileUpload)
34
32
  end
35
33
 
36
34
  should "be creatable" do
37
- stub_request(:post, "#{Stripe.uploads_base}/v1/files").
38
- with(:headers => {
39
- "Content-Type" => %r|\A#{Faraday::Request::Multipart.mime_type}|
40
- }) { |request|
41
- request.body =~ /FileUploadTest/
42
- }.to_return(body: JSON.generate(FIXTURE))
35
+ stub_request(:post, "#{Stripe.uploads_base}/v1/files")
36
+ .with(headers: {
37
+ "Content-Type" => /\A#{Faraday::Request::Multipart.mime_type}/,
38
+ }) do |request|
39
+ request.body =~ /FileUploadTest/
40
+ end.to_return(body: JSON.generate(FIXTURE))
43
41
 
44
42
  file = Stripe::FileUpload.create(
45
43
  purpose: "dispute_evidence",
46
- file: File.new(__FILE__),
44
+ file: File.new(__FILE__)
47
45
  )
48
- assert file.kind_of?(Stripe::FileUpload)
46
+ assert file.is_a?(Stripe::FileUpload)
49
47
  end
50
48
 
51
49
  should "be creatable with Faraday::UploadIO" do
52
- stub_request(:post, "#{Stripe.uploads_base}/v1/files").
53
- with(:headers => {
54
- "Content-Type" => %r|\A#{Faraday::Request::Multipart.mime_type}|
55
- }) { |request|
56
- request.body =~ /FileUploadTest/
57
- }.to_return(body: JSON.generate(FIXTURE))
50
+ stub_request(:post, "#{Stripe.uploads_base}/v1/files")
51
+ .with(headers: {
52
+ "Content-Type" => /\A#{Faraday::Request::Multipart.mime_type}/,
53
+ }) do |request|
54
+ request.body =~ /FileUploadTest/
55
+ end.to_return(body: JSON.generate(FIXTURE))
58
56
 
59
57
  file = Stripe::FileUpload.create(
60
58
  purpose: "dispute_evidence",
61
- file: Faraday::UploadIO.new(File.new(__FILE__), nil),
59
+ file: Faraday::UploadIO.new(File.new(__FILE__), nil)
62
60
  )
63
- assert file.kind_of?(Stripe::FileUpload)
61
+ assert file.is_a?(Stripe::FileUpload)
64
62
  end
65
63
  end
66
64
  end
@@ -1,19 +1,19 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class InvoiceItemTest < Test::Unit::TestCase
5
5
  should "be listable" do
6
6
  invoiceitems = Stripe::InvoiceItem.list
7
7
  assert_requested :get, "#{Stripe.api_base}/v1/invoiceitems"
8
- assert invoiceitems.data.kind_of?(Array)
9
- assert invoiceitems.first.kind_of?(Stripe::InvoiceItem)
8
+ assert invoiceitems.data.is_a?(Array)
9
+ assert invoiceitems.first.is_a?(Stripe::InvoiceItem)
10
10
  end
11
11
 
12
12
  should "be retrievable" do
13
13
  item = Stripe::InvoiceItem.retrieve("ii_123")
14
14
  assert_requested :get,
15
- "#{Stripe.api_base}/v1/invoiceitems/ii_123"
16
- assert item.kind_of?(Stripe::InvoiceItem)
15
+ "#{Stripe.api_base}/v1/invoiceitems/ii_123"
16
+ assert item.is_a?(Stripe::InvoiceItem)
17
17
  end
18
18
 
19
19
  should "be creatable" do
@@ -23,31 +23,31 @@ module Stripe
23
23
  customer: "cus_123"
24
24
  )
25
25
  assert_requested :post,
26
- "#{Stripe.api_base}/v1/invoiceitems"
27
- assert item.kind_of?(Stripe::InvoiceItem)
26
+ "#{Stripe.api_base}/v1/invoiceitems"
27
+ assert item.is_a?(Stripe::InvoiceItem)
28
28
  end
29
29
 
30
30
  should "be saveable" do
31
31
  item = Stripe::InvoiceItem.retrieve("ii_123")
32
- item.metadata['key'] = 'value'
32
+ item.metadata["key"] = "value"
33
33
  item.save
34
34
  assert_requested :post,
35
- "#{Stripe.api_base}/v1/invoiceitems/#{item.id}"
35
+ "#{Stripe.api_base}/v1/invoiceitems/#{item.id}"
36
36
  end
37
37
 
38
38
  should "be updateable" do
39
- item = Stripe::InvoiceItem.update("ii_123", metadata: { key: 'value' })
39
+ item = Stripe::InvoiceItem.update("ii_123", metadata: { key: "value" })
40
40
  assert_requested :post,
41
- "#{Stripe.api_base}/v1/invoiceitems/ii_123"
42
- assert item.kind_of?(Stripe::InvoiceItem)
41
+ "#{Stripe.api_base}/v1/invoiceitems/ii_123"
42
+ assert item.is_a?(Stripe::InvoiceItem)
43
43
  end
44
44
 
45
45
  should "be deletable" do
46
46
  item = Stripe::InvoiceItem.retrieve("ii_123")
47
47
  item = item.delete
48
48
  assert_requested :delete,
49
- "#{Stripe.api_base}/v1/invoiceitems/#{item.id}"
50
- assert item.kind_of?(Stripe::InvoiceItem)
49
+ "#{Stripe.api_base}/v1/invoiceitems/#{item.id}"
50
+ assert item.is_a?(Stripe::InvoiceItem)
51
51
  end
52
52
  end
53
53
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class InvoiceLineItemTest < Test::Unit::TestCase
@@ -1,39 +1,39 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class InvoiceTest < Test::Unit::TestCase
5
5
  should "be listable" do
6
6
  invoices = Stripe::Invoice.list
7
7
  assert_requested :get, "#{Stripe.api_base}/v1/invoices"
8
- assert invoices.data.kind_of?(Array)
9
- assert invoices.first.kind_of?(Stripe::Invoice)
8
+ assert invoices.data.is_a?(Array)
9
+ assert invoices.first.is_a?(Stripe::Invoice)
10
10
  end
11
11
 
12
12
  should "be retrievable" do
13
13
  invoice = Stripe::Invoice.retrieve("in_123")
14
14
  assert_requested :get, "#{Stripe.api_base}/v1/invoices/in_123"
15
- assert invoice.kind_of?(Stripe::Invoice)
15
+ assert invoice.is_a?(Stripe::Invoice)
16
16
  end
17
17
 
18
18
  should "be creatable" do
19
19
  invoice = Stripe::Invoice.create(
20
- :customer => "cus_123"
20
+ customer: "cus_123"
21
21
  )
22
22
  assert_requested :post, "#{Stripe.api_base}/v1/invoices"
23
- assert invoice.kind_of?(Stripe::Invoice)
23
+ assert invoice.is_a?(Stripe::Invoice)
24
24
  end
25
25
 
26
26
  should "be saveable" do
27
27
  invoice = Stripe::Invoice.retrieve("in_123")
28
- invoice.metadata['key'] = 'value'
28
+ invoice.metadata["key"] = "value"
29
29
  invoice.save
30
30
  assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{invoice.id}"
31
31
  end
32
32
 
33
33
  should "be updateable" do
34
- invoice = Stripe::Invoice.update("in_123", metadata: { key: 'value' })
34
+ invoice = Stripe::Invoice.update("in_123", metadata: { key: "value" })
35
35
  assert_requested :post, "#{Stripe.api_base}/v1/invoices/in_123"
36
- assert invoice.kind_of?(Stripe::Invoice)
36
+ assert invoice.is_a?(Stripe::Invoice)
37
37
  end
38
38
 
39
39
  context "#pay" do
@@ -41,21 +41,21 @@ module Stripe
41
41
  invoice = Stripe::Invoice.retrieve("in_123")
42
42
  invoice = invoice.pay
43
43
  assert_requested :post,
44
- "#{Stripe.api_base}/v1/invoices/#{invoice.id}/pay"
45
- assert invoice.kind_of?(Stripe::Invoice)
44
+ "#{Stripe.api_base}/v1/invoices/#{invoice.id}/pay"
45
+ assert invoice.is_a?(Stripe::Invoice)
46
46
  end
47
47
 
48
48
  should "pay invoice with a specific source" do
49
49
  invoice = Stripe::Invoice.retrieve("in_123")
50
50
  invoice = invoice.pay(
51
- source: 'src_123',
51
+ source: "src_123"
52
52
  )
53
53
  assert_requested :post,
54
- "#{Stripe.api_base}/v1/invoices/#{invoice.id}/pay",
55
- body: {
56
- source: 'src_123',
57
- }
58
- assert invoice.kind_of?(Stripe::Invoice)
54
+ "#{Stripe.api_base}/v1/invoices/#{invoice.id}/pay",
55
+ body: {
56
+ source: "src_123",
57
+ }
58
+ assert invoice.is_a?(Stripe::Invoice)
59
59
  end
60
60
  end
61
61
 
@@ -66,18 +66,18 @@ module Stripe
66
66
  subscription: "sub_123"
67
67
  )
68
68
  assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
69
- query: {
70
- customer: "cus_123",
71
- subscription: "sub_123"
72
- }
73
- assert invoice.kind_of?(Stripe::Invoice)
69
+ query: {
70
+ customer: "cus_123",
71
+ subscription: "sub_123",
72
+ }
73
+ assert invoice.is_a?(Stripe::Invoice)
74
74
  end
75
75
 
76
76
  should "retrieve upcoming invoices with items" do
77
77
  items = [{
78
- plan: 'gold',
79
- quantity: 2
80
- }]
78
+ plan: "gold",
79
+ quantity: 2,
80
+ },]
81
81
 
82
82
  invoice = Stripe::Invoice.upcoming(
83
83
  customer: "cus_123",
@@ -85,25 +85,25 @@ module Stripe
85
85
  )
86
86
 
87
87
  assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
88
- query: {
89
- customer: "cus_123",
90
- :'subscription_items[][plan]' => 'gold',
91
- :'subscription_items[][quantity]' => 2
92
- }
93
- assert invoice.kind_of?(Stripe::Invoice)
88
+ query: {
89
+ customer: "cus_123",
90
+ :'subscription_items[][plan]' => "gold",
91
+ :'subscription_items[][quantity]' => 2,
92
+ }
93
+ assert invoice.is_a?(Stripe::Invoice)
94
94
  end
95
95
 
96
96
  should "be callable with an empty string" do
97
97
  invoice = Stripe::Invoice.upcoming(
98
- coupon: '',
98
+ coupon: "",
99
99
  customer: "cus_123"
100
100
  )
101
101
  assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
102
- query: {
103
- coupon: '',
104
- customer: "cus_123"
105
- }
106
- assert invoice.kind_of?(Stripe::Invoice)
102
+ query: {
103
+ coupon: "",
104
+ customer: "cus_123",
105
+ }
106
+ assert invoice.is_a?(Stripe::Invoice)
107
107
  end
108
108
  end
109
109
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ListObjectTest < Test::Unit::TestCase
@@ -8,59 +8,53 @@ module Stripe
8
8
  end
9
9
 
10
10
  should "provide #count via enumerable" do
11
- list = Stripe::ListObject.construct_from({
12
- data: [{ object: "charge" }]
13
- })
11
+ list = Stripe::ListObject.construct_from(data: [{ object: "charge" }])
14
12
  assert_equal 1, list.count
15
13
  end
16
14
 
17
15
  should "provide #each" do
18
16
  arr = [
19
- { :id => 1 },
20
- { :id => 2 },
21
- { :id => 3 },
17
+ { id: 1 },
18
+ { id: 2 },
19
+ { id: 3 },
22
20
  ]
23
21
  expected = Util.convert_to_stripe_object(arr, {})
24
- list = Stripe::ListObject.construct_from({ :data => arr })
22
+ list = Stripe::ListObject.construct_from(data: arr)
25
23
  assert_equal expected, list.each.to_a
26
24
  end
27
25
 
28
26
  should "provide #auto_paging_each" do
29
27
  arr = [
30
- { :id => 1 },
31
- { :id => 2 },
32
- { :id => 3 },
28
+ { id: 1 },
29
+ { id: 2 },
30
+ { id: 3 },
33
31
  ]
34
32
  expected = Util.convert_to_stripe_object(arr, {})
35
33
 
36
- list = TestListObject.construct_from({
37
- :data => [{ :id => 1 }],
38
- :has_more => true,
39
- :url => "/things",
40
- })
41
- stub_request(:get, "#{Stripe.api_base}/things").
42
- with(query: { starting_after: "1" }).
43
- to_return(body: JSON.generate({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
34
+ list = TestListObject.construct_from(data: [{ id: 1 }],
35
+ has_more: true,
36
+ url: "/things")
37
+ stub_request(:get, "#{Stripe.api_base}/things")
38
+ .with(query: { starting_after: "1" })
39
+ .to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false))
44
40
 
45
41
  assert_equal expected, list.auto_paging_each.to_a
46
42
  end
47
43
 
48
44
  should "provide #auto_paging_each that responds to a block" do
49
45
  arr = [
50
- { :id => 1 },
51
- { :id => 2 },
52
- { :id => 3 },
46
+ { id: 1 },
47
+ { id: 2 },
48
+ { id: 3 },
53
49
  ]
54
50
  expected = Util.convert_to_stripe_object(arr, {})
55
51
 
56
- list = TestListObject.construct_from({
57
- :data => [{ :id => 1 }],
58
- :has_more => true,
59
- :url => "/things",
60
- })
61
- stub_request(:get, "#{Stripe.api_base}/things").
62
- with(query: { starting_after: "1" }).
63
- to_return(body: JSON.generate({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
52
+ list = TestListObject.construct_from(data: [{ id: 1 }],
53
+ has_more: true,
54
+ url: "/things")
55
+ stub_request(:get, "#{Stripe.api_base}/things")
56
+ .with(query: { starting_after: "1" })
57
+ .to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false))
64
58
 
65
59
  actual = []
66
60
  list.auto_paging_each do |obj|
@@ -71,9 +65,9 @@ module Stripe
71
65
  end
72
66
 
73
67
  should "provide #empty?" do
74
- list = Stripe::ListObject.construct_from({ :data => [] })
68
+ list = Stripe::ListObject.construct_from(data: [])
75
69
  assert list.empty?
76
- list = Stripe::ListObject.construct_from({ :data => [{}] })
70
+ list = Stripe::ListObject.construct_from(data: [{}])
77
71
  refute list.empty?
78
72
  end
79
73
 
@@ -82,38 +76,32 @@ module Stripe
82
76
  #
83
77
 
84
78
  should "fetch a next page through #next_page" do
85
- list = TestListObject.construct_from({
86
- :data => [{ :id => 1 }],
87
- :has_more => true,
88
- :url => "/things",
89
- })
90
- stub_request(:get, "#{Stripe.api_base}/things").
91
- with(query: { starting_after: "1" }).
92
- to_return(body: JSON.generate({ :data => [{ :id => 2 }], :has_more => false }))
79
+ list = TestListObject.construct_from(data: [{ id: 1 }],
80
+ has_more: true,
81
+ url: "/things")
82
+ stub_request(:get, "#{Stripe.api_base}/things")
83
+ .with(query: { starting_after: "1" })
84
+ .to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
93
85
  next_list = list.next_page
94
86
  refute next_list.empty?
95
87
  end
96
88
 
97
89
  should "fetch a next page through #next_page and respect limit" do
98
- list = TestListObject.construct_from({
99
- :data => [{ :id => 1 }],
100
- :has_more => true,
101
- :url => "/things",
102
- })
103
- list.filters = { :expand => ['data.source'], :limit => 3 }
104
- stub_request(:get, "#{Stripe.api_base}/things").
105
- with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" }).
106
- to_return(body: JSON.generate({ :data => [{ :id => 2 }], :has_more => false }))
90
+ list = TestListObject.construct_from(data: [{ id: 1 }],
91
+ has_more: true,
92
+ url: "/things")
93
+ list.filters = { expand: ["data.source"], limit: 3 }
94
+ stub_request(:get, "#{Stripe.api_base}/things")
95
+ .with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" })
96
+ .to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
107
97
  next_list = list.next_page
108
- assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
98
+ assert_equal({ expand: ["data.source"], limit: 3 }, next_list.filters)
109
99
  end
110
100
 
111
101
  should "fetch an empty page through #next_page" do
112
- list = TestListObject.construct_from({
113
- :data => [{ :id => 1 }],
114
- :has_more => false,
115
- :url => "/things",
116
- })
102
+ list = TestListObject.construct_from(data: [{ id: 1 }],
103
+ has_more: false,
104
+ url: "/things")
117
105
  next_list = list.next_page
118
106
  assert_equal Stripe::ListObject.empty_list, next_list
119
107
  end
@@ -123,28 +111,24 @@ module Stripe
123
111
  #
124
112
 
125
113
  should "fetch a next page through #previous_page" do
126
- list = TestListObject.construct_from({
127
- :data => [{ :id => 2 }],
128
- :url => "/things",
129
- })
130
- stub_request(:get, "#{Stripe.api_base}/things").
131
- with(query: { ending_before: "2" }).
132
- to_return(body: JSON.generate({ :data => [{ :id => 1 }] }))
114
+ list = TestListObject.construct_from(data: [{ id: 2 }],
115
+ url: "/things")
116
+ stub_request(:get, "#{Stripe.api_base}/things")
117
+ .with(query: { ending_before: "2" })
118
+ .to_return(body: JSON.generate(data: [{ id: 1 }]))
133
119
  next_list = list.previous_page
134
120
  refute next_list.empty?
135
121
  end
136
122
 
137
123
  should "fetch a next page through #previous_page and respect limit" do
138
- list = TestListObject.construct_from({
139
- :data => [{ :id => 2 }],
140
- :url => "/things",
141
- })
142
- list.filters = { :expand => ['data.source'], :limit => 3 }
143
- stub_request(:get, "#{Stripe.api_base}/things").
144
- with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" }).
145
- to_return(body: JSON.generate({ :data => [{ :id => 1 }] }))
124
+ list = TestListObject.construct_from(data: [{ id: 2 }],
125
+ url: "/things")
126
+ list.filters = { expand: ["data.source"], limit: 3 }
127
+ stub_request(:get, "#{Stripe.api_base}/things")
128
+ .with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" })
129
+ .to_return(body: JSON.generate(data: [{ id: 1 }]))
146
130
  next_list = list.previous_page
147
- assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
131
+ assert_equal({ expand: ["data.source"], limit: 3 }, next_list.filters)
148
132
  end
149
133
 
150
134
  #
@@ -155,12 +139,12 @@ module Stripe
155
139
  # in a list
156
140
  should "be able to retrieve full lists given a listobject" do
157
141
  c = Stripe::Charge.all
158
- assert c.kind_of?(Stripe::ListObject)
159
- assert_equal('/v1/charges', c.resource_url)
142
+ assert c.is_a?(Stripe::ListObject)
143
+ assert_equal("/v1/charges", c.resource_url)
160
144
  all = c.all
161
- assert all.kind_of?(Stripe::ListObject)
162
- assert_equal('/v1/charges', all.resource_url)
163
- assert all.data.kind_of?(Array)
145
+ assert all.is_a?(Stripe::ListObject)
146
+ assert_equal("/v1/charges", all.resource_url)
147
+ assert all.data.is_a?(Array)
164
148
  end
165
149
  end
166
150
  end