stripe-ruby-mock 2.4.1 → 2.5.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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -4
  3. data/README.md +10 -4
  4. data/lib/stripe_mock/api/client.rb +3 -3
  5. data/lib/stripe_mock/api/errors.rb +25 -14
  6. data/lib/stripe_mock/api/instance.rb +4 -4
  7. data/lib/stripe_mock/api/webhooks.rb +1 -1
  8. data/lib/stripe_mock/client.rb +2 -2
  9. data/lib/stripe_mock/data.rb +51 -26
  10. data/lib/stripe_mock/instance.rb +7 -3
  11. data/lib/stripe_mock/request_handlers/charges.rb +6 -6
  12. data/lib/stripe_mock/request_handlers/coupons.rb +3 -2
  13. data/lib/stripe_mock/request_handlers/customers.rb +16 -7
  14. data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +2 -2
  15. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +6 -1
  16. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +5 -5
  17. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -2
  18. data/lib/stripe_mock/request_handlers/invoices.rb +63 -11
  19. data/lib/stripe_mock/request_handlers/orders.rb +4 -4
  20. data/lib/stripe_mock/request_handlers/refunds.rb +3 -3
  21. data/lib/stripe_mock/request_handlers/subscriptions.rb +8 -8
  22. data/lib/stripe_mock/request_handlers/tokens.rb +1 -1
  23. data/lib/stripe_mock/request_handlers/transfers.rb +1 -1
  24. data/lib/stripe_mock/server.rb +1 -1
  25. data/lib/stripe_mock/version.rb +1 -1
  26. data/spec/instance_spec.rb +4 -4
  27. data/spec/integration_examples/prepare_error_examples.rb +6 -6
  28. data/spec/readme_spec.rb +2 -0
  29. data/spec/server_spec.rb +2 -2
  30. data/spec/shared_stripe_examples/card_examples.rb +3 -3
  31. data/spec/shared_stripe_examples/coupon_examples.rb +6 -0
  32. data/spec/shared_stripe_examples/customer_examples.rb +31 -3
  33. data/spec/shared_stripe_examples/dispute_examples.rb +9 -8
  34. data/spec/shared_stripe_examples/error_mock_examples.rb +3 -3
  35. data/spec/shared_stripe_examples/extra_features_examples.rb +2 -0
  36. data/spec/shared_stripe_examples/invoice_examples.rb +232 -48
  37. data/spec/shared_stripe_examples/recipient_examples.rb +7 -7
  38. data/spec/shared_stripe_examples/subscription_examples.rb +52 -16
  39. data/spec/shared_stripe_examples/transfer_examples.rb +8 -6
  40. data/spec/shared_stripe_examples/webhook_event_examples.rb +3 -3
  41. data/spec/spec_helper.rb +6 -5
  42. data/spec/stripe_mock_spec.rb +3 -3
  43. data/stripe-ruby-mock.gemspec +1 -1
  44. metadata +4 -10
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples 'Recipient API' do
4
4
 
