stripe-ruby-mock 1.8.3.11 → 1.8.3.12
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.
- data/README.md +2 -0
- data/lib/stripe_mock/data.rb +6 -7
- data/lib/stripe_mock/instance.rb +3 -2
- data/lib/stripe_mock/request_handlers/customers.rb +21 -7
- data/lib/stripe_mock/server.rb +0 -1
- data/lib/stripe_mock/util.rb +4 -4
- data/lib/stripe_mock/version.rb +1 -1
- data/spec/shared_stripe_examples/{charges.rb → charge_examples.rb} +0 -0
- data/spec/shared_stripe_examples/{customers.rb → customer_examples.rb} +19 -3
- data/spec/shared_stripe_examples/{error_mocks.rb → error_mock_examples.rb} +0 -0
- data/spec/shared_stripe_examples/{invoice_items.rb → invoice_item_examples.rb} +0 -0
- data/spec/shared_stripe_examples/{plans.rb → plan_examples.rb} +0 -0
- data/spec/support/stripe_examples.rb +5 -5
- data/spec/util_spec.rb +15 -15
- data/stripe-ruby-mock.gemspec +1 -0
- metadata +28 -12
data/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
|
12
12
|
* No stripe server access required
|
13
13
|
* Easily test against stripe errors
|
14
|
+
* Mock and customize stripe webhooks
|
14
15
|
|
15
16
|
## Description
|
16
17
|
|
@@ -107,6 +108,7 @@ running on different processes. In such cases you'll want to start the stripe mo
|
|
107
108
|
#
|
108
109
|
# The mock server will automatically be killed when your tests are done running.
|
109
110
|
#
|
111
|
+
require 'thin'
|
110
112
|
StripeMock.spawn_server
|
111
113
|
|
112
114
|
Then, instead of `StripeMock.start`, you'll want to use `StripeMock.start_client`:
|
data/lib/stripe_mock/data.rb
CHANGED
@@ -115,8 +115,8 @@ module StripeMock
|
|
115
115
|
end
|
116
116
|
|
117
117
|
#FIXME nested overrides would be better than hardcoding plan_id
|
118
|
-
def self.test_subscription(
|
119
|
-
{
|
118
|
+
def self.test_subscription(params={})
|
119
|
+
StripeMock::Util.rmerge({
|
120
120
|
:current_period_end => 1308681468,
|
121
121
|
:status => "trialing",
|
122
122
|
:plan => {
|
@@ -124,7 +124,7 @@ module StripeMock
|
|
124
124
|
:amount => 7500,
|
125
125
|
:trial_period_days => 30,
|
126
126
|
:object => "plan",
|
127
|
-
:id =>
|
127
|
+
:id => '__test_plan_id__'
|
128
128
|
},
|
129
129
|
:current_period_start => 1308595038,
|
130
130
|
:cancel_at_period_end => false,
|
@@ -135,7 +135,7 @@ module StripeMock
|
|
135
135
|
:trial_end => 1308681468,
|
136
136
|
:customer => "c_test_customer",
|
137
137
|
:quantity => 1
|
138
|
-
}
|
138
|
+
}, params)
|
139
139
|
end
|
140
140
|
|
141
141
|
def self.test_invoice(params={})
|
@@ -297,11 +297,10 @@ module StripeMock
|
|
297
297
|
}
|
298
298
|
end
|
299
299
|
|
300
|
-
def self.test_delete_subscription(
|
300
|
+
def self.test_delete_subscription(params={})
|
301
301
|
{
|
302
|
-
id: id,
|
303
302
|
deleted: true
|
304
|
-
}
|
303
|
+
}.merge(params)
|
305
304
|
end
|
306
305
|
|
307
306
|
def self.test_api_error
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -66,11 +66,12 @@ module StripeMock
|
|
66
66
|
|
67
67
|
private
|
68
68
|
|
69
|
-
def assert_existance(type, id, obj)
|
69
|
+
def assert_existance(type, id, obj, message=nil)
|
70
70
|
return unless @strict == true
|
71
71
|
|
72
72
|
if obj.nil?
|
73
|
-
|
73
|
+
msg = message || "No such #{type}: #{id}"
|
74
|
+
raise Stripe::InvalidRequestError.new(msg, type.to_s, 400)
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
@@ -4,7 +4,7 @@ module StripeMock
|
|
4
4
|
|
5
5
|
def Customers.included(klass)
|
6
6
|
klass.add_handler 'post /v1/customers', :new_customer
|
7
|
-
klass.add_handler 'post /v1/customers/(.*)/subscription', :
|
7
|
+
klass.add_handler 'post /v1/customers/(.*)/subscription', :update_subscription
|
8
8
|
klass.add_handler 'delete /v1/customers/(.*)/subscription', :cancel_subscription
|
9
9
|
klass.add_handler 'post /v1/customers/(.*)', :update_customer
|
10
10
|
klass.add_handler 'get /v1/customers/(.*)', :get_customer
|
@@ -16,17 +16,31 @@ module StripeMock
|
|
16
16
|
customers[ params[:id] ] = Data.test_customer(params)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def update_subscription(route, method_url, params, headers)
|
20
20
|
route =~ method_url
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
|
22
|
+
customer = customers[$1]
|
23
|
+
assert_existance :customer, $1, customer
|
24
|
+
plan = plans[ params[:plan] ]
|
25
|
+
assert_existance :plan, params[:plan], plan
|
26
|
+
|
27
|
+
sub = Data.test_subscription plan: plan, id: new_id('su')
|
28
|
+
customer[:subscription] = sub
|
24
29
|
end
|
25
30
|
|
26
31
|
def cancel_subscription(route, method_url, params, headers)
|
27
32
|
route =~ method_url
|
28
|
-
|
29
|
-
|
33
|
+
|
34
|
+
customer = customers[$1]
|
35
|
+
assert_existance :customer, $1, customer
|
36
|
+
|
37
|
+
sub = customer[:subscription]
|
38
|
+
assert_existance nil, nil, sub, "No active subscription for customer: #{$1}"
|
39
|
+
|
40
|
+
plan = plans[ sub[:plan][:id] ]
|
41
|
+
assert_existance :plan, params[:plan], plan
|
42
|
+
|
43
|
+
Data.test_delete_subscription(id: sub[:id])
|
30
44
|
end
|
31
45
|
|
32
46
|
def update_customer(route, method_url, params, headers)
|
data/lib/stripe_mock/server.rb
CHANGED
data/lib/stripe_mock/util.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module StripeMock
|
2
2
|
module Util
|
3
3
|
|
4
|
-
def self.rmerge(
|
5
|
-
return
|
6
|
-
return nil if
|
4
|
+
def self.rmerge(desh_hash, source_hash)
|
5
|
+
return source_hash if desh_hash.nil?
|
6
|
+
return nil if source_hash.nil?
|
7
7
|
|
8
|
-
|
8
|
+
desh_hash.merge(source_hash) do |key, oldval, newval|
|
9
9
|
if oldval.is_a?(Array) && newval.is_a?(Array)
|
10
10
|
oldval.zip(newval).map {|elems|
|
11
11
|
elems[1].nil? ? elems[0] : rmerge(elems[0], elems[1])
|
data/lib/stripe_mock/version.rb
CHANGED
File without changes
|
@@ -80,22 +80,38 @@ shared_examples 'Customer API' do
|
|
80
80
|
|
81
81
|
expect(sub.object).to eq('subscription')
|
82
82
|
expect(sub.plan.id).to eq('silver')
|
83
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
84
|
+
|
85
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
86
|
+
expect(customer.subscription).to_not be_nil
|
87
|
+
expect(customer.subscription.id).to eq(sub.id)
|
88
|
+
expect(customer.subscription.plan.id).to eq('silver')
|
83
89
|
end
|
84
90
|
|
85
91
|
it "cancels a stripe customer's subscription" do
|
92
|
+
plan = Stripe::Plan.create(id: 'the truth')
|
86
93
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
87
|
-
sub = customer.
|
94
|
+
sub = customer.update_subscription({ :plan => 'the truth' })
|
88
95
|
|
89
|
-
|
96
|
+
result = customer.cancel_subscription
|
97
|
+
expect(result.deleted).to eq(true)
|
98
|
+
expect(result.id).to eq(sub.id)
|
90
99
|
end
|
91
100
|
|
92
|
-
it "cannot
|
101
|
+
it "cannot update to a plan that does not exist" do
|
93
102
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
94
103
|
expect {
|
95
104
|
customer.update_subscription(plan: 'imagination')
|
96
105
|
}.to raise_error Stripe::InvalidRequestError
|
97
106
|
end
|
98
107
|
|
108
|
+
it "cannot cancel a plan that does not exist" do
|
109
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
110
|
+
expect {
|
111
|
+
customer.cancel_subscription(plan: 'imagination')
|
112
|
+
}.to raise_error Stripe::InvalidRequestError
|
113
|
+
end
|
114
|
+
|
99
115
|
|
100
116
|
context "With strict mode toggled off" do
|
101
117
|
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,10 +1,10 @@
|
|
1
1
|
|
2
2
|
def require_stripe_examples
|
3
|
-
require 'shared_stripe_examples/
|
4
|
-
require 'shared_stripe_examples/
|
5
|
-
require 'shared_stripe_examples/
|
6
|
-
require 'shared_stripe_examples/
|
7
|
-
require 'shared_stripe_examples/
|
3
|
+
require 'shared_stripe_examples/charge_examples'
|
4
|
+
require 'shared_stripe_examples/customer_examples'
|
5
|
+
require 'shared_stripe_examples/error_mock_examples'
|
6
|
+
require 'shared_stripe_examples/invoice_item_examples'
|
7
|
+
require 'shared_stripe_examples/plan_examples'
|
8
8
|
end
|
9
9
|
|
10
10
|
def it_behaves_like_stripe(&block)
|
data/spec/util_spec.rb
CHANGED
@@ -3,41 +3,41 @@ require 'spec_helper'
|
|
3
3
|
describe StripeMock::Util do
|
4
4
|
|
5
5
|
it "recursively merges a simple hash" do
|
6
|
-
|
7
|
-
|
8
|
-
result = StripeMock::Util.rmerge(
|
6
|
+
dest = { x: { y: 50 }, a: 5, b: 3 }
|
7
|
+
source = { x: { y: 999 }, a: 77 }
|
8
|
+
result = StripeMock::Util.rmerge(dest, source)
|
9
9
|
|
10
10
|
expect(result).to eq({ x: { y: 999 }, a: 77, b: 3 })
|
11
11
|
end
|
12
12
|
|
13
13
|
it "recursively merges a nested hash" do
|
14
|
-
|
15
|
-
|
16
|
-
result = StripeMock::Util.rmerge(
|
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)
|
17
17
|
|
18
18
|
expect(result).to eq({ x: { y: 999, z: { m: 44, n: 55 } } })
|
19
19
|
end
|
20
20
|
|
21
21
|
it "merges array elements" do
|
22
|
-
|
23
|
-
|
24
|
-
result = StripeMock::Util.rmerge(
|
22
|
+
dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
|
23
|
+
source = { x: [ {a: 0}, {a: 0} ] }
|
24
|
+
result = StripeMock::Util.rmerge(dest, source)
|
25
25
|
|
26
26
|
expect(result).to eq({ x: [ {a: 0}, {a: 0, b: 2}, {c: 3} ] })
|
27
27
|
end
|
28
28
|
|
29
29
|
it "treats an array nil element as a skip op" do
|
30
|
-
|
31
|
-
|
32
|
-
result = StripeMock::Util.rmerge(
|
30
|
+
dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
|
31
|
+
source = { x: [ nil, nil, {c: 0} ] }
|
32
|
+
result = StripeMock::Util.rmerge(dest, source)
|
33
33
|
|
34
34
|
expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 0} ] })
|
35
35
|
end
|
36
36
|
|
37
37
|
it "treats nil as a replacement otherwise" do
|
38
|
-
|
39
|
-
|
40
|
-
result = StripeMock::Util.rmerge(
|
38
|
+
dest = { x: 99 }
|
39
|
+
source = { x: nil }
|
40
|
+
result = StripeMock::Util.rmerge(dest, source)
|
41
41
|
|
42
42
|
expect(result).to eq({ x: nil })
|
43
43
|
end
|
data/stripe-ruby-mock.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-ruby-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.3.
|
4
|
+
version: 1.8.3.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stripe
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0.2'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: thin
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
description: A drop-in library to test stripe without hitting their servers
|
95
111
|
email: gilbertbgarza@gmail.com
|
96
112
|
executables:
|
@@ -171,11 +187,11 @@ files:
|
|
171
187
|
- spec/instance_spec.rb
|
172
188
|
- spec/readme_spec.rb
|
173
189
|
- spec/server_spec.rb
|
174
|
-
- spec/shared_stripe_examples/
|
175
|
-
- spec/shared_stripe_examples/
|
176
|
-
- spec/shared_stripe_examples/
|
177
|
-
- spec/shared_stripe_examples/
|
178
|
-
- spec/shared_stripe_examples/
|
190
|
+
- spec/shared_stripe_examples/charge_examples.rb
|
191
|
+
- spec/shared_stripe_examples/customer_examples.rb
|
192
|
+
- spec/shared_stripe_examples/error_mock_examples.rb
|
193
|
+
- spec/shared_stripe_examples/invoice_item_examples.rb
|
194
|
+
- spec/shared_stripe_examples/plan_examples.rb
|
179
195
|
- spec/spec_helper.rb
|
180
196
|
- spec/stripe_mock_spec.rb
|
181
197
|
- spec/support/stripe_examples.rb
|
@@ -214,11 +230,11 @@ test_files:
|
|
214
230
|
- spec/instance_spec.rb
|
215
231
|
- spec/readme_spec.rb
|
216
232
|
- spec/server_spec.rb
|
217
|
-
- spec/shared_stripe_examples/
|
218
|
-
- spec/shared_stripe_examples/
|
219
|
-
- spec/shared_stripe_examples/
|
220
|
-
- spec/shared_stripe_examples/
|
221
|
-
- spec/shared_stripe_examples/
|
233
|
+
- spec/shared_stripe_examples/charge_examples.rb
|
234
|
+
- spec/shared_stripe_examples/customer_examples.rb
|
235
|
+
- spec/shared_stripe_examples/error_mock_examples.rb
|
236
|
+
- spec/shared_stripe_examples/invoice_item_examples.rb
|
237
|
+
- spec/shared_stripe_examples/plan_examples.rb
|
222
238
|
- spec/spec_helper.rb
|
223
239
|
- spec/stripe_mock_spec.rb
|
224
240
|
- spec/support/stripe_examples.rb
|