stripe-ruby-mock 2.5.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +6 -6
  4. data/README.md +8 -8
  5. data/lib/stripe_mock.rb +3 -0
  6. data/lib/stripe_mock/api/errors.rb +31 -28
  7. data/lib/stripe_mock/api/webhooks.rb +3 -0
  8. data/lib/stripe_mock/data.rb +140 -13
  9. data/lib/stripe_mock/instance.rb +10 -3
  10. data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
  11. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +1 -1
  12. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
  13. data/lib/stripe_mock/request_handlers/invoices.rb +6 -1
  14. data/lib/stripe_mock/request_handlers/payment_intents.rb +175 -0
  15. data/lib/stripe_mock/request_handlers/payment_methods.rb +138 -0
  16. data/lib/stripe_mock/request_handlers/products.rb +1 -0
  17. data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
  18. data/lib/stripe_mock/request_handlers/subscriptions.rb +17 -4
  19. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +95 -9
  20. data/lib/stripe_mock/test_strategies/base.rb +42 -8
  21. data/lib/stripe_mock/test_strategies/live.rb +23 -12
  22. data/lib/stripe_mock/test_strategies/mock.rb +6 -2
  23. data/lib/stripe_mock/version.rb +1 -1
  24. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +166 -38
  25. data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
  26. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
  27. data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
  28. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
  29. data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
  30. data/spec/instance_spec.rb +6 -6
  31. data/spec/server_spec.rb +2 -1
  32. data/spec/shared_stripe_examples/account_examples.rb +1 -1
  33. data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
  34. data/spec/shared_stripe_examples/bank_examples.rb +3 -3
  35. data/spec/shared_stripe_examples/card_examples.rb +4 -4
  36. data/spec/shared_stripe_examples/charge_examples.rb +9 -22
  37. data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
  38. data/spec/shared_stripe_examples/customer_examples.rb +44 -30
  39. data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
  40. data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
  41. data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
  42. data/spec/shared_stripe_examples/invoice_examples.rb +41 -39
  43. data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
  44. data/spec/shared_stripe_examples/payment_intent_examples.rb +137 -0
  45. data/spec/shared_stripe_examples/payment_method_examples.rb +185 -0
  46. data/spec/shared_stripe_examples/payout_examples.rb +2 -2
  47. data/spec/shared_stripe_examples/plan_examples.rb +135 -92
  48. data/spec/shared_stripe_examples/product_examples.rb +155 -0
  49. data/spec/shared_stripe_examples/refund_examples.rb +25 -21
  50. data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
  51. data/spec/shared_stripe_examples/subscription_examples.rb +281 -310
  52. data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
  53. data/spec/shared_stripe_examples/transfer_examples.rb +6 -6
  54. data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
  55. data/spec/spec_helper.rb +3 -4
  56. data/spec/stripe_mock_spec.rb +2 -2
  57. data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
  58. data/spec/support/stripe_examples.rb +3 -0
  59. data/stripe-ruby-mock.gemspec +2 -2
  60. metadata +47 -27
  61. data/spec/shared_stripe_examples/product_example.rb +0 -65
@@ -15,6 +15,7 @@
15
15
  "delinquent": true,
16
16
  "metadata": {
17
17
  },
18
+ "preferred_locales": [],
18
19
  "subscription": null,
19
20
  "discount": null,
20
21
  "account_balance": 0,
@@ -15,6 +15,7 @@
15
15
  "delinquent": true,
16
16
  "metadata": {
17
17
  },
18
+ "preferred_locales": [],
18
19
  "subscription": null,
19
20
  "discount": null,
20
21
  "account_balance": 0,
