stripe-ruby-mock 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/stripe_mock.rb +3 -1
  4. data/lib/stripe_mock/data.rb +14 -5
  5. data/lib/stripe_mock/data/list.rb +64 -0
  6. data/lib/stripe_mock/instance.rb +1 -1
  7. data/lib/stripe_mock/request_handlers/cards.rb +21 -38
  8. data/lib/stripe_mock/request_handlers/charges.rb +4 -4
  9. data/lib/stripe_mock/request_handlers/coupons.rb +3 -3
  10. data/lib/stripe_mock/request_handlers/customers.rb +5 -5
  11. data/lib/stripe_mock/request_handlers/events.rb +1 -1
  12. data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +36 -1
  13. data/lib/stripe_mock/request_handlers/invoice_items.rb +4 -4
  14. data/lib/stripe_mock/request_handlers/invoices.rb +7 -7
  15. data/lib/stripe_mock/request_handlers/plans.rb +4 -4
  16. data/lib/stripe_mock/request_handlers/recipients.rb +2 -2
  17. data/lib/stripe_mock/request_handlers/subscriptions.rb +10 -10
  18. data/lib/stripe_mock/request_handlers/tokens.rb +4 -4
  19. data/lib/stripe_mock/test_strategies/base.rb +2 -3
  20. data/lib/stripe_mock/util.rb +11 -0
  21. data/lib/stripe_mock/version.rb +1 -1
  22. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +1 -0
  23. data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +1 -0
  24. data/lib/stripe_mock/webhook_fixtures/customer.card.created.json +1 -0
  25. data/lib/stripe_mock/webhook_fixtures/customer.card.deleted.json +1 -0
  26. data/lib/stripe_mock/webhook_fixtures/customer.card.updated.json +1 -0
  27. data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
  28. data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +2 -1
  29. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
  30. data/spec/list_spec.rb +123 -0
  31. data/spec/shared_stripe_examples/card_examples.rb +87 -9
  32. data/spec/shared_stripe_examples/charge_examples.rb +12 -6
  33. data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
  34. data/spec/shared_stripe_examples/customer_examples.rb +1 -1
  35. data/spec/shared_stripe_examples/invoice_examples.rb +8 -2
  36. data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
  37. data/spec/shared_stripe_examples/plan_examples.rb +1 -1
  38. data/spec/util_spec.rb +69 -35
  39. metadata +5 -2
@@ -9,7 +9,7 @@ shared_examples 'Charge API' do
9
9
  currency: 'usd',
10
10
  card: 'bogus_card_token'
11
11
  )
12
- }.to raise_error(Stripe::InvalidRequestError, /Invalid token id/)
12
+ }.to raise_error(Stripe::InvalidRequestError, /token/i)
13
13
  end
14
14
 
15
15
  it "creates a stripe charge item with a card token" do
@@ -120,21 +120,27 @@ shared_examples 'Charge API' do
120
120
  end
121
121
 
122
122
  it "stores charges for a customer in memory" do
123
- expect(@customer.charges.map(&:id)).to eq([@charge.id])
123
+ expect(@customer.charges.data.map(&:id)).to eq([@charge.id])
124
124
  end
125
125
 
126
126
  it "stores all charges in memory" do
127
- expect(Stripe::Charge.all.map(&:id)).to eq([@charge.id, @charge2.id])
127
+ expect(Stripe::Charge.all.data.map(&:id)).to eq([@charge.id, @charge2.id])
128
128
  end
129
129
 
130
130
  it "defaults count to 10 charges" do
131
131
  11.times { Stripe::Charge.create }
132
- expect(Stripe::Charge.all.count).to eq(10)
132
+ expect(Stripe::Charge.all.data.count).to eq(10)
133
133
  end
134
134
 
135
- context "when passing count" do
135
+ it "is marked as having more when more objects exist" do
136
+ 11.times { Stripe::Charge.create }
137
+
138
+ expect(Stripe::Charge.all.has_more).to eq(true)
139
+ end
140
+
141
+ context "when passing limit" do
136
142
  it "gets that many charges" do
137
- expect(Stripe::Charge.all(count: 1).count).to eq(1)
143
+ expect(Stripe::Charge.all(limit: 1).count).to eq(1)
138
144
  end
139
145
  end
140
146
  end
@@ -88,7 +88,7 @@ shared_examples 'Coupon API' do
88
88
  Stripe::Coupon.create({ id: 'Coupon Two', amount_off: 3000 })
89
89
 
90
90
  all = Stripe::Coupon.all
