stripe-ruby-mock 2.3.1 → 2.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +2 -0
- data/.travis.yml +8 -4
- data/README.md +12 -5
- data/lib/stripe_mock/api/account_balance.rb +14 -0
- data/lib/stripe_mock/api/client.rb +4 -4
- data/lib/stripe_mock/api/conversion_rate.rb +14 -0
- data/lib/stripe_mock/api/errors.rb +25 -13
- data/lib/stripe_mock/api/instance.rb +16 -6
- data/lib/stripe_mock/api/webhooks.rb +8 -1
- data/lib/stripe_mock/client.rb +18 -2
- data/lib/stripe_mock/data/list.rb +14 -2
- data/lib/stripe_mock/data.rb +398 -58
- data/lib/stripe_mock/instance.rb +105 -9
- data/lib/stripe_mock/request_handlers/accounts.rb +41 -2
- data/lib/stripe_mock/request_handlers/balance.rb +17 -0
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +18 -2
- data/lib/stripe_mock/request_handlers/charges.rb +44 -33
- data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
- data/lib/stripe_mock/request_handlers/coupons.rb +5 -4
- data/lib/stripe_mock/request_handlers/customers.rb +29 -11
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
- data/lib/stripe_mock/request_handlers/external_accounts.rb +55 -0
- data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +9 -7
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +10 -6
- data/lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb +49 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +59 -16
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +3 -2
- data/lib/stripe_mock/request_handlers/invoices.rb +93 -14
- data/lib/stripe_mock/request_handlers/orders.rb +5 -5
- data/lib/stripe_mock/request_handlers/payouts.rb +32 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -0
- data/lib/stripe_mock/request_handlers/products.rb +43 -0
- data/lib/stripe_mock/request_handlers/recipients.rb +12 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +91 -0
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +101 -39
- data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +9 -3
- data/lib/stripe_mock/request_handlers/transfers.rb +11 -5
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +15 -1
- data/lib/stripe_mock/server.rb +14 -1
- data/lib/stripe_mock/test_strategies/base.rb +10 -5
- data/lib/stripe_mock/test_strategies/live.rb +5 -0
- data/lib/stripe_mock/test_strategies/mock.rb +8 -0
- data/lib/stripe_mock/util.rb +8 -2
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.updated.json +58 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +40 -10
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +39 -10
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +39 -10
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +40 -11
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +3 -2
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +92 -85
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +3 -2
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +1 -1
- data/lib/stripe_mock.rb +15 -0
- data/spec/api/instance_spec.rb +30 -0
- data/spec/instance_spec.rb +54 -4
- data/spec/integration_examples/prepare_error_examples.rb +6 -6
- data/spec/list_spec.rb +27 -10
- data/spec/readme_spec.rb +2 -0
- data/spec/server_spec.rb +7 -3
- data/spec/shared_stripe_examples/account_examples.rb +46 -0
- data/spec/shared_stripe_examples/balance_examples.rb +11 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +28 -0
- data/spec/shared_stripe_examples/bank_examples.rb +28 -1
- data/spec/shared_stripe_examples/card_examples.rb +23 -5
- data/spec/shared_stripe_examples/card_token_examples.rb +1 -0
- data/spec/shared_stripe_examples/charge_examples.rb +131 -26
- data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +8 -2
- data/spec/shared_stripe_examples/customer_examples.rb +90 -0
- data/spec/shared_stripe_examples/dispute_examples.rb +19 -8
- data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
- data/spec/shared_stripe_examples/error_mock_examples.rb +15 -5
- data/spec/shared_stripe_examples/external_account_examples.rb +170 -0
- data/spec/shared_stripe_examples/extra_features_examples.rb +2 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +314 -51
- data/spec/shared_stripe_examples/payout_examples.rb +68 -0
- data/spec/shared_stripe_examples/plan_examples.rb +47 -4
- data/spec/shared_stripe_examples/product_example.rb +65 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +13 -7
- data/spec/shared_stripe_examples/refund_examples.rb +453 -84
- data/spec/shared_stripe_examples/subscription_examples.rb +477 -32
- data/spec/shared_stripe_examples/subscription_items_examples.rb +75 -0
- data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
- data/spec/shared_stripe_examples/transfer_examples.rb +72 -23
- data/spec/shared_stripe_examples/webhook_event_examples.rb +74 -5
- data/spec/spec_helper.rb +7 -6
- data/spec/stripe_mock_spec.rb +16 -3
- data/spec/support/stripe_examples.rb +8 -1
- data/spec/util_spec.rb +35 -1
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +44 -8
- data/ChangeLog.rdoc +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a15c09639e0a93df5b15cc5a45646c0fb189460e
|
4
|
+
data.tar.gz: b8cdf0692aba8099229f66e1906e691dd40075aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d70a5de8ae26c090632d00c1013d5ca63933fee41e40561b2e713b511a1c1347b21485b1d1c4eb8ee6837b6f4ec9a9f8e857a7bfa0785ac2182b8190180bfbb
|
7
|
+
data.tar.gz: 542f7a6f6c8743269e0337c1fc0b4fabef97003fe4d945c077ab4e16fe908bf7c21996dcb8c25ade7a4975a273a51972621d8d997e35a86f00dcb5287ae63d89
|
data/.env
ADDED
data/.travis.yml
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
+
dist: trusty
|
2
|
+
group: deprecated-2017Q2
|
3
|
+
sudo: required
|
1
4
|
language: ruby
|
2
5
|
rvm:
|
3
|
-
- 1.9.3
|
4
6
|
- 2.0.0
|
5
|
-
- 2.1.
|
7
|
+
- 2.1.10
|
8
|
+
- 2.2.7
|
9
|
+
- 2.3.4
|
6
10
|
before_install:
|
7
|
-
- rvm 1.
|
11
|
+
- rvm 2.1.10 do gem install mime-types -v 2.6.2
|
8
12
|
- gem install bundler
|
9
13
|
before_script:
|
10
14
|
- "sudo touch /var/log/stripe-mock-server.log"
|
@@ -13,7 +17,7 @@ script: "bundle exec rspec && bundle exec rspec -t live"
|
|
13
17
|
|
14
18
|
env:
|
15
19
|
global:
|
16
|
-
- IS_TRAVIS=true STRIPE_TEST_SECRET_KEY_A=
|
20
|
+
- IS_TRAVIS=true STRIPE_TEST_SECRET_KEY_A=sk_test_Ut2MSlZANdT3iDALdGhyLymy STRIPE_TEST_SECRET_KEY_B=sk_test_JXtzss9tHOG1ofIyEZgoUP4Q STRIPE_TEST_SECRET_KEY_C=sk_test_ZR5nVz9p3ivsqVa7mYB0sFep STRIPE_TEST_SECRET_KEY_D=sk_test_ZR5nVz9p3ivsqVa7mYB0sFep
|
17
21
|
|
18
22
|
notifications:
|
19
23
|
webhooks:
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'
|
|
12
12
|
|
13
13
|
In your gemfile:
|
14
14
|
|
15
|
-
gem 'stripe-ruby-mock', '~> 2.
|
15
|
+
gem 'stripe-ruby-mock', '~> 2.5.8', :require => 'stripe_mock'
|
16
16
|
|
17
17
|
## Features
|
18
18
|
|
@@ -21,12 +21,18 @@ In your gemfile:
|
|
21
21
|
* Mock and customize stripe webhooks
|
22
22
|
* Flip a switch to run your tests against Stripe's **live test servers**
|
23
23
|
|
24
|
+
### Requirements
|
25
|
+
|
26
|
+
* ruby >= 2.0.0
|
27
|
+
* stripe >= 2.0.3
|
28
|
+
|
24
29
|
### Specifications
|
25
30
|
|
26
|
-
**STRIPE API TARGET VERSION:**
|
31
|
+
**STRIPE API TARGET VERSION:** 2017-06-05 (master)
|
27
32
|
|
28
33
|
Older API version branches:
|
29
34
|
|
35
|
+
- api-2015-09-08 - use gem version 2.4.1
|
30
36
|
- [api-2014-06-17](https://github.com/rebelidealist/stripe-ruby-mock/tree/api-2014-06-17)
|
31
37
|
|
32
38
|
### Versioning System
|
@@ -62,7 +68,7 @@ describe MyApp do
|
|
62
68
|
# Specify :source in place of :card (with same value) to return customer with source data
|
63
69
|
customer = Stripe::Customer.create({
|
64
70
|
email: 'johnny@appleseed.com',
|
65
|
-
|
71
|
+
source: stripe_helper.generate_card_token
|
66
72
|
})
|
67
73
|
expect(customer.email).to eq('johnny@appleseed.com')
|
68
74
|
end
|
@@ -164,6 +170,7 @@ StripeMock.prepare_card_error(:incorrect_cvc)
|
|
164
170
|
StripeMock.prepare_card_error(:card_declined)
|
165
171
|
StripeMock.prepare_card_error(:missing)
|
166
172
|
StripeMock.prepare_card_error(:processing_error)
|
173
|
+
StripeMock.prepare_card_error(:incorrect_zip)
|
167
174
|
```
|
168
175
|
|
169
176
|
You can see the details of each error in [lib/stripe_mock/api/errors.rb](lib/stripe_mock/api/errors.rb)
|
@@ -294,9 +301,9 @@ it "mocks a stripe webhook" do
|
|
294
301
|
end
|
295
302
|
|
296
303
|
it "mocks stripe connect webhooks" do
|
297
|
-
event = StripeMock.mock_webhook_event('customer.created',
|
304
|
+
event = StripeMock.mock_webhook_event('customer.created', account: 'acc_123123')
|
298
305
|
|
299
|
-
expect(event.
|
306
|
+
expect(event.account).to eq('acc_123123')
|
300
307
|
end
|
301
308
|
```
|
302
309
|
|
@@ -8,7 +8,7 @@ module StripeMock
|
|
8
8
|
return false if @state == 'live'
|
9
9
|
return @client unless @client.nil?
|
10
10
|
|
11
|
-
|
11
|
+
Stripe::StripeClient.send(:define_method, :execute_request) { |*args| StripeMock.redirect_to_mock_server(*args) }
|
12
12
|
@client = StripeMock::Client.new(port)
|
13
13
|
@state = 'remote'
|
14
14
|
@client
|
@@ -18,7 +18,7 @@ module StripeMock
|
|
18
18
|
return false unless @state == 'remote'
|
19
19
|
@state = 'ready'
|
20
20
|
|
21
|
-
|
21
|
+
restore_stripe_execute_request_method
|
22
22
|
@client.clear_server_data if opts[:clear_server_data] == true
|
23
23
|
@client.cleanup
|
24
24
|
@client = nil
|
@@ -27,7 +27,7 @@ module StripeMock
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def self.redirect_to_mock_server(method, url, api_key, params
|
30
|
+
def self.redirect_to_mock_server(method, url, api_key: nil, api_base: nil, params: {}, headers: {})
|
31
31
|
handler = Instance.handler_for_method_url("#{method} #{url}")
|
32
32
|
|
33
33
|
if mock_error = client.error_queue.error_for_handler_name(handler[:name])
|
@@ -35,7 +35,7 @@ module StripeMock
|
|
35
35
|
raise mock_error
|
36
36
|
end
|
37
37
|
|
38
|
-
Stripe::Util.symbolize_names client.mock_request(method, url, api_key, params, headers)
|
38
|
+
Stripe::Util.symbolize_names client.mock_request(method, url, api_key: api_key, params: params, headers: headers)
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
@@ -24,28 +24,40 @@ module StripeMock
|
|
24
24
|
|
25
25
|
def self.argument_map
|
26
26
|
@__map ||= {
|
27
|
-
incorrect_number: add_json_body(["The card number is incorrect", 'number', 'incorrect_number', 402]),
|
28
|
-
invalid_number: add_json_body(["The card number is not a valid credit card number", 'number', 'invalid_number', 402]),
|
29
|
-
invalid_expiry_month: add_json_body(["The card's expiration month is invalid", 'exp_month', 'invalid_expiry_month', 402]),
|
30
|
-
invalid_expiry_year: add_json_body(["The card's expiration year is invalid", 'exp_year', 'invalid_expiry_year', 402]),
|
31
|
-
invalid_cvc: add_json_body(["The card's security code is invalid", 'cvc', 'invalid_cvc', 402]),
|
32
|
-
expired_card: add_json_body(["The card has expired", 'exp_month', 'expired_card', 402]),
|
33
|
-
incorrect_cvc: add_json_body(["The card's security code is incorrect", 'cvc', 'incorrect_cvc', 402]),
|
34
|
-
card_declined: add_json_body(["The card was declined", nil, 'card_declined', 402]),
|
35
|
-
missing: add_json_body(["There is no card on a customer that is being charged.", nil, 'missing', 402]),
|
36
|
-
processing_error: add_json_body(["An error occurred while processing the card", nil, 'processing_error', 402]),
|
37
|
-
card_error: add_json_body(['The card number is not a valid credit card number.', 'number', 'invalid_number', 402])
|
27
|
+
incorrect_number: add_json_body(["The card number is incorrect", 'number', 'incorrect_number', http_status: 402]),
|
28
|
+
invalid_number: add_json_body(["The card number is not a valid credit card number", 'number', 'invalid_number', http_status: 402]),
|
29
|
+
invalid_expiry_month: add_json_body(["The card's expiration month is invalid", 'exp_month', 'invalid_expiry_month', http_status: 402]),
|
30
|
+
invalid_expiry_year: add_json_body(["The card's expiration year is invalid", 'exp_year', 'invalid_expiry_year', http_status: 402]),
|
31
|
+
invalid_cvc: add_json_body(["The card's security code is invalid", 'cvc', 'invalid_cvc', http_status: 402]),
|
32
|
+
expired_card: add_json_body(["The card has expired", 'exp_month', 'expired_card', http_status: 402]),
|
33
|
+
incorrect_cvc: add_json_body(["The card's security code is incorrect", 'cvc', 'incorrect_cvc', http_status: 402]),
|
34
|
+
card_declined: add_json_body(["The card was declined", nil, 'card_declined', http_status: 402]),
|
35
|
+
missing: add_json_body(["There is no card on a customer that is being charged.", nil, 'missing', http_status: 402]),
|
36
|
+
processing_error: add_json_body(["An error occurred while processing the card", nil, 'processing_error', http_status: 402]),
|
37
|
+
card_error: add_json_body(['The card number is not a valid credit card number.', 'number', 'invalid_number', http_status: 402]),
|
38
|
+
incorrect_zip: add_json_body(['The zip code you supplied failed validation.', 'address_zip', 'incorrect_zip', http_status: 402])
|
38
39
|
}
|
39
40
|
end
|
40
41
|
|
42
|
+
def self.get_decline_code(code)
|
43
|
+
decline_code_map = {
|
44
|
+
card_declined: 'do_not_honor',
|
45
|
+
missing: nil
|
46
|
+
}
|
47
|
+
decline_code_map.default = code.to_s
|
48
|
+
|
49
|
+
code_key = code.to_sym
|
50
|
+
decline_code_map[code_key]
|
51
|
+
end
|
52
|
+
|
41
53
|
def self.add_json_body(error_values)
|
42
54
|
error_keys = [:message, :param, :code]
|
43
55
|
|
44
56
|
json_hash = Hash[error_keys.zip error_values]
|
45
57
|
json_hash[:type] = 'card_error'
|
58
|
+
json_hash[:decline_code] = get_decline_code(json_hash[:code])
|
46
59
|
|
47
|
-
error_values.
|
48
|
-
error_values.push(error: json_hash) # json_body
|
60
|
+
error_values.last.merge!(json_body: { error: json_hash }, http_body: { error: json_hash })
|
49
61
|
|
50
62
|
error_values
|
51
63
|
end
|
@@ -2,24 +2,34 @@ module StripeMock
|
|
2
2
|
|
3
3
|
@state = 'ready'
|
4
4
|
@instance = nil
|
5
|
-
@
|
5
|
+
@original_execute_request_method = Stripe::StripeClient.instance_method(:execute_request)
|
6
6
|
|
7
7
|
def self.start
|
8
8
|
return false if @state == 'live'
|
9
|
-
@instance = Instance.new
|
10
|
-
|
9
|
+
@instance = instance = Instance.new
|
10
|
+
Stripe::StripeClient.send(:define_method, :execute_request) { |*args| instance.mock_request(*args) }
|
11
11
|
@state = 'local'
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.stop
|
15
15
|
return unless @state == 'local'
|
16
|
-
|
16
|
+
restore_stripe_execute_request_method
|
17
17
|
@instance = nil
|
18
18
|
@state = 'ready'
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
# Yield the given block between StripeMock.start and StripeMock.stop
|
22
|
+
def self.mock(&block)
|
23
|
+
begin
|
24
|
+
self.start
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
self.stop
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.restore_stripe_execute_request_method
|
32
|
+
Stripe::StripeClient.send(:define_method, :execute_request, @original_execute_request_method)
|
23
33
|
end
|
24
34
|
|
25
35
|
def self.instance; @instance; end
|
@@ -15,9 +15,10 @@ module StripeMock
|
|
15
15
|
|
16
16
|
json = Stripe::Util.symbolize_names(json)
|
17
17
|
params = Stripe::Util.symbolize_names(params)
|
18
|
-
json[:
|
18
|
+
json[:account] = params.delete(:account) if params.key?(:account)
|
19
19
|
json[:data][:object] = Util.rmerge(json[:data][:object], params)
|
20
20
|
json.delete(:id)
|
21
|
+
json[:created] = params[:created] || Time.now.to_i
|
21
22
|
|
22
23
|
if @state == 'local'
|
23
24
|
event_data = instance.generate_webhook_event(json)
|
@@ -38,13 +39,19 @@ module StripeMock
|
|
38
39
|
@__list = [
|
39
40
|
'account.updated',
|
40
41
|
'account.application.deauthorized',
|
42
|
+
'account.external_account.created',
|
43
|
+
'account.external_account.updated',
|
44
|
+
'account.external_account.deleted',
|
41
45
|
'balance.available',
|
42
46
|
'charge.succeeded',
|
47
|
+
'charge.updated',
|
43
48
|
'charge.failed',
|
44
49
|
'charge.refunded',
|
45
50
|
'charge.dispute.created',
|
46
51
|
'charge.dispute.updated',
|
47
52
|
'charge.dispute.closed',
|
53
|
+
'charge.dispute.funds_reinstated',
|
54
|
+
'charge.dispute.funds_withdrawn',
|
48
55
|
'customer.source.created',
|
49
56
|
'customer.source.deleted',
|
50
57
|
'customer.source.updated',
|
data/lib/stripe_mock/client.rb
CHANGED
@@ -13,9 +13,9 @@ module StripeMock
|
|
13
13
|
@state = 'ready'
|
14
14
|
end
|
15
15
|
|
16
|
-
def mock_request(method, url, api_key, params
|
16
|
+
def mock_request(method, url, api_key: nil, params: {}, headers: {})
|
17
17
|
timeout_wrap do
|
18
|
-
@pipe.mock_request(method, url, api_key, params, headers).tap {|result|
|
18
|
+
@pipe.mock_request(method, url, api_key: api_key, params: params, headers: headers).tap {|result|
|
19
19
|
response, api_key = result
|
20
20
|
if response.is_a?(Hash) && response[:error_raised] == 'invalid_request'
|
21
21
|
raise Stripe::InvalidRequestError.new(*response[:error_params])
|
@@ -65,6 +65,18 @@ module StripeMock
|
|
65
65
|
timeout_wrap { Stripe::Util.symbolize_names @pipe.generate_webhook_event(event_data) }
|
66
66
|
end
|
67
67
|
|
68
|
+
def get_conversion_rate
|
69
|
+
timeout_wrap { @pipe.get_data(:conversion_rate) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_conversion_rate(value)
|
73
|
+
timeout_wrap { @pipe.set_conversion_rate(value) }
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_account_balance(value)
|
77
|
+
timeout_wrap { @pipe.set_account_balance(value) }
|
78
|
+
end
|
79
|
+
|
68
80
|
def destroy_resource(type, id)
|
69
81
|
timeout_wrap { @pipe.destroy_resource(type, id) }
|
70
82
|
end
|
@@ -73,6 +85,10 @@ module StripeMock
|
|
73
85
|
timeout_wrap { @pipe.clear_data }
|
74
86
|
end
|
75
87
|
|
88
|
+
def upsert_stripe_object(object, attributes)
|
89
|
+
timeout_wrap { @pipe.upsert_stripe_object(object, attributes) }
|
90
|
+
end
|
91
|
+
|
76
92
|
def close!
|
77
93
|
self.cleanup
|
78
94
|
StripeMock.stop_client(:clear_server_data => false)
|
@@ -1,12 +1,20 @@
|
|
1
1
|
module StripeMock
|
2
2
|
module Data
|
3
3
|
class List
|
4
|
-
attr_reader :data, :limit, :offset, :starting_after
|
4
|
+
attr_reader :data, :limit, :offset, :starting_after, :ending_before
|
5
5
|
|
6
6
|
def initialize(data, options = {})
|
7
7
|
@data = Array(data.clone)
|
8
8
|
@limit = [[options[:limit] || 10, 100].min, 1].max # restrict @limit to 1..100
|
9
9
|
@starting_after = options[:starting_after]
|
10
|
+
@ending_before = options[:ending_before]
|
11
|
+
if @data.first.is_a?(Hash) && @data.first[:created]
|
12
|
+
@data.sort_by! { |x| x[:created] }
|
13
|
+
@data.reverse!
|
14
|
+
elsif @data.first.respond_to?(:created)
|
15
|
+
@data.sort_by { |x| x.created }
|
16
|
+
@data.reverse!
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
def url
|
@@ -39,9 +47,13 @@ module StripeMock
|
|
39
47
|
private
|
40
48
|
|
41
49
|
def offset
|
42
|
-
|
50
|
+
case
|
51
|
+
when starting_after
|
43
52
|
index = data.index { |datum| datum[:id] == starting_after }
|
44
53
|
(index || raise("No such object id: #{starting_after}")) + 1
|
54
|
+
when ending_before
|
55
|
+
index = data.index { |datum| datum[:id] == ending_before }
|
56
|
+
(index || raise("No such object id: #{ending_before}")) - 1
|
45
57
|
else
|
46
58
|
0
|
47
59
|
end
|