@@ -0,0 +1,34 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "product.created",
6
+ "object": "event",
7
+ "data": {
8
+ "object": {
9
+ "id": "prod_00000000000000",
10
+ "object": "product",
11
+ "active": true,
12
+ "attributes": [
13
+ ],
14
+ "caption": null,
15
+ "created": 1558795883,
16
+ "deactivate_on": [
17
+ ],
18
+ "description": null,
19
+ "images": [
20
+ ],
21
+ "livemode": false,
22
+ "metadata": {
23
+ },
24
+ "name": "Test Product",
25
+ "package_dimensions": null,
26
+ "shippable": null,
27
+ "statement_descriptor": null,
28
+ "type": "service",
29
+ "unit_label": null,
30
+ "updated": 1558795883,
31
+ "url": null
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "product.deleted",
6
+ "object": "event",
7
+ "data": {
8
+ "object": {
9
+ "id": "prod_00000000000000",
10
+ "object": "product",
11
+ "active": true,
12
+ "attributes": [
13
+ ],
14
+ "caption": null,
15
+ "created": 1558795883,
16
+ "deactivate_on": [
17
+ ],
18
+ "description": null,
19
+ "images": [
20
+ ],
21
+ "livemode": false,
22
+ "metadata": {
23
+ },
24
+ "name": "Test Product",
25
+ "package_dimensions": null,
26
+ "shippable": null,
27
+ "statement_descriptor": null,
28
+ "type": "service",
29
+ "unit_label": null,
30
+ "updated": 1558795883,
31
+ "url": null
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "product.updated",
6
+ "object": "event",
7
+ "data": {
8
+ "object": {
9
+ "id": "prod_00000000000000",
10
+ "object": "product",
11
+ "active": true,
12
+ "attributes": [
13
+ ],
14
+ "caption": null,
15
+ "created": 1558795883,
16
+ "deactivate_on": [
17
+ ],
18
+ "description": null,
19
+ "images": [
20
+ ],
21
+ "livemode": false,
22
+ "metadata": {
23
+ },
24
+ "name": "Test Product",
25
+ "package_dimensions": null,
26
+ "shippable": null,
27
+ "statement_descriptor": null,
28
+ "type": "service",
29
+ "unit_label": null,
30
+ "updated": 1558795883,
31
+ "url": null
32
+ },
33
+ "previous_attributes": {
34
+ "name": "Product Test",
35
+ "updated": 1558873981
36
+ }
37
+ }
38
+ }
@@ -13,13 +13,13 @@ describe StripeMock::Instance do
13
13
  after { StripeMock.stop }
14
14
 
15
15
  it "handles both string and symbol hash keys" do
16
- string_params = stripe_helper.create_plan_params(
17
- "id" => "str_abcde",
18
- :name => "String Plan"
16
+ symbol_params = stripe_helper.create_product_params(
17
+ :name => "Symbol Product",
18
+ "type" => "service"
19
19
  )
20
- res, api_key = StripeMock.instance.mock_request('post', '/v1/plans', api_key: 'api_key', params: string_params)
21
- expect(res.data[:id]).to eq('str_abcde')
22
- expect(res.data[:name]).to eq('String Plan')
20
+ res, api_key = StripeMock.instance.mock_request('post', '/v1/products', api_key: 'api_key', params: symbol_params)
21
+ expect(res.data[:name]).to eq('Symbol Product')
22
+ expect(res.data[:type]).to eq('service')
23
23
  end
24
24
 
25
25
  it "exits gracefully on an unrecognized handler url" do
@@ -19,6 +19,7 @@ describe 'StripeMock Server', :mock_server => true do
19
19
 
20
20
  after { StripeMock.stop_client(:clear_server_data => true) }
21
21
 
22
+ let(:product) { stripe_helper.create_product }
22
23
 
23
24
  it "uses an RPC client for mock requests" do
24
25
  charge = Stripe::Charge.create(
@@ -51,7 +52,7 @@ describe 'StripeMock Server', :mock_server => true do
51
52
 
52
53
 
53
54
  it "returns a response with symbolized hash keys" do
54
- stripe_helper.create_plan(id: 'x')
55
+ stripe_helper.create_plan(id: 'x', product: product.id)
55
56
  response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
56
57
  response.data.keys.each {|k| expect(k).to be_a(Symbol) }
57
58
  end
@@ -15,7 +15,7 @@ shared_examples 'Account API' do
15
15
  expect(account.id).to match /acct\_/
16
16
  end
17
17
  it 'retrieves all' do
18
- accounts = Stripe::Account.all
18
+ accounts = Stripe::Account.list
19
19
 
20
20
  expect(accounts).to be_a Stripe::ListObject
21
21
  expect(accounts.data.count).to satisfy { |n| n >= 1 }
@@ -26,7 +26,7 @@ shared_examples 'Balance Transaction API' do
26
26
  describe "listing balance transactions" do
27
27
 
28
28
  it "retrieves all balance transactions" do
29
- disputes = Stripe::BalanceTransaction.all
29
+ disputes = Stripe::BalanceTransaction.list
30
30
 
31
31
  expect(disputes.count).to eq(10)
32
32
  expect(disputes.map &:id).to include('txn_05RsQX2eZvKYlo2C0FRTGSSA','txn_15RsQX2eZvKYlo2C0ERTYUIA', 'txn_25RsQX2eZvKYlo2C0ZXCVBNM', 'txn_35RsQX2eZvKYlo2C0QAZXSWE', 'txn_45RsQX2eZvKYlo2C0EDCVFRT', 'txn_55RsQX2eZvKYlo2C0OIKLJUY', 'txn_65RsQX2eZvKYlo2C0ASDFGHJ', 'txn_75RsQX2eZvKYlo2C0EDCXSWQ', 'txn_85RsQX2eZvKYlo2C0UJMCDET', 'txn_95RsQX2eZvKYlo2C0EDFRYUI')
@@ -38,7 +38,7 @@ shared_examples 'Balance Transaction API' do
38
38
  transfer_id = Stripe::Transfer.create({ amount: 2730, currency: "usd" })
39
39
 
40
40
  # verify transfer currently has no balance transactions
41
- transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id})
41
+ transfer_transactions = Stripe::BalanceTransaction.list({transfer: transfer_id})
42
42
  expect(transfer_transactions.count).to eq(0)
43
43
 
44
44
  # verify we can create a new balance transaction associated with the transfer
@@ -55,7 +55,7 @@ shared_examples 'Balance Transaction API' do
55
55
  stripe_helper.upsert_stripe_object(:balance_transaction, {id: existing_txn_id, transfer: transfer_id})
56
56
 
57
57
  # now verify that only these balance transactions are retrieved with the transfer
58
- transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id})
58
+ transfer_transactions = Stripe::BalanceTransaction.list({transfer: transfer_id})
59
59
  expect(transfer_transactions.count).to eq(2)
60
60
  expect(transfer_transactions.map &:id).to include(new_txn_id, existing_txn_id)
61
61
  end
@@ -77,7 +77,7 @@ shared_examples 'Bank API' do
77
77
  let!(:bank) { customer.sources.create(source: bank_token) }
78
78
 
79
79
  it "can retrieve all customer's banks" do
80
- retrieved = customer.sources.all
80
+ retrieved = customer.sources.list
81
81
  expect(retrieved.count).to eq(1)
82
82
  end
83
83
 
@@ -174,7 +174,7 @@ shared_examples 'Bank API' do
174
174
 
175
175
  customer = Stripe::Customer.retrieve('test_customer_bank')
176
176
 
177
- list = customer.sources.all
177
+ list = customer.sources.list
178
178
 
179
179
  expect(list.object).to eq("list")
180
180
  expect(list.count).to eq(2)
@@ -191,7 +191,7 @@ shared_examples 'Bank API' do
191
191
  Stripe::Customer.create(id: 'no_banks')
192
192
  customer = Stripe::Customer.retrieve('no_banks')
193
193
 
194
- list = customer.sources.all
194
+ list = customer.sources.list
195
195
 
196
196
  expect(list.object).to eq("list")
197
197
  expect(list.count).to eq(0)
@@ -134,7 +134,7 @@ shared_examples 'Card API' do
134
134
  let!(:card) { customer.sources.create(source: card_token) }
135
135
 
136
136
  it "can retrieve all customer's cards" do
137
- retrieved = customer.sources.all
137
+ retrieved = customer.sources.list
138
138
  expect(retrieved.count).to eq(1)
139
139
  end
140
140
 
@@ -198,7 +198,7 @@ shared_examples 'Card API' do
198
198
  let!(:card) { recipient.cards.create(card: card_token) }
199
199
 
200
200
  it "can retrieve all recipient's cards" do
201
- retrieved = recipient.cards.all
201
+ retrieved = recipient.cards.list
202
202
  expect(retrieved.count).to eq(1)
203
203
  end
204
204
 
@@ -279,7 +279,7 @@ shared_examples 'Card API' do
279
279
 
280
280
  customer = Stripe::Customer.retrieve('test_customer_card')
281
281
 
282
- list = customer.sources.all
282
+ list = customer.sources.list
283
283
 
284
284
  expect(list.object).to eq("list")
285
285
  expect(list.count).to eq(2)
@@ -296,7 +296,7 @@ shared_examples 'Card API' do
296
296
  Stripe::Customer.create(id: 'no_cards')
297
297
  customer = Stripe::Customer.retrieve('no_cards')
298
298
 
299
- list = customer.sources.all
299
+ list = customer.sources.list
300
300
 
301
301
  expect(list.object).to eq("list")
302
302
  expect(list.count).to eq(0)
@@ -278,20 +278,6 @@ shared_examples 'Charge API' do
278
278
  }.not_to raise_error
