stripe-ruby-mock 1.8.4.5 → 1.8.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  In your gemfile:
9
9
 
10
- gem 'stripe-ruby-mock', '>= 1.8.4.4'
10
+ gem 'stripe-ruby-mock', '>= 1.8.4.6'
11
11
 
12
12
  ## Features
13
13
 
@@ -1,7 +1,7 @@
1
1
  module StripeMock
2
2
  module Data
3
3
 
4
- def self.test_customer(cards, params)
4
+ def self.mock_customer(cards, params)
5
5
  cus_id = params[:id] || "test_cus_default"
6
6
  cards.each {|card| card[:customer] = cus_id}
7
7
  {
@@ -25,7 +25,7 @@ module StripeMock
25
25
  }.merge(params)
26
26
  end
27
27
 
28
- def self.test_charge(params={})
28
+ def self.mock_charge(params={})
29
29
  {
30
30
  id: "ch_1fD6uiR9FAA2zc",
31
31
  object: "charge",
@@ -67,7 +67,7 @@ module StripeMock
67
67
  }.merge(params)
68
68
  end
69
69
 
70
- def self.test_charge_array
70
+ def self.mock_charge_array
71
71
  {
72
72
  :data => [test_charge, test_charge, test_charge],
73
73
  :object => 'list',
@@ -75,7 +75,7 @@ module StripeMock
75
75
  }
76
76
  end
77
77
 
78
- def self.test_card(params={})
78
+ def self.mock_card(params={})
79
79
  {
80
80
  id: "test_cc_default",
81
81
  object: "card",
@@ -99,7 +99,7 @@ module StripeMock
99
99
  }.merge(params)
100
100
  end
101
101
 
