stripe-ruby-mock 1.8.3.0 → 1.8.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -198,6 +198,20 @@ module StripeMock
198
198
  }
199
199
  end
200
200
 
201
+ def self.test_plan(params={})
202
+ {
203
+ interval: "month",
204
+ name: "The Basic Plan",
205
+ amount: 2300,
206
+ currency: "usd",
207
+ id: "2",
208
+ object: "plan",
209
+ livemode: false,
210
+ interval_count: 1,
211
+ trial_period_days: nil
212
+ }.merge(params)
213
+ end
214
+
201
215
  def self.test_recipient(params={})
202
216
  {
203
217
  :name => "Stripe User",
@@ -14,14 +14,17 @@ module StripeMock
14
14
  include StripeMock::RequestHandlers::Charges
15
15
  include StripeMock::RequestHandlers::Customers
16
16
  include StripeMock::RequestHandlers::InvoiceItems
17
+ include StripeMock::RequestHandlers::Plans
17
18
 
18
19
 
19
- attr_reader :charges, :customers
20
+ attr_reader :charges, :customers, :plans
20
21
  attr_accessor :pending_error
21
22
 
22
23
  def initialize
23
24
  @customers = {}
24
25
  @charges = {}
26
+ @plans = {}
27
+
25
28
  @id_counter = 0
26
29
  @pending_error = nil
27
30
  end
@@ -0,0 +1,22 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module Plans
4
+
5
+ def Plans.included(klass)
6
+ klass.add_handler 'post /v1/plans', :new_plan
7
+ klass.add_handler 'get /v1/plans/(.*)', :get_plan
8
+ end
9
+
10
+ def new_plan(route, method_url, params, headers)
11
+ params[:id] ||= new_id
12
+ plans[ params[:id] ] = Data.test_plan(params)
13
+ end
14
+
15
+ def get_plan(route, method_url, params, headers)
16
+ route =~ method_url
17
+ plans[$1] ||= Data.test_plan(:id => $1)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.8.3.0"
3
+ VERSION = "1.8.3.1"
4
4
  end
data/lib/stripe_mock.rb CHANGED
@@ -9,4 +9,5 @@ require 'stripe_mock/api/errors'
9
9
  require 'stripe_mock/request_handlers/charges.rb'
10
10
  require 'stripe_mock/request_handlers/customers.rb'
11
11
  require 'stripe_mock/request_handlers/invoice_items.rb'
12
+ require 'stripe_mock/request_handlers/plans.rb'
12
13
  require 'stripe_mock/instance'
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Plan API' do
4
+
5
+ before { StripeMock.start }
6
+ after { StripeMock.stop }
7
+
8
+ it "creates a stripe plan" do
9
+ plan = Stripe::Plan.create(
10
+ :id => 'pid_1',
11
+ :name => 'The Mock Plan',
12
+ :amount => 9900,
13
+ :currency => 'USD',
14
+ :interval => 1,
15
+ :trial_period_days => 30
16
+ )
17
+
18
+ expect(plan.id).to eq('pid_1')
19
+ expect(plan.name).to eq('The Mock Plan')
20
+ expect(plan.amount).to eq(9900)
21
+
22
+ expect(plan.currency).to eq('USD')
23
+ expect(plan.interval).to eq(1)
24
+ expect(plan.trial_period_days).to eq(30)
25
+ end
26
+
27
+
28
+ it "stores a created stripe plan in memory" do
29
+ plan = Stripe::Plan.create(
30
+ :id => 'pid_2',
31
+ :name => 'The Memory Plan',
32
+ :amount => 1100,
33
+ :currency => 'USD',
34
+ :interval => 1
35
+ )
36
+ plan2 = Stripe::Plan.create(
37
+ :id => 'pid_3',
38
+ :name => 'The Bonk Plan',
39
+ :amount => 7777,
40
+ :currency => 'USD',
41
+ :interval => 1
42
+ )
43
+ data = StripeMock.instance.plans
44
+ expect(data[plan.id]).to_not be_nil
45
+ expect(data[plan.id][:amount]).to eq(1100)
46
+
47
+ expect(data[plan2.id]).to_not be_nil
48
+ expect(data[plan2.id][:amount]).to eq(7777)
49
+ end
50
+
51
+
52
+ it "retrieves a stripe plan" do
53
+ original = Stripe::Plan.create({
54
+ amount: 1331
55
+ })
56
+ plan = Stripe::Plan.retrieve(original.id)
57
+
58
+ expect(plan.id).to eq(original.id)
59
+ expect(plan.amount).to eq(original.amount)
60
+ end
61
+
62
+
63
+ it "retrieves a stripe plan with an id that doesn't exist" do
64
+ plan = Stripe::Plan.retrieve('test_charge_x')
65
+
66
+ expect(plan.id).to eq('test_charge_x')
67
+ expect(plan.amount).to_not be_nil
68
+ expect(plan.name).to_not be_nil
69
+
70
+ expect(plan.currency).to_not be_nil
71
+ expect(plan.interval).to_not be_nil
72
+ end
73
+
74
+ 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.3.0
4
+ version: 1.8.3.1
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-05-19 00:00:00.000000000 Z
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe
@@ -79,6 +79,7 @@ files:
79
79
  - lib/stripe_mock/request_handlers/charges.rb
80
80
  - lib/stripe_mock/request_handlers/customers.rb
81
81
  - lib/stripe_mock/request_handlers/invoice_items.rb
82
+ - lib/stripe_mock/request_handlers/plans.rb
82
83
  - lib/stripe_mock/version.rb
83
84
  - spec/readme_spec.rb
84
85
  - spec/spec_helper.rb
@@ -86,6 +87,7 @@ files:
86
87
  - spec/stripe/customer_spec.rb
87
88
  - spec/stripe/error_mock_spec.rb
88
89
  - spec/stripe/invoice_item_spec.rb
90
+ - spec/stripe/plan_spec.rb
89
91
  - spec/stripe_mock_spec.rb
90
92
  - stripe-ruby-mock.gemspec
91
93
  homepage: https://github.com/mindeavor/stripe-ruby-mock
@@ -120,4 +122,5 @@ test_files:
120
122
  - spec/stripe/customer_spec.rb
121
123
  - spec/stripe/error_mock_spec.rb
122
124
  - spec/stripe/invoice_item_spec.rb
125
+ - spec/stripe/plan_spec.rb
123
126
  - spec/stripe_mock_spec.rb