279
279
  end
280
280
 
281
- it "marks a charge as safe" do
282
- original = Stripe::Charge.create({
283
- amount: 777,
284
- currency: 'USD',
285
- source: stripe_helper.generate_card_token
286
- })
287
- charge = Stripe::Charge.retrieve(original.id)
288
-
289
- charge.mark_as_safe
290
-
291
- updated = Stripe::Charge.retrieve(original.id)
292
- expect(updated.fraud_details[:user_report]).to eq "safe"
293
- end
294
-
295
281
  it "does not lose data when updating a charge" do
296
282
  original = Stripe::Charge.create({
297
283
  amount: 777,
@@ -357,28 +343,29 @@ shared_examples 'Charge API' do
357
343
  end
358
344
 
359
345
  it "stores charges for a customer in memory" do
360
- expect(@customer.charges.data.map(&:id)).to eq([@charge.id])
346
+ charges = Stripe::Charge.list(customer: @customer.id)
347
+ expect(charges.map(&:id)).to eq([@charge.id])
361
348
  end
362
349
 
363
350
  it "stores all charges in memory" do
364
- expect(Stripe::Charge.all.data.map(&:id).reverse).to eq([@charge.id, @charge2.id])
351
+ expect(Stripe::Charge.list.data.map(&:id).reverse).to eq([@charge.id, @charge2.id])
365
352
  end
366
353
 
367
354
  it "defaults count to 10 charges" do
368
355
  11.times { Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
369
356
 
370
- expect(Stripe::Charge.all.data.count).to eq(10)
357
+ expect(Stripe::Charge.list.data.count).to eq(10)
371
358
  end
372
359
 
373
360
  it "is marked as having more when more objects exist" do
374
361
  11.times { Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
375
362
 
376
- expect(Stripe::Charge.all.has_more).to eq(true)
363
+ expect(Stripe::Charge.list.has_more).to eq(true)
377
364
  end
378
365
 
379
366
  context "when passing limit" do
380
367
  it "gets that many charges" do
381
- expect(Stripe::Charge.all(limit: 1).count).to eq(1)
368
+ expect(Stripe::Charge.list(limit: 1).count).to eq(1)
382
369
  end
383
370
  end
384
371
  end
@@ -398,13 +385,13 @@ shared_examples 'Charge API' do
398
385
  Stripe::Charge.create(customer: cus.id, amount: 100, currency: "usd")
399
386
  end
400
387
 
401
- all = Stripe::Charge.all
388
+ all_charges = Stripe::Charge.list
402
389
  default_limit = 10
403
- half = Stripe::Charge.all(starting_after: all.data.at(1).id)
390
+ half = Stripe::Charge.list(starting_after: all_charges.data.at(1).id)
404
391
 
405
392
  expect(half).to be_a(Stripe::ListObject)
406
393
  expect(half.data.count).to eq(default_limit)
407
- expect(half.data.first.id).to eq(all.data.at(2).id)
394
+ expect(half.data.first.id).to eq(all_charges.data.at(2).id)
408
395
  end
409
396
 
410
397
 
@@ -53,7 +53,7 @@ shared_examples 'Coupon API' do
53
53
  coupon1
54
54
  coupon2
55
55
 
56
- all = Stripe::Coupon.all
56
+ all = Stripe::Coupon.list
57
57
 
58
58
  expect(all.count).to eq(2)
59
59
  expect(all.map &:id).to include('10BUCKS', '11BUCKS')
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  shared_examples 'Customer API' do
4
+ let(:product_params) { {id: "prod_CCC", name: "My Product", type: "service"} }
5
+ let(:product) { stripe_helper.create_product(product_params) }
4
6
 
5
7
  def gen_card_tk
6
8
  stripe_helper.generate_card_token
@@ -15,6 +17,7 @@ shared_examples 'Customer API' do
15
17
  expect(customer.id).to match(/^test_cus/)
16
18
  expect(customer.email).to eq('johnny@appleseed.com')
17
19
  expect(customer.description).to eq('a description')
20
+ expect(customer.preferred_locales).to eq([])
18
21
 
19
22
  expect(customer.sources.count).to eq(1)
20
23
  expect(customer.sources.data.length).to eq(1)
@@ -24,6 +27,17 @@ shared_examples 'Customer API' do
24
27
  expect { customer.source }.to raise_error
25
28
  end
26
29
 
30
+ it "creates a stripe customer with a default payment method" do
31
+ customer = Stripe::Customer.create({
32
+ email: 'johnny@appleseed.com',
33
+ invoice_settings: {
34
+ default_payment_method: "pm_1ExEuFL2DI6wht39WNJgbybl"
35
+ },
36
+ description: "a description"
37
+ })
38
+ expect(customer.invoice_settings.default_payment_method).to eq("pm_1ExEuFL2DI6wht39WNJgbybl")
39
+ end
40
+
27
41
  it "creates a stripe customer with multiple cards and updates the default card" do
28
42
  card_a = gen_card_tk
29
43
  card_b = gen_card_tk
@@ -88,7 +102,7 @@ shared_examples 'Customer API' do
88
102
  end
89
103
 
90
104
  it 'creates a customer with a plan' do
91
- plan = stripe_helper.create_plan(id: 'silver')
105
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id)
92
106
  customer = Stripe::Customer.create(id: 'test_cus_plan', source: gen_card_tk, :plan => 'silver')
93
107
 
94
108
  customer = Stripe::Customer.retrieve('test_cus_plan')
@@ -101,23 +115,29 @@ shared_examples 'Customer API' do
101
115
  end
102
116
 
103
117
  it "creates a customer with a plan (string/symbol agnostic)" do
104
- plan = stripe_helper.create_plan(id: 'string_id')
105
- customer = Stripe::Customer.create(id: 'test_cus_plan', source: gen_card_tk, :plan => :string_id)
118
+ stripe_helper.create_plan(id: 'silver', product: product.id)
106
119
 
107
- customer = Stripe::Customer.retrieve('test_cus_plan')
108
- expect(customer.subscriptions.first.plan.id).to eq('string_id')
109
-
110
- plan = stripe_helper.create_plan(:id => :sym_id)
111
- customer = Stripe::Customer.create(id: 'test_cus_plan', source: gen_card_tk, :plan => 'sym_id')
120
+ Stripe::Customer.create(id: 'cust_SLV1', source: gen_card_tk, :plan => 'silver')
121
+ customer = Stripe::Customer.retrieve('cust_SLV1')
122
+ expect(customer.subscriptions.count).to eq(1)
123
+ expect(customer.subscriptions.data.length).to eq(1)
124
+ expect(customer.subscriptions).to_not be_nil
125
+ expect(customer.subscriptions.first.plan.id).to eq('silver')
126
+ expect(customer.subscriptions.first.customer).to eq(customer.id)
112
127
 
113
- customer = Stripe::Customer.retrieve('test_cus_plan')
114
- expect(customer.subscriptions.first.plan.id).to eq('sym_id')
128
+ Stripe::Customer.create(id: 'cust_SLV2', source: gen_card_tk, :plan => :silver)
129
+ customer = Stripe::Customer.retrieve('cust_SLV2')
130
+ expect(customer.subscriptions.count).to eq(1)
131
+ expect(customer.subscriptions.data.length).to eq(1)
132
+ expect(customer.subscriptions).to_not be_nil
133
+ expect(customer.subscriptions.first.plan.id).to eq('silver')
134
+ expect(customer.subscriptions.first.customer).to eq(customer.id)
115
135
  end
116
136
 
117
137
  context "create customer" do
118
138
 
119
139
  it "with a trial when trial_end is set" do
120
- plan = stripe_helper.create_plan(id: 'no_trial', amount: 999)
140
+ plan = stripe_helper.create_plan(id: 'no_trial', product: product.id, amount: 999)
121
141
  trial_end = Time.now.utc.to_i + 3600
122
142
  customer = Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'no_trial', trial_end: trial_end)
123
143
 
@@ -133,7 +153,7 @@ shared_examples 'Customer API' do
133
153
  end
134
154
 
135
155
  it 'overrides trial period length when trial_end is set' do
136
- plan = stripe_helper.create_plan(id: 'silver', amount: 999, trial_period_days: 14)
156
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999, trial_period_days: 14)
137
157
  trial_end = Time.now.utc.to_i + 3600
138
158
  customer = Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: trial_end)