102
- def self.test_coupon(params={})
102
+ def self.mock_coupon(params={})
103
103
  {
104
104
  :duration => 'repeating',
105
105
  :duration_in_months => 3,
@@ -110,7 +110,7 @@ module StripeMock
110
110
  end
111
111
 
112
112
  #FIXME nested overrides would be better than hardcoding plan_id
113
- def self.test_subscription(params={})
113
+ def self.mock_subscription(params={})
114
114
  StripeMock::Util.rmerge({
115
115
  :current_period_end => 1308681468,
116
116
  :status => "trialing",
@@ -133,7 +133,7 @@ module StripeMock
133
133
  }, params)
134
134
  end
135
135
 
136
- def self.test_invoice(params={})
136
+ def self.mock_invoice(params={})
137
137
  {
138
138
  :id => 'in_test_invoice',
139
139
  :object => 'invoice',
@@ -173,7 +173,7 @@ module StripeMock
173
173
  }.merge(params)
174
174
  end
175
175
 
176
- def self.test_paid_invoice
176
+ def self.mock_paid_invoice
177
177
  test_invoice.merge({
178
178
  :attempt_count => 1,
179
179
  :attempted => true,
@@ -185,7 +185,7 @@ module StripeMock
185
185
  })
186
186
  end
187
187
 
188
- def self.test_invoice_customer_array
188
+ def self.mock_invoice_customer_array
189
189
  {
190
190
  :data => [test_invoice],
191
191
  :object => 'list',
@@ -193,7 +193,7 @@ module StripeMock
193
193
  }
194
194
  end
195
195
 
196
- def self.test_plan(params={})
196
+ def self.mock_plan(params={})
197
197
  {
198
198
  interval: "month",
199
199
  name: "The Basic Plan",
@@ -207,7 +207,7 @@ module StripeMock
207
207
  }.merge(params)
208
208
  end
209
209
 
210
- def self.test_recipient(params={})
210
+ def self.mock_recipient(params={})
211
211
  {
212
212
  :name => "Stripe User",
213
213
  :type => "individual",
@@ -225,7 +225,7 @@ module StripeMock
225
225
  }.merge(params)
226
226
  end
227
227
 
228
- def self.test_recipient_array
228
+ def self.mock_recipient_array
229
229
  {
230
230
  :data => [test_recipient, test_recipient, test_recipient],
231
231
  :object => 'list',
@@ -233,7 +233,7 @@ module StripeMock
233
233
  }
234
234
  end
235
235
 
236
- def self.test_transfer(params={})
236
+ def self.mock_transfer(params={})
237
237
  {
238
238
  :status => 'pending',
239
239
  :amount => 100,
@@ -254,7 +254,7 @@ module StripeMock
254
254
  }.merge(params)
255
255
  end
256
256
 
257
- def self.test_transfer_array
257
+ def self.mock_transfer_array
258
258
  {
259
259
  :data => [test_transfer, test_transfer, test_transfer],
260
260
  :object => 'list',
@@ -262,7 +262,7 @@ module StripeMock
262
262
  }
263
263
  end
264
264
 
265
- def self.test_invalid_api_key_error
265
+ def self.mock_invalid_api_key_error
266
266
  {
267
267
  "error" => {
268
268
  "type" => "invalid_request_error",
@@ -271,7 +271,7 @@ module StripeMock
271
271
  }
272
272
  end
273
273
 
274
- def self.test_invalid_exp_year_error
274
+ def self.mock_invalid_exp_year_error
275
275
  {
276
276
  "error" => {
277
277
  "code" => "invalid_expiry_year",
@@ -282,7 +282,7 @@ module StripeMock
282
282
  }
283
283
  end
284
284
 
285
- def self.test_missing_id_error
285
+ def self.mock_missing_id_error
286
286
  {
287
287
  :error => {
288
288
  :param => "id",
@@ -292,13 +292,13 @@ module StripeMock
292
292
  }
293
293
  end
294
294
 
295
- def self.test_delete_subscription(params={})
295
+ def self.mock_delete_subscription(params={})
296
296
  {
297
297
  deleted: true
298
298
  }.merge(params)
299
299
  end
300
300
 
301
- def self.test_api_error
301
+ def self.mock_api_error
302
302
  {
303
303
  :error => {
304
304
  :type => "api_error"
@@ -306,7 +306,7 @@ module StripeMock
306
306
  }
307
307
  end
308
308
 
309
- def self.test_delete_discount_response
309
+ def self.mock_delete_discount_response
310
310
  {
311
311
  :deleted => true,
312
312
  :id => "di_test_coupon"
@@ -68,13 +68,13 @@ module StripeMock
68
68
  def generate_card_token(card_params)
69
69
  token = new_id 'tok'
70
70
  card_params[:id] = new_id 'cc'
71
- @card_tokens[token] = Data.test_card(card_params)
71
+ @card_tokens[token] = Data.mock_card(card_params)
72
72
  token
73
73
  end
74
74
 
75
75
  def get_card_by_token(token)
76
76
  if token.nil? || @card_tokens[token].nil?
77
- Data.test_card :id => new_id('cc')
77
+ Data.mock_card :id => new_id('cc')
78
78
  else
79
79
  @card_tokens.delete(token)
80
80
  end
@@ -87,7 +87,7 @@ module StripeMock
87
87
 
88
88
  if obj.nil?
89
89
  msg = message || "No such #{type}: #{id}"
90
- raise Stripe::InvalidRequestError.new(msg, type.to_s, 400)
90
+ raise Stripe::InvalidRequestError.new(msg, type.to_s, 404)
91
91
  end
92
92
  end
93
93
 
@@ -9,13 +9,13 @@ module StripeMock
9
9
 
10
10
  def new_charge(route, method_url, params, headers)
11
11
  id = new_id('ch')
12
- charges[id] = Data.test_charge(params.merge :id => id)
12
+ charges[id] = Data.mock_charge(params.merge :id => id)
13
13
  end
14
14
 
15
15
  def get_charge(route, method_url, params, headers)
16
16
  route =~ method_url
17
17
  assert_existance :charge, $1, charges[$1]
18
- charges[$1] ||= Data.test_charge(:id => $1)
18
+ charges[$1] ||= Data.mock_charge(:id => $1)
19
19
  end
20
20
 
21
21
  end
@@ -18,7 +18,7 @@ module StripeMock
18
18
  cards << get_card_by_token(params.delete(:card))
19
19
  params[:default_card] = cards.first[:id]
20
20
  end
21
- customers[ params[:id] ] = Data.test_customer(cards, params)
21
+ customers[ params[:id] ] = Data.mock_customer(cards, params)
22
22
  end
23
23
 
24
24
  def update_subscription(route, method_url, params, headers)
@@ -29,7 +29,7 @@ module StripeMock
29
29
  plan = plans[ params[:plan] ]
30
30
  assert_existance :plan, params[:plan], plan
31
31
 
32
- sub = Data.test_subscription id: new_id('su'), plan: plan, customer: $1
32
+ sub = Data.mock_subscription id: new_id('su'), plan: plan, customer: $1
33
33
  customer[:subscription] = sub
34
34
  end
35
35
 
@@ -42,10 +42,12 @@ module StripeMock
42
42
  sub = customer[:subscription]
43
43
  assert_existance nil, nil, sub, "No active subscription for customer: #{$1}"
44
44
 
45
+ customer[:subscription] = nil
46
+
45
47
  plan = plans[ sub[:plan][:id] ]
46
48
  assert_existance :plan, params[:plan], plan
47
49
 
48
- Data.test_delete_subscription(id: sub[:id])
50
+ Data.mock_delete_subscription(id: sub[:id])
49
51
  end
50
52
 
51
53
  def update_customer(route, method_url, params, headers)
@@ -53,11 +55,11 @@ module StripeMock
53
55
  assert_existance :customer, $1, customers[$1]
54
56
 
55
57
  card_id = new_id('cc') if params.delete(:card)
56
- cus = customers[$1] ||= Data.test_customer([], :id => $1)
58
+ cus = customers[$1] ||= Data.mock_customer([], :id => $1)
57
59
  cus.merge!(params)
58
60
 
59
61
  if card_id
60
- new_card = Data.test_card(id: card_id, customer: cus[:id])
62
+ new_card = Data.mock_card(id: card_id, customer: cus[:id])
61
63
 
62
64
  if cus[:cards][:count] == 0
63
65
  cus[:cards][:count] += 1
@@ -74,7 +76,7 @@ module StripeMock
74
76
  def get_customer(route, method_url, params, headers)
75
77
  route =~ method_url
76
78
  assert_existance :customer, $1, customers[$1]
77
- customers[$1] ||= Data.test_customer([], :id => $1)
79
+ customers[$1] ||= Data.mock_customer([], :id => $1)
78
80
  end
79
81
 
80
82
  def list_customers(route, method_url, params, headers)
@@ -7,7 +7,7 @@ module StripeMock
7
7
  end
8
8
 
9
9
  def new_invoice_item(route, method_url, params, headers)
10
- Data.test_invoice(params)
10
+ Data.mock_invoice(params)
11
11
  end
12
12
 
13
13
  end
@@ -3,28 +3,35 @@ module StripeMock
3
3
  module Plans
4
4
 
5
5
  def Plans.included(klass)
6
- klass.add_handler 'post /v1/plans', :new_plan
7
- klass.add_handler 'post /v1/plans/(.*)', :update_plan
8
- klass.add_handler 'get /v1/plans/(.*)', :get_plan
9
- klass.add_handler 'get /v1/plans', :list_plans
6
+ klass.add_handler 'post /v1/plans', :new_plan
7
+ klass.add_handler 'post /v1/plans/(.*)', :update_plan
8
+ klass.add_handler 'get /v1/plans/(.*)', :get_plan
9
+ klass.add_handler 'delete /v1/plans/(.*)', :delete_plan
10
+ klass.add_handler 'get /v1/plans', :list_plans
10
11
  end
11
12
 
12
13
  def new_plan(route, method_url, params, headers)
13
14
  params[:id] ||= new_id('plan')
14
- plans[ params[:id] ] = Data.test_plan(params)
15
+ plans[ params[:id] ] = Data.mock_plan(params)
15
16
  end
16
17
 
17
18
  def update_plan(route, method_url, params, headers)
18
19
  route =~ method_url
19
20
  assert_existance :plan, $1, plans[$1]
20
- plans[$1] ||= Data.test_plan(:id => $1)
21
+ plans[$1] ||= Data.mock_plan(:id => $1)
21
22
  plans[$1].merge!(params)
22
23
  end
23
24
 
24
25
  def get_plan(route, method_url, params, headers)
25
26
  route =~ method_url
26
27
  assert_existance :plan, $1, plans[$1]
27
- plans[$1] ||= Data.test_plan(:id => $1)
28
+ plans[$1] ||= Data.mock_plan(:id => $1)
29
+ end
30
+
31
+ def delete_plan(route, method_url, params, headers)
32
+ route =~ method_url
33
+ assert_existance :plan, $1, plans[$1]
34
+ plans.delete($1)
28
35
  end
29
36
 
30
37
  def list_plans(route, method_url, params, headers)
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.8.4.5"
3
+ VERSION = "1.8.4.6"
4
4
  end
@@ -52,7 +52,7 @@ shared_examples 'Charge API' do
52
52
  expect { Stripe::Charge.retrieve('nope') }.to raise_error {|e|
53
53
  expect(e).to be_a Stripe::InvalidRequestError
54
54
  expect(e.param).to eq('charge')
55
- expect(e.http_status).to eq(400)
55
+ expect(e.http_status).to eq(404)
56
56
  }
57
57
  end
58
58
 
@@ -68,7 +68,7 @@ shared_examples 'Customer API' do
68
68
  expect { Stripe::Customer.retrieve('nope') }.to raise_error {|e|
69
69
  expect(e).to be_a Stripe::InvalidRequestError
70
70
  expect(e.param).to eq('customer')
71
- expect(e.http_status).to eq(400)
71
+ expect(e.http_status).to eq(404)
72
72
  }
73
73
  end
74
74
 
@@ -136,6 +136,8 @@ shared_examples 'Customer API' do
136
136
  result = customer.cancel_subscription
137
137
  expect(result.deleted).to eq(true)
138
138
  expect(result.id).to eq(sub.id)
139
+ customer = Stripe::Customer.retrieve('test_customer_sub')
140
+ expect(customer.subscription).to be_nil
139
141
  end
140
142
 
141
143
  it "cannot update to a plan that does not exist" do
@@ -74,10 +74,24 @@ shared_examples 'Plan API' do
74
74
  expect { Stripe::Plan.retrieve('nope') }.to raise_error {|e|
75
75
  expect(e).to be_a Stripe::InvalidRequestError
76
76
  expect(e.param).to eq('plan')
77
- expect(e.http_status).to eq(400)
77
+ expect(e.http_status).to eq(404)
78
78
  }
79
79
  end
80
80
 
81
+ it "deletes a stripe plan" do
82
+ Stripe::Plan.create(id: 'super_member', amount: 111)
83
+
84
+ plan = Stripe::Plan.retrieve('super_member')
85
+ expect(plan).to_not be_nil
86
+
87
+ plan.delete
88
+
89
+ expect { Stripe::Plan.retrieve('super_member') }.to raise_error {|e|
90
+ expect(e).to be_a Stripe::InvalidRequestError
91
+ expect(e.param).to eq('plan')
92
+ expect(e.http_status).to eq(404)
93
+ }
94
+ end
81
95
 
82
96
  it "retrieves all plans" do
83
97
  Stripe::Plan.create({ id: 'Plan One', amount: 54321 })
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.4.5
4
+ version: 1.8.4.6
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-07-26 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe