stripe-ruby-mock 1.8.7.4 → 1.8.7.5
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 +1 -1
- data/lib/stripe_mock.rb +1 -0
- data/lib/stripe_mock/data.rb +28 -0
- data/lib/stripe_mock/instance.rb +1 -0
- data/lib/stripe_mock/request_handlers/invoices.rb +8 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +33 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/spec/shared_stripe_examples/bank_token_examples.rb +12 -1
- data/spec/shared_stripe_examples/card_token_examples.rb +69 -17
- data/spec/shared_stripe_examples/customer_examples.rb +0 -116
- data/spec/shared_stripe_examples/invoice_examples.rb +16 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +121 -0
- metadata +11 -2
data/README.md
CHANGED
data/lib/stripe_mock.rb
CHANGED
@@ -37,6 +37,7 @@ require 'stripe_mock/request_handlers/invoices.rb'
|
|
37
37
|
require 'stripe_mock/request_handlers/invoice_items.rb'
|
38
38
|
require 'stripe_mock/request_handlers/plans.rb'
|
39
39
|
require 'stripe_mock/request_handlers/recipients.rb'
|
40
|
+
require 'stripe_mock/request_handlers/tokens.rb'
|
40
41
|
require 'stripe_mock/instance'
|
41
42
|
|
42
43
|
module StripeMock
|
data/lib/stripe_mock/data.rb
CHANGED
@@ -261,6 +261,34 @@ module StripeMock
|
|
261
261
|
}
|
262
262
|
end
|
263
263
|
|
264
|
+
def self.mock_token(params={})
|
265
|
+
{
|
266
|
+
:id => 'tok_default',
|
267
|
+
:livemode => false,
|
268
|
+
:used => false,
|
269
|
+
:object => 'token',
|
270
|
+
:type => 'card',
|
271
|
+
:card => {
|
272
|
+
:id => 'card_default',
|
273
|
+
:object => 'card',
|
274
|
+
:last4 => '2222',
|
275
|
+
:type => 'Visa',
|
276
|
+
:exp_month => 9,
|
277
|
+
:exp_year => 2017,
|
278
|
+
:fingerprint => 'JRRLXGh38NiYygM7',
|
279
|
+
:customer => nil,
|
280
|
+
:country => 'US',
|
281
|
+
:name => nil,
|
282
|
+
:address_line1 => nil,
|
283
|
+
:address_line2 => nil,
|
284
|
+
:address_city => nil,
|
285
|
+
:address_state => nil,
|
286
|
+
:address_zip => nil,
|
287
|
+
:address_country => nil
|
288
|
+
}
|
289
|
+
}.merge(params)
|
290
|
+
end
|
291
|
+
|
264
292
|
def self.mock_transfer(params={})
|
265
293
|
{
|
266
294
|
:status => 'pending',
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -23,6 +23,7 @@ module StripeMock
|
|
23
23
|
include StripeMock::RequestHandlers::InvoiceItems
|
24
24
|
include StripeMock::RequestHandlers::Plans
|
25
25
|
include StripeMock::RequestHandlers::Recipients
|
26
|
+
include StripeMock::RequestHandlers::Tokens
|
26
27
|
|
27
28
|
|
28
29
|
attr_reader :bank_tokens, :charges, :customers, :events,
|
@@ -6,6 +6,7 @@ module StripeMock
|
|
6
6
|
klass.add_handler 'post /v1/invoices', :new_invoice
|
7
7
|
klass.add_handler 'get /v1/invoices/(.*)', :get_invoice
|
8
8
|
klass.add_handler 'get /v1/invoices', :list_invoices
|
9
|
+
klass.add_handler 'post /v1/invoices/(.*)/pay', :pay_invoice
|
9
10
|
end
|
10
11
|
|
11
12
|
def new_invoice(route, method_url, params, headers)
|
@@ -31,6 +32,13 @@ module StripeMock
|
|
31
32
|
assert_existance :invoice, $1, invoices[$1]
|
32
33
|
invoices[$1] ||= Data.mock_invoice(:id => $1)
|
33
34
|
end
|
35
|
+
|
36
|
+
def pay_invoice(route, method_url, params, headers)
|
37
|
+
route =~ method_url
|
38
|
+
assert_existance :invoice, $1, invoices[$1]
|
39
|
+
invoices[$1] ||= Data.mock_invoice(:id => $1)
|
40
|
+
invoices[$1].merge!(:paid => true, :attempted => true, :charge => 'ch_1fD6uiR9FAA2zc')
|
41
|
+
end
|
34
42
|
|
35
43
|
end
|
36
44
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Tokens
|
4
|
+
|
5
|
+
def Tokens.included(klass)
|
6
|
+
klass.add_handler 'post /v1/tokens', :create_token
|
7
|
+
klass.add_handler 'get /v1/tokens/(.*)', :get_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_token(route, method_url, params, headers)
|
11
|
+
# "Sanitize" card number
|
12
|
+
params[:card][:last4] = params[:card][:number][-4,4]
|
13
|
+
token_id = generate_card_token(params[:card])
|
14
|
+
card = @card_tokens[token_id]
|
15
|
+
|
16
|
+
Data.mock_token(params.merge :id => token_id, :card => card)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_token(route, method_url, params, headers)
|
20
|
+
route =~ method_url
|
21
|
+
# A Stripe token can be either a bank token or a card token
|
22
|
+
bank_or_card = @bank_tokens[$1] || @card_tokens[$1]
|
23
|
+
assert_existance :token, $1, bank_or_card
|
24
|
+
|
25
|
+
if bank_or_card[:object] == 'card'
|
26
|
+
Data.mock_token(:id => $1, :card => bank_or_card)
|
27
|
+
elsif bank_or_card[:object] == 'bank_account'
|
28
|
+
Data.mock_token(:id => $1, :bank_account => bank_or_card)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/stripe_mock/version.rb
CHANGED
@@ -36,5 +36,16 @@ shared_examples 'Bank Account Token Mocking' do
|
|
36
36
|
expect(recipient.active_account.bank_name).to eq("Bank Token Mocking")
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
it "retrieves a created token" do
|
40
|
+
bank_token = StripeMock.generate_bank_token(
|
41
|
+
:bank_name => "Cha-ching Banking",
|
42
|
+
:last4 => "3939"
|
43
|
+
)
|
44
|
+
token = Stripe::Token.retrieve(bank_token)
|
40
45
|
|
46
|
+
expect(token.id).to eq(bank_token)
|
47
|
+
expect(token.bank_account.last4).to eq("3939")
|
48
|
+
expect(token.bank_account.bank_name).to eq("Cha-ching Banking")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -2,27 +2,79 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples 'Card Token Mocking' do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
describe 'Direct Token Creation' do
|
6
|
+
|
7
|
+
it "generates and reads a card token for create customer" do
|
8
|
+
card_token = StripeMock.generate_card_token(last4: "9191", exp_month: 99, exp_year: 3005)
|
9
|
+
|
10
|
+
cus = Stripe::Customer.create(card: card_token)
|
11
|
+
card = cus.cards.data.first
|
12
|
+
expect(card.last4).to eq("9191")
|
13
|
+
expect(card.exp_month).to eq(99)
|
14
|
+
expect(card.exp_year).to eq(3005)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "generated and reads a card token for update customer" do
|
18
|
+
card_token = StripeMock.generate_card_token(last4: "1133", exp_month: 11, exp_year: 2099)
|
19
|
+
|
20
|
+
cus = Stripe::Customer.create()
|
21
|
+
cus.card = card_token
|
22
|
+
cus.save
|
23
|
+
|
24
|
+
card = cus.cards.data.first
|
25
|
+
expect(card.last4).to eq("1133")
|
26
|
+
expect(card.exp_month).to eq(11)
|
27
|
+
expect(card.exp_year).to eq(2099)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "retrieves a created token" do
|
31
|
+
card_token = StripeMock.generate_card_token(last4: "2323", exp_month: 33, exp_year: 2222)
|
32
|
+
token = Stripe::Token.retrieve(card_token)
|
33
|
+
|
34
|
+
expect(token.id).to eq(card_token)
|
35
|
+
expect(token.card.last4).to eq("2323")
|
36
|
+
expect(token.card.exp_month).to eq(33)
|
37
|
+
expect(token.card.exp_year).to eq(2222)
|
38
|
+
end
|
13
39
|
end
|
14
40
|
|
15
|
-
|
16
|
-
|
41
|
+
describe 'Stripe::Token' do
|
42
|
+
|
43
|
+
it "generates and reads a card token for create customer" do
|
44
|
+
|
45
|
+
card_token = Stripe::Token.create({
|
46
|
+
card: {
|
47
|
+
number: "4222222222222222",
|
48
|
+
exp_month: 9,
|
49
|
+
exp_year: 2017
|
50
|
+
}
|
51
|
+
})
|
52
|
+
|
53
|
+
cus = Stripe::Customer.create(card: card_token.id)
|
54
|
+
card = cus.cards.data.first
|
55
|
+
expect(card.last4).to eq("2222")
|
56
|
+
expect(card.exp_month).to eq(9)
|
57
|
+
expect(card.exp_year).to eq(2017)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "generates and reads a card token for update customer" do
|
61
|
+
card_token = Stripe::Token.create({
|
62
|
+
card: {
|
63
|
+
number: "1111222233334444",
|
64
|
+
exp_month: 11,
|
65
|
+
exp_year: 2019
|
66
|
+
}
|
67
|
+
})
|
17
68
|
|
18
|
-
|
19
|
-
|
20
|
-
|
69
|
+
cus = Stripe::Customer.create()
|
70
|
+
cus.card = card_token.id
|
71
|
+
cus.save
|
21
72
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
73
|
+
card = cus.cards.data.first
|
74
|
+
expect(card.last4).to eq("4444")
|
75
|
+
expect(card.exp_month).to eq(11)
|
76
|
+
expect(card.exp_year).to eq(2019)
|
77
|
+
end
|
26
78
|
end
|
27
79
|
|
28
80
|
end
|
@@ -141,128 +141,12 @@ shared_examples 'Customer API' do
|
|
141
141
|
expect(new_card.id).to_not eq(card.id)
|
142
142
|
end
|
143
143
|
|
144
|
-
it "updates a stripe customer's subscription" do
|
145
|
-
plan = Stripe::Plan.create(id: 'silver')
|
146
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
147
|
-
sub = customer.update_subscription({ :plan => 'silver' })
|
148
|
-
|
149
|
-
expect(sub.object).to eq('subscription')
|
150
|
-
expect(sub.plan.id).to eq('silver')
|
151
|
-
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
152
|
-
|
153
|
-
customer = Stripe::Customer.retrieve('test_customer_sub')
|
154
|
-
expect(customer.subscription).to_not be_nil
|
155
|
-
expect(customer.subscription.id).to eq(sub.id)
|
156
|
-
expect(customer.subscription.plan.id).to eq('silver')
|
157
|
-
expect(customer.subscription.customer).to eq(customer.id)
|
158
|
-
end
|
159
|
-
|
160
|
-
it "throws an error when subscribing a customer with no card" do
|
161
|
-
plan = Stripe::Plan.create(id: 'enterprise', amount: 499)
|
162
|
-
customer = Stripe::Customer.create(id: 'cardless')
|
163
|
-
|
164
|
-
expect { customer.update_subscription({ :plan => 'enterprise' }) }.to raise_error {|e|
|
165
|
-
expect(e).to be_a Stripe::InvalidRequestError
|
166
|
-
expect(e.http_status).to eq(400)
|
167
|
-
expect(e.message).to_not be_nil
|
168
|
-
}
|
169
|
-
end
|
170
|
-
|
171
|
-
it "subscribes a customer with no card to a free plan" do
|
172
|
-
plan = Stripe::Plan.create(id: 'free_tier', amount: 0)
|
173
|
-
customer = Stripe::Customer.create(id: 'cardless')
|
174
|
-
sub = customer.update_subscription({ :plan => 'free_tier' })
|
175
|
-
|
176
|
-
expect(sub.object).to eq('subscription')
|
177
|
-
expect(sub.plan.id).to eq('free_tier')
|
178
|
-
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
179
|
-
|
180
|
-
customer = Stripe::Customer.retrieve('cardless')
|
181
|
-
expect(customer.subscription).to_not be_nil
|
182
|
-
expect(customer.subscription.id).to eq(sub.id)
|
183
|
-
expect(customer.subscription.plan.id).to eq('free_tier')
|
184
|
-
expect(customer.subscription.customer).to eq(customer.id)
|
185
|
-
end
|
186
|
-
|
187
|
-
it "subscribes a customer with no card to a plan with a free trial" do
|
188
|
-
plan = Stripe::Plan.create(id: 'trial', amount: 999, trial_period_days: 14)
|
189
|
-
customer = Stripe::Customer.create(id: 'cardless')
|
190
|
-
sub = customer.update_subscription({ :plan => 'trial' })
|
191
|
-
|
192
|
-
expect(sub.object).to eq('subscription')
|
193
|
-
expect(sub.plan.id).to eq('trial')
|
194
|
-
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
195
|
-
|
196
|
-
customer = Stripe::Customer.retrieve('cardless')
|
197
|
-
expect(customer.subscription).to_not be_nil
|
198
|
-
expect(customer.subscription.id).to eq(sub.id)
|
199
|
-
expect(customer.subscription.plan.id).to eq('trial')
|
200
|
-
expect(customer.subscription.customer).to eq(customer.id)
|
201
|
-
end
|
202
|
-
|
203
|
-
it "cancels a stripe customer's subscription" do
|
204
|
-
Stripe::Plan.create(id: 'the truth')
|
205
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
206
|
-
sub = customer.update_subscription({ :plan => 'the truth' })
|
207
|
-
|
208
|
-
result = customer.cancel_subscription
|
209
|
-
expect(result.status).to eq('canceled')
|
210
|
-
expect(result.cancel_at_period_end).to be_false
|
211
|
-
expect(result.id).to eq(sub.id)
|
212
|
-
|
213
|
-
customer = Stripe::Customer.retrieve('test_customer_sub')
|
214
|
-
expect(customer.subscription).to_not be_nil
|
215
|
-
expect(customer.subscription.id).to eq(result.id)
|
216
|
-
end
|
217
|
-
|
218
|
-
it "cancels a stripe customer's subscription at period end" do
|
219
|
-
Stripe::Plan.create(id: 'the truth')
|
220
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
221
|
-
sub = customer.update_subscription({ :plan => 'the truth' })
|
222
|
-
|
223
|
-
result = customer.cancel_subscription(at_period_end: true)
|
224
|
-
expect(result.status).to eq('active')
|
225
|
-
expect(result.cancel_at_period_end).to be_true
|
226
|
-
expect(result.id).to eq(sub.id)
|
227
|
-
|
228
|
-
customer = Stripe::Customer.retrieve('test_customer_sub')
|
229
|
-
expect(customer.subscription).to_not be_nil
|
230
|
-
expect(customer.subscription.id).to eq(result.id)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "cannot update to a plan that does not exist" do
|
234
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
235
|
-
expect {
|
236
|
-
customer.update_subscription(plan: 'imagination')
|
237
|
-
}.to raise_error Stripe::InvalidRequestError
|
238
|
-
end
|
239
|
-
|
240
|
-
it "cannot cancel a plan that does not exist" do
|
241
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
242
|
-
expect {
|
243
|
-
customer.cancel_subscription(plan: 'imagination')
|
244
|
-
}.to raise_error Stripe::InvalidRequestError
|
245
|
-
end
|
246
|
-
|
247
144
|
it "deletes a customer" do
|
248
145
|
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
249
146
|
customer = customer.delete
|
250
147
|
expect(customer.deleted).to be_true
|
251
148
|
end
|
252
149
|
|
253
|
-
it "sets card" do
|
254
|
-
plan = Stripe::Plan.create(id: 'small')
|
255
|
-
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
256
|
-
customer.update_subscription(card: 'tk', :plan => 'small')
|
257
|
-
|
258
|
-
customer = Stripe::Customer.retrieve('test_customer_sub')
|
259
|
-
|
260
|
-
expect(customer.cards.count).to eq(1)
|
261
|
-
expect(customer.cards.data.length).to eq(1)
|
262
|
-
expect(customer.default_card).to_not be_nil
|
263
|
-
expect(customer.default_card).to eq customer.cards.data.first.id
|
264
|
-
end
|
265
|
-
|
266
150
|
context "With strict mode toggled off" do
|
267
151
|
|
268
152
|
before { StripeMock.toggle_strict(false) }
|
@@ -51,4 +51,20 @@ shared_examples 'Invoice API' do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
context "paying an invoice" do
|
55
|
+
before do
|
56
|
+
@invoice = Stripe::Invoice.create
|
57
|
+
@invoice.pay
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'updates attempted and paid flags' do
|
61
|
+
expect(@invoice.attempted).to be_true
|
62
|
+
expect(@invoice.paid).to be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'sets the charge attribute' do
|
66
|
+
expect(@invoice.charge).to be_a String
|
67
|
+
expect(@invoice.charge.length).to be > 0
|
68
|
+
end
|
69
|
+
end
|
54
70
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Customer Subscriptions' do
|
4
|
+
|
5
|
+
it "updates a stripe customer's subscription" do
|
6
|
+
plan = Stripe::Plan.create(id: 'silver')
|
7
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
8
|
+
sub = customer.update_subscription({ :plan => 'silver' })
|
9
|
+
|
10
|
+
expect(sub.object).to eq('subscription')
|
11
|
+
expect(sub.plan.id).to eq('silver')
|
12
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
13
|
+
|
14
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
15
|
+
expect(customer.subscription).to_not be_nil
|
16
|
+
expect(customer.subscription.id).to eq(sub.id)
|
17
|
+
expect(customer.subscription.plan.id).to eq('silver')
|
18
|
+
expect(customer.subscription.customer).to eq(customer.id)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "throws an error when subscribing a customer with no card" do
|
22
|
+
plan = Stripe::Plan.create(id: 'enterprise', amount: 499)
|
23
|
+
customer = Stripe::Customer.create(id: 'cardless')
|
24
|
+
|
25
|
+
expect { customer.update_subscription({ :plan => 'enterprise' }) }.to raise_error {|e|
|
26
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
27
|
+
expect(e.http_status).to eq(400)
|
28
|
+
expect(e.message).to_not be_nil
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
it "subscribes a customer with no card to a free plan" do
|
33
|
+
plan = Stripe::Plan.create(id: 'free_tier', amount: 0)
|
34
|
+
customer = Stripe::Customer.create(id: 'cardless')
|
35
|
+
sub = customer.update_subscription({ :plan => 'free_tier' })
|
36
|
+
|
37
|
+
expect(sub.object).to eq('subscription')
|
38
|
+
expect(sub.plan.id).to eq('free_tier')
|
39
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
40
|
+
|
41
|
+
customer = Stripe::Customer.retrieve('cardless')
|
42
|
+
expect(customer.subscription).to_not be_nil
|
43
|
+
expect(customer.subscription.id).to eq(sub.id)
|
44
|
+
expect(customer.subscription.plan.id).to eq('free_tier')
|
45
|
+
expect(customer.subscription.customer).to eq(customer.id)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "subscribes a customer with no card to a plan with a free trial" do
|
49
|
+
plan = Stripe::Plan.create(id: 'trial', amount: 999, trial_period_days: 14)
|
50
|
+
customer = Stripe::Customer.create(id: 'cardless')
|
51
|
+
sub = customer.update_subscription({ :plan => 'trial' })
|
52
|
+
|
53
|
+
expect(sub.object).to eq('subscription')
|
54
|
+
expect(sub.plan.id).to eq('trial')
|
55
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
56
|
+
|
57
|
+
customer = Stripe::Customer.retrieve('cardless')
|
58
|
+
expect(customer.subscription).to_not be_nil
|
59
|
+
expect(customer.subscription.id).to eq(sub.id)
|
60
|
+
expect(customer.subscription.plan.id).to eq('trial')
|
61
|
+
expect(customer.subscription.customer).to eq(customer.id)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "cancels a stripe customer's subscription" do
|
65
|
+
Stripe::Plan.create(id: 'the truth')
|
66
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
67
|
+
sub = customer.update_subscription({ :plan => 'the truth' })
|
68
|
+
|
69
|
+
result = customer.cancel_subscription
|
70
|
+
expect(result.status).to eq('canceled')
|
71
|
+
expect(result.cancel_at_period_end).to be_false
|
72
|
+
expect(result.id).to eq(sub.id)
|
73
|
+
|
74
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
75
|
+
expect(customer.subscription).to_not be_nil
|
76
|
+
expect(customer.subscription.id).to eq(result.id)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "cancels a stripe customer's subscription at period end" do
|
80
|
+
Stripe::Plan.create(id: 'the truth')
|
81
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', card: 'tk')
|
82
|
+
sub = customer.update_subscription({ :plan => 'the truth' })
|
83
|
+
|
84
|
+
result = customer.cancel_subscription(at_period_end: true)
|
85
|
+
expect(result.status).to eq('active')
|
86
|
+
expect(result.cancel_at_period_end).to be_true
|
87
|
+
expect(result.id).to eq(sub.id)
|
88
|
+
|
89
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
90
|
+
expect(customer.subscription).to_not be_nil
|
91
|
+
expect(customer.subscription.id).to eq(result.id)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "cannot update to a plan that does not exist" do
|
95
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
96
|
+
expect {
|
97
|
+
customer.update_subscription(plan: 'imagination')
|
98
|
+
}.to raise_error Stripe::InvalidRequestError
|
99
|
+
end
|
100
|
+
|
101
|
+
it "cannot cancel a plan that does not exist" do
|
102
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
103
|
+
expect {
|
104
|
+
customer.cancel_subscription(plan: 'imagination')
|
105
|
+
}.to raise_error Stripe::InvalidRequestError
|
106
|
+
end
|
107
|
+
|
108
|
+
it "sets a card when updating a customer's subscription" do
|
109
|
+
plan = Stripe::Plan.create(id: 'small')
|
110
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
111
|
+
customer.update_subscription(card: 'tk', :plan => 'small')
|
112
|
+
|
113
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
114
|
+
|
115
|
+
expect(customer.cards.count).to eq(1)
|
116
|
+
expect(customer.cards.data.length).to eq(1)
|
117
|
+
expect(customer.default_card).to_not be_nil
|
118
|
+
expect(customer.default_card).to eq customer.cards.data.first.id
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
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.7.
|
4
|
+
version: 1.8.7.5
|
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:
|
12
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stripe
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/stripe_mock/request_handlers/invoices.rb
|
152
152
|
- lib/stripe_mock/request_handlers/plans.rb
|
153
153
|
- lib/stripe_mock/request_handlers/recipients.rb
|
154
|
+
- lib/stripe_mock/request_handlers/tokens.rb
|
154
155
|
- lib/stripe_mock/server.rb
|
155
156
|
- lib/stripe_mock/util.rb
|
156
157
|
- lib/stripe_mock/version.rb
|
@@ -206,6 +207,7 @@ files:
|
|
206
207
|
- spec/shared_stripe_examples/invoice_item_examples.rb
|
207
208
|
- spec/shared_stripe_examples/plan_examples.rb
|
208
209
|
- spec/shared_stripe_examples/recipient_examples.rb
|
210
|
+
- spec/shared_stripe_examples/subscription_examples.rb
|
209
211
|
- spec/shared_stripe_examples/webhook_event_examples.rb
|
210
212
|
- spec/spec_helper.rb
|
211
213
|
- spec/stripe_mock_spec.rb
|
@@ -225,12 +227,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
227
|
- - ! '>='
|
226
228
|
- !ruby/object:Gem::Version
|
227
229
|
version: '0'
|
230
|
+
segments:
|
231
|
+
- 0
|
232
|
+
hash: 93428361631981441
|
228
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
234
|
none: false
|
230
235
|
requirements:
|
231
236
|
- - ! '>='
|
232
237
|
- !ruby/object:Gem::Version
|
233
238
|
version: '0'
|
239
|
+
segments:
|
240
|
+
- 0
|
241
|
+
hash: 93428361631981441
|
234
242
|
requirements: []
|
235
243
|
rubyforge_project:
|
236
244
|
rubygems_version: 1.8.25
|
@@ -254,6 +262,7 @@ test_files:
|
|
254
262
|
- spec/shared_stripe_examples/invoice_item_examples.rb
|
255
263
|
- spec/shared_stripe_examples/plan_examples.rb
|
256
264
|
- spec/shared_stripe_examples/recipient_examples.rb
|
265
|
+
- spec/shared_stripe_examples/subscription_examples.rb
|
257
266
|
- spec/shared_stripe_examples/webhook_event_examples.rb
|
258
267
|
- spec/spec_helper.rb
|
259
268
|
- spec/stripe_mock_spec.rb
|