139
159
 
@@ -148,7 +168,7 @@ shared_examples 'Customer API' do
148
168
  end
149
169
 
150
170
  it 'creates a customer when trial_end is set and no source', live: true do
151
- plan = stripe_helper.create_plan(id: 'silver', amount: 999)
171
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999)
152
172
  trial_end = Time.now.utc.to_i + 3600
153
173
  customer = Stripe::Customer.create(plan: 'silver', trial_end: trial_end)
154
174
  expect(customer.subscriptions.count).to eq(1)
@@ -161,7 +181,7 @@ shared_examples 'Customer API' do
161
181
  end
162
182
 
163
183
  it "returns no trial when trial_end is set to 'now'" do
164
- plan = stripe_helper.create_plan(id: 'silver', amount: 999, trial_period_days: 14)
184
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999, trial_period_days: 14)
165
185
  customer = Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: "now")
166
186
 
167
187
  customer = Stripe::Customer.retrieve('test_cus_trial_end')
@@ -176,7 +196,7 @@ shared_examples 'Customer API' do
176
196
  end
177
197
 
178
198
  it "returns an error if trial_end is set to a past time" do
179
- plan = stripe_helper.create_plan(id: 'silver', amount: 999)
199
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999)
180
200
  expect {
181
201
  Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: Time.now.utc.to_i - 3600)
182
202
  }.to raise_error {|e|
@@ -206,7 +226,7 @@ shared_examples 'Customer API' do
206
226
  end
207
227
 
208
228
  it 'cannot create a customer with an existing plan, but no card token' do
209
- plan = stripe_helper.create_plan(id: 'p')
229
+ plan = stripe_helper.create_plan(id: 'p', product: product.id)
210
230
  expect {
211
231
  customer = Stripe::Customer.create(id: 'test_cus_no_plan', :plan => 'p')
212
232
  }.to raise_error {|e|
@@ -235,7 +255,7 @@ shared_examples 'Customer API' do
235
255
  discount = Stripe::Customer.retrieve(customer.id).discount
236
256
  expect(discount).to_not be_nil
237
257
  expect(discount.coupon).to_not be_nil
238
- expect(discount.end).to be_within(1).of (Time.now.to_datetime >> 12).to_time.to_i
258
+ expect(discount.end).to be_within(10).of (DateTime.now >> 12).to_time.to_i
239
259
  end
240
260
  after { Stripe::Coupon.retrieve(coupon.id).delete }
241
261
  after { Stripe::Customer.retrieve(customer.id).delete }
@@ -307,7 +327,7 @@ shared_examples 'Customer API' do
307
327
  Stripe::Customer.create({ email: 'one@one.com' })
308
328
  Stripe::Customer.create({ email: 'two@two.com' })
309
329
 
310
- all = Stripe::Customer.all
330
+ all = Stripe::Customer.list
311
331
  expect(all.count).to eq(2)
312
332
  expect(all.map &:email).to include('one@one.com', 'two@two.com')
313
333
  end
@@ -317,8 +337,9 @@ shared_examples 'Customer API' do
317
337
  email = original.email
318
338
 
319
339
  coupon = Stripe::Coupon.create(id: "10PERCENT", duration: 'once')
320
- original.description = 'new desc'
321
- original.coupon = coupon.id
340
+ original.description = 'new desc'
341
+ original.preferred_locales = %w(fr en)
342
+ original.coupon = coupon.id
322
343
  original.save
323
344
 
324
345
  expect(original.email).to eq(email)
@@ -328,6 +349,7 @@ shared_examples 'Customer API' do
328
349
  customer = Stripe::Customer.retrieve("test_customer_update")
329
350
  expect(customer.email).to eq(original.email)
330
351
  expect(customer.description).to eq('new desc')
352
+ expect(customer.preferred_locales).to eq(%w(fr en))
331
353
  expect(customer.discount.coupon).to be_a Stripe::Coupon
332
354
  end
333
355
 
@@ -391,7 +413,7 @@ shared_examples 'Customer API' do
391
413
  end
392
414
 
393
415
  it "still has subscriptions after save when subscriptions unchanged" do
394
- plan = stripe_helper.create_plan(id: 'silver')
416
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id)
395
417
  original = Stripe::Customer.create(source: gen_card_tk, plan: 'silver')
396
418
  subscription = original.subscriptions.data.first
397
419
  subscription_id = subscription.id
@@ -404,7 +426,7 @@ shared_examples 'Customer API' do
404
426
  end
405
427
 
406
428
  it "should add a customer to a subscription" do
407
- plan = stripe_helper.create_plan(id: 'silver')
429
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id)
408
430
  customer = Stripe::Customer.create(source: gen_card_tk)
409
431
  customer.subscriptions.create(plan: plan.id)
410
432
 
@@ -417,14 +439,6 @@ shared_examples 'Customer API' do
417
439
  expect(customer.deleted).to eq(true)
418
440
  end
419
441
 
420
- it 'works with the update_subscription method' do
421
- stripe_helper.create_plan(id: 'silver')
422
- cus = Stripe::Customer.create(source: gen_card_tk)
423
- expect {
424
- cus.update_subscription(plan: 'silver')
425
- }.not_to raise_error
426
- end
427
-
428
442
  it "deletes a stripe customer discount" do
429
443
  original = Stripe::Customer.create(id: 'test_customer_update')
430
444