stripe-ruby-mock 1.10.1.2 → 1.10.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  In your gemfile:
10
10
 
11
- gem 'stripe-ruby-mock', '~> 1.10.2'
11
+ gem 'stripe-ruby-mock', '~> 1.10.1.3'
12
12
 
13
13
  ## Features
14
14
 
@@ -272,6 +272,18 @@ debug will be toggled off.
272
272
 
273
273
  If you always want debug to be on (it's quite verbose), you should put this in a `before` block.
274
274
 
275
+ ## Miscellaneous Features
276
+
277
+ You may have noticed that all generated Stripe ids start with `test_`. If you want to remove this:
278
+
279
+ ```ruby
280
+ # Turns off test_ prefix
281
+ StripeMock.global_id_prefix = false
282
+
283
+ # Or you can set your own
284
+ StripeMock.global_id_prefix = 'my_app_'
285
+ ```
286
+
275
287
  ## TODO
276
288
 
277
289
  * Cover all stripe urls/methods
data/lib/stripe_mock.rb CHANGED
@@ -22,12 +22,14 @@ require 'stripe_mock/server'
22
22
  require 'stripe_mock/api/instance'
23
23
  require 'stripe_mock/api/client'
24
24
  require 'stripe_mock/api/server'
25
- require 'stripe_mock/api/card_tokens'
25
+
26
26
  require 'stripe_mock/api/bank_tokens'
27
+ require 'stripe_mock/api/card_tokens'
28
+ require 'stripe_mock/api/debug'
27
29
  require 'stripe_mock/api/errors'
28
- require 'stripe_mock/api/webhooks'
30
+ require 'stripe_mock/api/global_id_prefix'
29
31
  require 'stripe_mock/api/strict'
30
- require 'stripe_mock/api/debug'
32
+ require 'stripe_mock/api/webhooks'
31
33
 
32
34
  require 'stripe_mock/request_handlers/helpers/card_helpers.rb'
33
35
  require 'stripe_mock/request_handlers/helpers/subscription_helpers.rb'
@@ -0,0 +1,22 @@
1
+ module StripeMock
2
+
3
+ def self.global_id_prefix
4
+ if StripeMock.client
5
+ StripeMock.client.server_global_id_prefix
6
+ else
7
+ case @global_id_prefix
8
+ when false then ""
9
+ when nil then "test_"
10
+ else @global_id_prefix
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.global_id_prefix=(value)
16
+ if StripeMock.client
17
+ StripeMock.client.set_server_global_id_prefix(value)
18
+ else
19
+ @global_id_prefix = value
20
+ end
21
+ end
22
+ end
@@ -48,6 +48,14 @@ module StripeMock
48
48
  timeout_wrap { @pipe.strict? }
49
49
  end
50
50
 
51
+ def set_server_global_id_prefix(value)
52
+ timeout_wrap { @pipe.set_global_id_prefix(value) }
53
+ end
54
+
55
+ def server_global_id_prefix
56
+ timeout_wrap { @pipe.global_id_prefix }
57
+ end
58
+
51
59
  def generate_bank_token(recipient_params)
52
60
  timeout_wrap { @pipe.generate_bank_token(recipient_params) }
53
61
  end
@@ -100,7 +100,7 @@ module StripeMock
100
100
 
101
101
  def new_id(prefix)
102
102
  # Stripe ids must be strings
103
- "test_#{prefix}_#{@id_counter += 1}"
103
+ "#{StripeMock.global_id_prefix}#{prefix}_#{@id_counter += 1}"
104
104
  end
105
105
 
106
106
  def symbolize_names(hash)
@@ -47,6 +47,14 @@ module StripeMock
47
47
  @instance.strict = toggle
48
48
  end
49
49
 
50
+ def set_global_id_prefix(value)
51
+ StripeMock.global_id_prefix = value
52
+ end
53
+
54
+ def global_id_prefix
55
+ StripeMock.global_id_prefix
56
+ end
57
+
50
58
  def generate_card_token(card_params)
51
59
  @instance.generate_card_token(card_params)
52
60
  end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.10.1.2"
3
+ VERSION = "1.10.1.3"
4
4
  end
@@ -45,5 +45,4 @@ describe StripeMock::Instance do
45
45
  StripeMock.start
46
46
  expect(StripeMock.instance.debug).to eq(false)
47
47
  end
48
-
49
48
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Extra Features' do
4
+
5
+ it "can set the global id prefix" do
6
+ StripeMock.global_id_prefix = "custom_prefix_"
7
+ expect(StripeMock.global_id_prefix).to eq("custom_prefix_")
8
+
9
+ customer = Stripe::Customer.create
10
+ expect(customer.id).to match /^custom_prefix_cus/
11
+ end
12
+
13
+ it "can set the global id prefix to nothing" do
14
+ StripeMock.global_id_prefix = ""
15
+ expect(StripeMock.global_id_prefix).to eq("")
16
+
17
+ customer = Stripe::Customer.create
18
+ expect(customer.id).to match /^cus/
19
+
20
+ # Support false
21
+ StripeMock.global_id_prefix = false
22
+ expect(StripeMock.global_id_prefix).to eq("")
23
+
24
+ customer = Stripe::Customer.create
25
+ expect(customer.id).to match /^cus/
26
+ end
27
+
28
+ it "has a default global id prefix" do
29
+ StripeMock.global_id_prefix = nil
30
+ expect(StripeMock.global_id_prefix).to eq("test_")
31
+ customer = Stripe::Customer.create
32
+ expect(customer.id).to match /^test_cus/
33
+ end
34
+ end
@@ -7,6 +7,7 @@ def require_stripe_examples
7
7
  require 'shared_stripe_examples/coupon_examples'
8
8
  require 'shared_stripe_examples/customer_examples'
9
9
  require 'shared_stripe_examples/error_mock_examples'
10
+ require 'shared_stripe_examples/extra_features_examples'
10
11
  require 'shared_stripe_examples/invoice_examples'
11
12
  require 'shared_stripe_examples/invoice_item_examples'
12
13
  require 'shared_stripe_examples/plan_examples'
@@ -22,6 +23,7 @@ def it_behaves_like_stripe(&block)
22
23
  it_behaves_like 'Charge API', &block
23
24
  it_behaves_like 'Coupon API', &block
24
25
  it_behaves_like 'Customer API', &block
26
+ it_behaves_like 'Extra Features', &block
25
27
  it_behaves_like 'Invoice API', &block
26
28
  it_behaves_like 'Invoice Item API', &block
27
29
  it_behaves_like 'Plan API', &block
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.10.1.2
4
+ version: 1.10.1.3
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: 2014-03-04 00:00:00.000000000 Z
12
+ date: 2014-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe
@@ -129,6 +129,7 @@ files:
129
129
  - lib/stripe_mock/api/client.rb
130
130
  - lib/stripe_mock/api/debug.rb
131
131
  - lib/stripe_mock/api/errors.rb
132
+ - lib/stripe_mock/api/global_id_prefix.rb
132
133
  - lib/stripe_mock/api/instance.rb
133
134
  - lib/stripe_mock/api/server.rb
134
135
  - lib/stripe_mock/api/strict.rb
@@ -212,6 +213,7 @@ files:
212
213
  - spec/shared_stripe_examples/coupon_examples.rb
213
214
  - spec/shared_stripe_examples/customer_examples.rb
214
215
  - spec/shared_stripe_examples/error_mock_examples.rb
216
+ - spec/shared_stripe_examples/extra_features_examples.rb
215
217
  - spec/shared_stripe_examples/invoice_examples.rb
216
218
  - spec/shared_stripe_examples/invoice_item_examples.rb
217
219
  - spec/shared_stripe_examples/plan_examples.rb
@@ -262,6 +264,7 @@ test_files:
262
264
  - spec/shared_stripe_examples/coupon_examples.rb
263
265
  - spec/shared_stripe_examples/customer_examples.rb
264
266
  - spec/shared_stripe_examples/error_mock_examples.rb
267
+ - spec/shared_stripe_examples/extra_features_examples.rb
265
268
  - spec/shared_stripe_examples/invoice_examples.rb
266
269
  - spec/shared_stripe_examples/invoice_item_examples.rb
267
270
  - spec/shared_stripe_examples/plan_examples.rb