stripe-ruby-mock 2.0.1 → 2.0.2
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/stripe_mock.rb +3 -1
- data/lib/stripe_mock/data.rb +14 -5
- data/lib/stripe_mock/data/list.rb +64 -0
- data/lib/stripe_mock/instance.rb +1 -1
- data/lib/stripe_mock/request_handlers/cards.rb +21 -38
- data/lib/stripe_mock/request_handlers/charges.rb +4 -4
- data/lib/stripe_mock/request_handlers/coupons.rb +3 -3
- data/lib/stripe_mock/request_handlers/customers.rb +5 -5
- data/lib/stripe_mock/request_handlers/events.rb +1 -1
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +36 -1
- data/lib/stripe_mock/request_handlers/invoice_items.rb +4 -4
- data/lib/stripe_mock/request_handlers/invoices.rb +7 -7
- data/lib/stripe_mock/request_handlers/plans.rb +4 -4
- data/lib/stripe_mock/request_handlers/recipients.rb +2 -2
- data/lib/stripe_mock/request_handlers/subscriptions.rb +10 -10
- data/lib/stripe_mock/request_handlers/tokens.rb +4 -4
- data/lib/stripe_mock/test_strategies/base.rb +2 -3
- data/lib/stripe_mock/util.rb +11 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.card.created.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.card.deleted.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.card.updated.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
- data/spec/list_spec.rb +123 -0
- data/spec/shared_stripe_examples/card_examples.rb +87 -9
- data/spec/shared_stripe_examples/charge_examples.rb +12 -6
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +1 -1
- data/spec/shared_stripe_examples/invoice_examples.rb +8 -2
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/plan_examples.rb +1 -1
- data/spec/util_spec.rb +69 -35
- 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, /
|
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
|
-
|
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(
|
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.
|
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.
|
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
|
-
|
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(
|
71
|
+
expect(Stripe::Invoice.all(limit: 1).count).to eq(1)
|
66
72
|
end
|
67
73
|
end
|
68
74
|
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.
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
11
|
+
expect(result).to eq({ x: { y: 999 }, a: 77, b: 3 })
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
19
|
+
expect(result).to eq({ x: { y: 999, z: { m: 44, n: 55 } } })
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
-
|
27
|
+
expect(result).to eq({ x: [ {a: 0}, {a: 0, b: 2}, {c: 3} ] })
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
35
|
+
expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 3} ] })
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
43
|
+
expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 0} ] })
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
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.
|
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:
|
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
|