5
- it "creates a stripe recipient with a default bank and card" do
5
+ it "creates a stripe recipient with a default bank and card", skip: 'Stripe has deprecated Recipients' do
6
6
  recipient = Stripe::Recipient.create({
7
7
  type: "corporation",
8
8
  name: "MyCo",
@@ -28,14 +28,14 @@ shared_examples 'Recipient API' do
28
28
  expect { recipient.card }.to raise_error
29
29
  end
30
30
 
31
- it "raises a error if params are invalid" do
31
+ it "raises a error if params are invalid", skip: 'Stripe has deprecated Recipients' do
32
32
  expect { Stripe::Recipient.create(name: "foo") }.to raise_error
33
33
  expect { Stripe::Recipient.create(type: "individual") }.to raise_error
34
34
  expect { Stripe::Recipient.create(name: "foo", type: "bar") }.to raise_error
35
35
  expect { Stripe::Recipient.create(name: "foo", type: "individual") }.not_to raise_error
36
36
  end
37
37
 
38
- it "creates a stripe recipient without a card" do
38
+ it "creates a stripe recipient without a card", skip: 'Stripe has deprecated Recipients' do
39
39
  recipient = Stripe::Recipient.create({
40
40
  type: "corporation",
41
41
  name: "MyCo",
@@ -51,7 +51,7 @@ shared_examples 'Recipient API' do
51
51
  expect(recipient.default_card).to be_nil
52
52
  end
53
53
 
54
- it "stores a created stripe recipient in memory" do
54
+ it "stores a created stripe recipient in memory", skip: 'Stripe has deprecated Recipients' do
55
55
  recipient = Stripe::Recipient.create({
56
56
  type: "individual",
57
57
  name: "Customer One",
@@ -76,7 +76,7 @@ shared_examples 'Recipient API' do
76
76
  expect(data[recipient2.id][:default_card]).to_not be_nil
77
77
  end
78
78
 
79
- it "retrieves a stripe recipient" do
79
+ it "retrieves a stripe recipient", skip: 'Stripe has deprecated Recipients' do
80
80
  original = Stripe::Recipient.create({
81
81
  type: "individual",
82
82
  name: "Bob",
@@ -92,7 +92,7 @@ shared_examples 'Recipient API' do
92
92
  expect(recipient.default_card).to_not be_nil
93
93
  end
94
94
 
95
- it "cannot retrieve a recipient that doesn't exist" do
95
+ it "cannot retrieve a recipient that doesn't exist", skip: 'Stripe has deprecated Recipients' do
96
96
  expect { Stripe::Recipient.retrieve('nope') }.to raise_error {|e|
97
97
  expect(e).to be_a Stripe::InvalidRequestError
98
98
  expect(e.param).to eq('recipient')
@@ -100,7 +100,7 @@ shared_examples 'Recipient API' do
100
100
  }
101
101
  end
102
102
 
103
- describe "Errors", :live => true do
103
+ describe "Errors", :live => true, skip: 'Stripe has deprecated Recipients' do
104
104
  it "throws an error when the customer does not have the retrieving card id" do
105
105
  recipient = Stripe::Recipient.create(:name => "Bob Bobber", :type => "individual")
106
106
  card_id = "card_123"
@@ -215,7 +215,7 @@ shared_examples 'Customer Subscriptions' do
215
215
  }
216
216
  end
217
217
 
218
- it 'when attempting to create a new subscription with the params trial', focus: true, live: true do
218
+ it 'when attempting to create a new subscription with the params trial', live: true do
219
219
  plan = stripe_helper.create_plan(id: 'trial', amount: 999)
220
220
  customer = Stripe::Customer.create(source: gen_card_tk)
221
221
 
@@ -452,24 +452,32 @@ shared_examples 'Customer Subscriptions' do
452
452
  expect(customer.subscriptions.data.first.plan.to_hash).to eq(free.to_hash)
453
453
  end
454
454
 
455
- it "throws an error when updating a customer with no card" do
456
- free = stripe_helper.create_plan(id: 'free', amount: 0)
457
- paid = stripe_helper.create_plan(id: 'enterprise', amount: 499)
458
- customer = Stripe::Customer.create(id: 'cardless', plan: 'free')
455
+ [nil, 0].each do |trial_period_days|
456
+ it "throws an error when updating a customer with no card, and plan trail_period_days = #{trial_period_days}", live: true do
457
+ begin
458
+ free = stripe_helper.create_plan(id: 'free', amount: 0)
459
+ paid = stripe_helper.create_plan(id: 'enterprise', amount: 499, trial_period_days: trial_period_days)
460
+ customer = Stripe::Customer.create(description: 'cardless', plan: 'free')
459
461
 
460
- sub = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
461
- sub.plan = 'enterprise'
462
+ sub = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
463
+ sub.plan = 'enterprise'
462
464
 
463
- expect { sub.save }.to raise_error {|e|
464
- expect(e).to be_a Stripe::InvalidRequestError
465
- expect(e.http_status).to eq(400)
466
- expect(e.message).to_not be_nil
467
- }
465
+ expect { sub.save }.to raise_error {|e|
466
+ expect(e).to be_a Stripe::InvalidRequestError
467
+ expect(e.http_status).to eq(400)
468
+ expect(e.message).to_not be_nil
469
+ }
468
470
 
469
- customer = Stripe::Customer.retrieve('cardless')
470
- expect(customer.subscriptions.count).to eq(1)
471
- expect(customer.subscriptions.data.length).to eq(1)
472
- expect(customer.subscriptions.data.first.plan.to_hash).to eq(free.to_hash)
471
+ customer = Stripe::Customer.retrieve(customer.id)
472
+ expect(customer.subscriptions.count).to eq(1)
473
+ expect(customer.subscriptions.data.length).to eq(1)
474
+ expect(customer.subscriptions.data.first.plan.to_hash).to eq(free.to_hash)
475
+ ensure
476
+ customer.delete if customer
477
+ paid.delete if paid
478
+ free.delete if free
479
+ end
480
+ end
473
481
  end
474
482
 
475
483
  it 'updates a subscription if the customer has a free trial', live: true do
@@ -701,6 +709,34 @@ shared_examples 'Customer Subscriptions' do
701
709
  Stripe::Subscription.create options
702
710
  end
703
711
 
712
+ context 'retrieving a single subscription' do
713
+ let(:customer) { Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk, plan: 'free') }
714
+ let(:subscription) { Stripe::Subscription.retrieve(customer.subscriptions.data.first.id) }
715
+
716
+ before do
717
+ stripe_helper.create_plan(id: 'free', amount: 0)
718
+ Stripe::Subscription.create({ plan: 'free', customer: customer.id })
719
+ end
720
+
721
+ it 'retrieves a single subscription' do
722
+ expect(subscription).to be_truthy
723
+ end
724
+
725
+ it "includes 'items' object on retrieved subscription" do
726
+ expect(subscription.items).to be_truthy
727
+ expect(subscription.items.object).to eq('list')
728
+ expect(subscription.items.data.class).to eq(Array)
729
+ expect(subscription.items.data.count).to eq(1)
730
+ expect(subscription.items.data.first.id).to eq('si_1AwFf62eZvKYlo2C9u6Dhf9')
731
+ expect(subscription.items.data.first.created).to eq(1504035973)
732
+ expect(subscription.items.data.first.object).to eq('subscription_item')
733
+ expect(subscription.items.data.first.plan.amount).to eq(999)
734
+ expect(subscription.items.data.first.plan.created).to eq(1504035972)
735
+ expect(subscription.items.data.first.plan.currency).to eq('usd')
736
+ expect(subscription.items.data.first.quantity).to eq(1)
737
+ end
738
+ end
739
+
704
740
  context "retrieve multiple subscriptions" do
705
741
 
706
742
  it "retrieves a list of multiple subscriptions" do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples 'Transfer API' do
4
4
 
5
- it "creates a stripe transfer" do
5
+ it "creates a stripe transfer", skip: 'Stripe has deprecated Recipients' do
6
6
  recipient = Stripe::Recipient.create(type: "corporation", name: "MyCo")
7
7
  transfer = Stripe::Transfer.create(amount: "100", currency: "usd", recipient: recipient.id)
8
8
 
@@ -11,9 +11,10 @@ shared_examples 'Transfer API' do
11
11
  expect(transfer.currency).to eq('usd')
12
12
  expect(transfer.recipient).to eq recipient.id
13
13
  expect(transfer.reversed).to eq(false)
14
+ expect(transfer.metadata).to eq({})
14
15
  end
15
16
 
16
- describe "listing transfers" do
17
+ describe "listing transfers", skip: 'Stripe has deprecated Recipients' do
17
18
  let(:recipient) { Stripe::Recipient.create(type: "corporation", name: "MyCo") }
18
19
 
19
20
  before do
@@ -47,13 +48,14 @@ shared_examples 'Transfer API' do
47
48
  expect(transfer.amount).to eq(original.amount)
48
49
  expect(transfer.currency).to eq(original.currency)
49
50
  expect(transfer.recipient).to eq(original.recipient)
51
+ expect(transfer.metadata).to eq(original.metadata)
50
52
  end
51
53
 
52
54
  it "canceles a stripe transfer " do
53
55
  original = Stripe::Transfer.create(amount: "100", currency: "usd")
54
- res, api_key = Stripe.request(:post, "/v1/transfers/#{original.id}/cancel", 'api_key', {})
56
+ res, api_key = Stripe::StripeClient.active_client.execute_request(:post, "/v1/transfers/#{original.id}/cancel", api_key: 'api_key')
55
57
 
56
- expect(res[:status]).to eq("canceled")
58
+ expect(res.data[:status]).to eq("canceled")
57
59
  end
58
60
 
59
61
  it "cannot retrieve a transfer that doesn't exist" do
@@ -64,7 +66,7 @@ shared_examples 'Transfer API' do
64
66
  }
65
67
  end
66
68
 
67
- it 'when amount is not integer', live: true do
69
+ it 'when amount is not integer', live: true, skip: 'Stripe has deprecated Recipients' do
68
70
  rec = Stripe::Recipient.create({
69
71
  type: 'individual',
70
72
  name: 'Alex Smith',
@@ -79,7 +81,7 @@ shared_examples 'Transfer API' do
79
81
  }
80
82
  end
81
83
 
82
- it 'when amount is negative', focus: true, live: true do
84
+ it 'when amount is negative', live: true, skip: 'Stripe has deprecated Recipients' do
83
85
  rec = Stripe::Recipient.create({
84
86
  type: 'individual',
85
87
  name: 'Alex Smith',
@@ -70,10 +70,10 @@ shared_examples 'Webhook Events API' do
70
70
  expect(data[event_b.id][:id]).to eq(event_b.id)
71
71
  end
72
72
 
73
- it "handles stripe connect event when user_id is present" do
73
+ it "handles stripe connect event when account is present" do
74
74
  acc_12314 = 'acc_12314'
75
- event = StripeMock.mock_webhook_event('customer.created', user_id: acc_12314)
76
- expect(event[:user_id]).to eq(acc_12314)
75
+ event = StripeMock.mock_webhook_event('customer.created', account: acc_12314)
76
+ expect(event[:account]).to eq(acc_12314)
77
77
  end
78
78
 
79
79
  it "retrieves an eveng using the event resource" do
@@ -30,9 +30,10 @@ RSpec.configure do |c|
30
30
  if ENV['IS_TRAVIS']
31
31
  puts "Travis ruby version: #{RUBY_VERSION}"
32
32
  api_key = case RUBY_VERSION
33
- when '1.9.3' then ENV['STRIPE_TEST_SECRET_KEY_A']
34
- when '2.0.0' then ENV['STRIPE_TEST_SECRET_KEY_B']
35
- when '2.1.6' then ENV['STRIPE_TEST_SECRET_KEY_C']
33
+ when '2.0.0' then ENV['STRIPE_TEST_SECRET_KEY_A']
34
+ when '2.1.10' then ENV['STRIPE_TEST_SECRET_KEY_B']
35
+ when '2.2.7' then ENV['STRIPE_TEST_SECRET_KEY_C']
36
+ when '2.3.4' then ENV['STRIPE_TEST_SECRET_KEY_D']
36
37
  end
37
38
  else
38
39
  api_key = ENV['STRIPE_TEST_SECRET_KEY']
@@ -42,8 +43,8 @@ RSpec.configure do |c|
42
43
  end
43
44
 
44
45
  c.before(:each) do
45
- StripeMock.stub(:start).and_return(nil)
46
- StripeMock.stub(:stop).and_return(nil)
46
+ allow(StripeMock).to receive(:start).and_return(nil)
47
+ allow(StripeMock).to receive(:stop).and_return(nil)
47
48
  Stripe.api_key = api_key
48
49
  end
49
50
  c.after(:each) { sleep 0.01 }
@@ -4,15 +4,15 @@ describe StripeMock do
4
4
 
5
5
  it "overrides stripe's request method" do
6
6
  StripeMock.start
7
- Stripe.request(:xtest, '/', 'abcde') # no error
7
+ Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') # no error
8
8
  StripeMock.stop
9
9
  end
10
10
 
11
11
  it "reverts overriding stripe's request method" do
12
12
  StripeMock.start
13
- Stripe.request(:xtest, '/', 'abcde') # no error
13
+ Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') # no error
14
14
  StripeMock.stop
15
- expect { Stripe.request(:x, '/', 'abcde') }.to raise_error
15
+ expect { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.to raise_error ArgumentError
16
16
  end
17
17
 
18
18
  it "does not persist data between mock sessions" do
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency 'stripe', ['>= 1.31.0', '<= 1.58.0']
20
+ gem.add_dependency 'stripe', '>= 2.0.3'
21
21
  gem.add_dependency 'multi_json', '~> 1.0'
22
22
  gem.add_dependency 'dante', '>= 0.2.0'
23
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stripe
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.31.0
20
- - - <=
21
- - !ruby/object:Gem::Version
22
- version: 1.58.0
19
+ version: 2.0.3
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: 1.31.0
30
- - - <=
31
- - !ruby/object:Gem::Version
32
- version: 1.58.0
26
+ version: 2.0.3
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: multi_json
35
29
  requirement: !ruby/object:Gem::Requirement