91
- expect(all.length).to eq(2)
91
+ expect(all.count).to eq(2)
92
92
  expect(all.map &:id).to include('Coupon One', 'Coupon Two')
93
93
  expect(all.map &:amount_off).to include(1500, 3000)
94
94
  end
@@ -197,7 +197,7 @@ shared_examples 'Customer API' do
197
197
  Stripe::Customer.create({ email: 'two@two.com' })
198
198
 
199
199
  all = Stripe::Customer.all
200
- expect(all.length).to eq(2)
200
+ expect(all.count).to eq(2)
201
201
  expect(all.map &:email).to include('one@one.com', 'two@two.com')
202
202
  end
203
203
 
@@ -60,9 +60,15 @@ shared_examples 'Invoice API' do
60
60
  expect(Stripe::Invoice.all.count).to eq(10)
61
61
  end
62
62
 
63
- context "when passing count" do
63
+ it "is marked as having more when more objects exist" do
64
+ 11.times { Stripe::Invoice.create }
65
+
66
+ expect(Stripe::Invoice.all.has_more).to eq(true)
67
+ end
68
+
69
+ context "when passing limit" do
64
70
  it "gets that many invoices" do
65
- expect(Stripe::Invoice.all(count: 1).count).to eq(1)
71
+ expect(Stripe::Invoice.all(limit: 1).count).to eq(1)
66
72
  end
67
73
  end
68
74
  end
@@ -40,7 +40,7 @@ shared_examples 'Invoice Item API' do
40
40
 
41
41
  it "retrieves all invoice items" do
42
42
  all = Stripe::InvoiceItem.all
43
- expect(all.length).to eq(2)
43
+ expect(all.count).to eq(2)
44
44
  expect(all.map &:amount).to include(1075, 1540)
45
45
  end
46
46
  end
@@ -96,7 +96,7 @@ shared_examples 'Plan API' do
96
96
  stripe_helper.create_plan(id: 'Plan Two', amount: 98765)
97
97
 
98
98
  all = Stripe::Plan.all
99
- expect(all.length).to eq(2)
99
+ expect(all.count).to eq(2)
100
100
  expect(all.map &:id).to include('Plan One', 'Plan Two')
101
101
  expect(all.map &:amount).to include(54321, 98765)
102
102
  end
data/spec/util_spec.rb CHANGED
@@ -2,52 +2,86 @@ require 'spec_helper'
2
2
 
3
3
  describe StripeMock::Util do
4
4
 
5
- it "recursively merges a simple hash" do
6
- dest = { x: { y: 50 }, a: 5, b: 3 }
7
- source = { x: { y: 999 }, a: 77 }
8
- result = StripeMock::Util.rmerge(dest, source)
5
+ describe 'rmerge' do
6
+ it "recursively merges a simple hash" do
7
+ dest = { x: { y: 50 }, a: 5, b: 3 }
8
+ source = { x: { y: 999 }, a: 77 }
9
+ result = StripeMock::Util.rmerge(dest, source)
9
10
 
10
- expect(result).to eq({ x: { y: 999 }, a: 77, b: 3 })
11
- end
11
+ expect(result).to eq({ x: { y: 999 }, a: 77, b: 3 })
12
+ end
12
13
 
13
- it "recursively merges a nested hash" do
14
- dest = { x: { y: 50, z: { m: 44, n: 4 } } }
15
- source = { x: { y: 999, z: { n: 55 } } }
16
- result = StripeMock::Util.rmerge(dest, source)
14
+ it "recursively merges a nested hash" do
15
+ dest = { x: { y: 50, z: { m: 44, n: 4 } } }
16
+ source = { x: { y: 999, z: { n: 55 } } }
17
+ result = StripeMock::Util.rmerge(dest, source)
17
18
 
18
- expect(result).to eq({ x: { y: 999, z: { m: 44, n: 55 } } })
19
- end
19
+ expect(result).to eq({ x: { y: 999, z: { m: 44, n: 55 } } })
20
+ end
20
21
 
21
- it "merges array elements" do
22
- dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
23
- source = { x: [ {a: 0}, {a: 0} ] }
24
- result = StripeMock::Util.rmerge(dest, source)
22
+ it "merges array elements" do
23
+ dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
24
+ source = { x: [ {a: 0}, {a: 0} ] }
25
+ result = StripeMock::Util.rmerge(dest, source)
25
26
 
26
- expect(result).to eq({ x: [ {a: 0}, {a: 0, b: 2}, {c: 3} ] })
27
- end
27
+ expect(result).to eq({ x: [ {a: 0}, {a: 0, b: 2}, {c: 3} ] })
28
+ end
28
29
 
29
- it "does not truncate the array when merging" do
30
- dest = { x: [ {a: 1}, {b: 2} ] }
31
- source = { x: [ nil, nil, {c: 3} ] }
32
- result = StripeMock::Util.rmerge(dest, source)
30
+ it "does not truncate the array when merging" do
31
+ dest = { x: [ {a: 1}, {b: 2} ] }
32
+ source = { x: [ nil, nil, {c: 3} ] }
33
+ result = StripeMock::Util.rmerge(dest, source)
33
34
 
34
- expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 3} ] })
35
- end
35
+ expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 3} ] })
36
+ end
36
37
 
37
- it "treats an array nil element as a skip op" do
38
- dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
39
- source = { x: [ nil, nil, {c: 0} ] }
40
- result = StripeMock::Util.rmerge(dest, source)
38
+ it "treats an array nil element as a skip op" do
39
+ dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
40
+ source = { x: [ nil, nil, {c: 0} ] }
41
+ result = StripeMock::Util.rmerge(dest, source)
41
42
 
42
- expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 0} ] })
43
- end
43
+ expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 0} ] })
44
+ end
44
45
 
45
- it "treats nil as a replacement otherwise" do
46
- dest = { x: 99 }
47
- source = { x: nil }
48
- result = StripeMock::Util.rmerge(dest, source)
46
+ it "treats nil as a replacement otherwise" do
47
+ dest = { x: 99 }
48
+ source = { x: nil }
49
+ result = StripeMock::Util.rmerge(dest, source)
49
50
 
50
- expect(result).to eq({ x: nil })
51
+ expect(result).to eq({ x: nil })
52
+ end
51
53
  end
52
54
 
55
+ describe 'card_merge' do
56
+ it 'merges last4 into number' do
57
+ new_param = { last4: '9999' }
58
+ old_param = { number: '4242424242424242' }
59
+ result = StripeMock::Util.card_merge(old_param, new_param)
60
+ expect(result[:last4]).to eq('9999')
61
+ expect(result[:number]).to eq('4242424242429999')
62
+ end
63
+
64
+ it 'overwrites old last4 if new number given' do
65
+ new_param = { number: '9999999999999999' }
66
+ old_param = { number: '4242424242424242', last4: '4242' }
67
+ result = StripeMock::Util.card_merge(old_param, new_param)
68
+ expect(result[:last4]).to eq('9999')
69
+ expect(result[:number]).to eq('9999999999999999')
70
+ end
71
+
72
+ it 'uses last4 in preference to number if both given' do
73
+ new_param = { number: '9999999999999999', last4: '1111' }
74
+ old_param = { number: '4242424242424242', last4: '4242' }
75
+ result = StripeMock::Util.card_merge(old_param, new_param)
76
+ expect(result[:last4]).to eq('1111')
77
+ expect(result[:number]).to eq('9999999999991111')
78
+ end
79
+
80
+ it 'simple merge if old and new cards are missing number' do
81
+ new_param = { last4: '1111' }
82
+ old_param = { last4: '4242' }
83
+ result = StripeMock::Util.card_merge(old_param, new_param)
84
+ expect(result[:last4]).to eq('1111')
85
+ end
86
+ end
53
87
  end
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.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stripe
@@ -124,6 +124,7 @@ files:
124
124
  - lib/stripe_mock/api/webhooks.rb
125
125
  - lib/stripe_mock/client.rb
126
126
  - lib/stripe_mock/data.rb
127
+ - lib/stripe_mock/data/list.rb
127
128
  - lib/stripe_mock/error_queue.rb
128
129
  - lib/stripe_mock/errors/closed_client_connection_error.rb
129
130
  - lib/stripe_mock/errors/server_timeout_error.rb
@@ -201,6 +202,7 @@ files:
201
202
  - spec/integration_examples/charge_token_examples.rb
202
203
  - spec/integration_examples/customer_card_examples.rb
203
204
  - spec/integration_examples/prepare_error_examples.rb
205
+ - spec/list_spec.rb
204
206
  - spec/readme_spec.rb
205
207
  - spec/server_spec.rb
206
208
  - spec/shared_stripe_examples/bank_token_examples.rb
@@ -257,6 +259,7 @@ test_files:
257
259
  - spec/integration_examples/charge_token_examples.rb
258
260
  - spec/integration_examples/customer_card_examples.rb
259
261
  - spec/integration_examples/prepare_error_examples.rb
262
+ - spec/list_spec.rb
260
263
  - spec/readme_spec.rb
261
264
  - spec/server_spec.rb
262
265
  - spec/shared_stripe_examples/bank_token_examples.rb