stripe-ruby-mock 1.10.1.0 → 1.10.1.1

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 CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  In your gemfile:
10
10
 
11
- gem 'stripe-ruby-mock', '>= 1.10.1.0'
11
+ gem 'stripe-ruby-mock', '>= 1.10.1.1'
12
12
 
13
13
  ## Features
14
14
 
@@ -131,8 +131,15 @@ module StripeMock
131
131
  :duration => 'repeating',
132
132
  :duration_in_months => 3,
133
133
  :percent_off => 25,
134
+ :amount_off => nil,
135
+ :currency => nil,
134
136
  :id => "co_test_coupon",
135
- :object => "coupon"
137
+ :object => "coupon",
138
+ :max_redemptions => nil,
139
+ :redeem_by => nil,
140
+ :times_redeemed => 0,
141
+ :valid => true,
142
+ :metadata => {},
136
143
  }.merge(params)
137
144
  end
138
145
 
@@ -19,6 +19,7 @@ module StripeMock
19
19
  include StripeMock::RequestHandlers::Cards
20
20
  include StripeMock::RequestHandlers::Subscriptions # must be before Customers
21
21
  include StripeMock::RequestHandlers::Customers
22
+ include StripeMock::RequestHandlers::Coupons
22
23
  include StripeMock::RequestHandlers::Events
23
24
  include StripeMock::RequestHandlers::Invoices
24
25
  include StripeMock::RequestHandlers::InvoiceItems
@@ -27,7 +28,7 @@ module StripeMock
27
28
  include StripeMock::RequestHandlers::Tokens
28
29
 
29
30
 
30
- attr_reader :bank_tokens, :charges, :customers, :events,
31
+ attr_reader :bank_tokens, :charges, :coupons, :customers, :events,
31
32
  :invoices, :plans, :recipients, :subscriptions
32
33
 
33
34
  attr_accessor :error_queue, :debug, :strict
@@ -37,6 +38,7 @@ module StripeMock
37
38
  @card_tokens = {}
38
39
  @customers = {}
39
40
  @charges = {}
41
+ @coupons = {}
40
42
  @events = {}
41
43
  @invoices = {}
42
44
  @plans = {}
@@ -0,0 +1,35 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module Coupons
4
+
5
+ def Coupons.included(klass)
6
+ klass.add_handler 'post /v1/coupons', :new_coupon
7
+ klass.add_handler 'get /v1/coupons/(.*)', :get_coupon
8
+ klass.add_handler 'delete /v1/coupons/(.*)', :delete_coupon
9
+ klass.add_handler 'get /v1/coupons', :list_coupons
10
+ end
11
+
12
+ def new_coupon(route, method_url, params, headers)
13
+ params[:id] ||= new_id('coupon')
14
+ coupons[ params[:id] ] = Data.mock_coupon(params)
15
+ end
16
+
17
+ def get_coupon(route, method_url, params, headers)
18
+ route =~ method_url
19
+ assert_existance :coupon, $1, coupons[$1]
20
+ coupons[$1] ||= Data.mock_coupon(:id => $1)
21
+ end
22
+
23
+ def delete_coupon(route, method_url, params, headers)
24
+ route =~ method_url
25
+ assert_existance :coupon, $1, coupons[$1]
26
+ coupons.delete($1)
27
+ end
28
+
29
+ def list_coupons(route, method_url, params, headers)
30
+ coupons.values
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.10.1.0"
3
+ VERSION = "1.10.1.1"
4
4
  end
@@ -16,7 +16,8 @@
16
16
  "redeem_by": null,
17
17
  "max_redemptions": null,
18
18
  "times_redeemed": 0,
19
- "duration_in_months": 3
19
+ "duration_in_months": 3,
20
+ "valid": true
20
21
  }
21
22
  }
22
23
  }
@@ -2,51 +2,22 @@
2
2
  "created": 1326853478,
3
3
  "livemode": false,
4
4
  "id": "evt_00000000000000",
5
- "type": "customer.deleted",
5
+ "type": "coupon.deleted",
6
6
  "object": "event",
7
7
  "data": {
8
8
  "object": {
9
- "object": "customer",
10
- "created": 1375148334,
11
- "id": "cus_00000000000000",
9
+ "id": "25OFF_00000000000000",
10
+ "percent_off": 25,
11
+ "amount_off": null,
12
+ "currency": "usd",
13
+ "object": "coupon",
12
14
  "livemode": false,
13
- "description": null,
14
- "email": "bond@mailinator.com",
15
- "delinquent": true,
16
- "metadata": {
17
- },
18
- "subscription": null,
19
- "discount": null,
20
- "account_balance": 0,
21
- "cards": {
22
- "object": "list",
23
- "count": 1,
24
- "url": "/v1/customers/cus_2I2AhGQOPmEFeu/cards",
25
- "data": [
26
- {
27
- "id": "cc_2I2akIhmladin5",
28
- "object": "card",
29
- "last4": "0341",
30
- "type": "Visa",
31
- "exp_month": 12,
32
- "exp_year": 2013,
33
- "fingerprint": "fWvZEzdbEIFF8QrK",
34
- "customer": "cus_2I2AhGQOPmEFeu",
35
- "country": "US",
36
- "name": "Johnny Goodman",
37
- "address_line1": null,
38
- "address_line2": null,
39
- "address_city": null,
40
- "address_state": null,
41
- "address_zip": null,
42
- "address_country": null,
43
- "cvc_check": "pass",
44
- "address_line1_check": null,
45
- "address_zip_check": null
46
- }
47
- ]
48
- },
49
- "default_card": "cc_2I2akIhmladin5"
15
+ "duration": "repeating",
16
+ "redeem_by": null,
17
+ "max_redemptions": null,
18
+ "times_redeemed": 0,
19
+ "duration_in_months": 3,
20
+ "valid": false
50
21
  }
51
22
  }
52
23
  }
data/lib/stripe_mock.rb CHANGED
@@ -32,6 +32,7 @@ require 'stripe_mock/api/debug'
32
32
  require 'stripe_mock/request_handlers/charges.rb'
33
33
  require 'stripe_mock/request_handlers/cards.rb'
34
34
  require 'stripe_mock/request_handlers/customers.rb'
35
+ require 'stripe_mock/request_handlers/coupons.rb'
35
36
  require 'stripe_mock/request_handlers/events.rb'
36
37
  require 'stripe_mock/request_handlers/invoices.rb'
37
38
  require 'stripe_mock/request_handlers/invoice_items.rb'
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Coupon API' do
4
+
5
+ let(:percent_off_attributes) do
6
+ {
7
+ :id => '25PERCENT',
8
+ :percent_off => 25,
9
+ :redeem_by => nil,
10
+ :duration_in_months => 3,
11
+ }
12
+ end
13
+
14
+ it "creates a stripe coupon" do
15
+ coupon = Stripe::Coupon.create(
16
+ :id => '10BUCKS',
17
+ :amount_off => 1000,
18
+ :currency => 'USD',
19
+ :max_redemptions => 100,
20
+ :metadata => {
21
+ :created_by => 'admin_acct_1',
22
+ },
23
+ )
24
+
25
+ expect(coupon.id).to eq('10BUCKS')
26
+ expect(coupon.amount_off).to eq(1000)
27
+
28
+ expect(coupon.currency).to eq('USD')
29
+ expect(coupon.max_redemptions).to eq(100)
30
+ expect(coupon.metadata.to_hash).to eq( { :created_by => 'admin_acct_1' } )
31
+ end
32
+
33
+
34
+ it "stores a created stripe coupon in memory" do
35
+ coupon = Stripe::Coupon.create(
36
+ :id => '10BUCKS',
37
+ :amount_off => 1000,
38
+ :currency => 'USD',
39
+ :redeem_by => nil,
40
+ :max_redemptions => 100,
41
+ :metadata => {
42
+ :created_by => 'admin_acct_1',
43
+ },
44
+ )
45
+ coupon2 = Stripe::Coupon.create(percent_off_attributes)
46
+
47
+ data = test_data_source(:coupons)
48
+ expect(data[coupon.id]).to_not be_nil
49
+ expect(data[coupon.id][:amount_off]).to eq(1000)
50
+
51
+ expect(data[coupon2.id]).to_not be_nil
52
+ expect(data[coupon2.id][:percent_off]).to eq(25)
53
+ end
54
+
55
+
56
+ it "retrieves a stripe coupon" do
57
+ original = Stripe::Coupon.create(percent_off_attributes)
58
+ coupon = Stripe::Coupon.retrieve(original.id)
59
+
60
+ expect(coupon.id).to eq(original.id)
61
+ expect(coupon.percent_off).to eq(original.percent_off)
62
+ end
63
+
64
+
65
+ it "cannot retrieve a stripe coupon that doesn't exist" do
66
+ expect { Stripe::Coupon.retrieve('nope') }.to raise_error {|e|
67
+ expect(e).to be_a Stripe::InvalidRequestError
68
+ expect(e.param).to eq('coupon')
69
+ expect(e.http_status).to eq(404)
70
+ }
71
+ end
72
+
73
+ it "deletes a stripe coupon" do
74
+ original = Stripe::Coupon.create(percent_off_attributes)
75
+ coupon = Stripe::Coupon.retrieve(original.id)
76
+
77
+ coupon.delete
78
+
79
+ expect { Stripe::Coupon.retrieve(original.id) }.to raise_error {|e|
80
+ expect(e).to be_a Stripe::InvalidRequestError
81
+ expect(e.param).to eq('coupon')
82
+ expect(e.http_status).to eq(404)
83
+ }
84
+ end
85
+
86
+ it "retrieves all coupons" do
87
+ Stripe::Coupon.create({ id: 'Coupon One', amount_off: 1500 })
88
+ Stripe::Coupon.create({ id: 'Coupon Two', amount_off: 3000 })
89
+
90
+ all = Stripe::Coupon.all
91
+ expect(all.length).to eq(2)
92
+ all.map(&:id).should include('Coupon One', 'Coupon Two')
93
+ all.map(&:amount_off).should include(1500, 3000)
94
+ end
95
+
96
+
97
+ context "With strict mode toggled off" do
98
+
99
+ before { StripeMock.toggle_strict(false) }
100
+
101
+ it "can retrieve a stripe coupon with an id that doesn't exist" do
102
+ coupon = Stripe::Coupon.retrieve('test_coupon_x')
103
+
104
+ expect(coupon.id).to eq('test_coupon_x')
105
+ expect(coupon.percent_off).to_not be_nil
106
+ expect(coupon.valid).to be_true
107
+ end
108
+ end
109
+
110
+ end
@@ -4,6 +4,7 @@ def require_stripe_examples
4
4
  require 'shared_stripe_examples/card_token_examples'
5
5
  require 'shared_stripe_examples/card_examples'
6
6
  require 'shared_stripe_examples/charge_examples'
7
+ require 'shared_stripe_examples/coupon_examples'
7
8
  require 'shared_stripe_examples/customer_examples'
8
9
  require 'shared_stripe_examples/error_mock_examples'
9
10
  require 'shared_stripe_examples/invoice_examples'
@@ -19,6 +20,7 @@ def it_behaves_like_stripe(&block)
19
20
  it_behaves_like 'Card Token Mocking', &block
20
21
  it_behaves_like 'Card API', &block
21
22
  it_behaves_like 'Charge API', &block
23
+ it_behaves_like 'Coupon API', &block
22
24
  it_behaves_like 'Customer API', &block
23
25
  it_behaves_like 'Invoice API', &block
24
26
  it_behaves_like 'Invoice Item 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.0
4
+ version: 1.10.1.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: 2014-02-23 00:00:00.000000000 Z
12
+ date: 2014-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe
@@ -145,6 +145,7 @@ files:
145
145
  - lib/stripe_mock/instance.rb
146
146
  - lib/stripe_mock/request_handlers/cards.rb
147
147
  - lib/stripe_mock/request_handlers/charges.rb
148
+ - lib/stripe_mock/request_handlers/coupons.rb
148
149
  - lib/stripe_mock/request_handlers/customers.rb
149
150
  - lib/stripe_mock/request_handlers/events.rb
150
151
  - lib/stripe_mock/request_handlers/invoice_items.rb
@@ -205,6 +206,7 @@ files:
205
206
  - spec/shared_stripe_examples/card_examples.rb
206
207
  - spec/shared_stripe_examples/card_token_examples.rb
207
208
  - spec/shared_stripe_examples/charge_examples.rb
209
+ - spec/shared_stripe_examples/coupon_examples.rb
208
210
  - spec/shared_stripe_examples/customer_examples.rb
209
211
  - spec/shared_stripe_examples/error_mock_examples.rb
210
212
  - spec/shared_stripe_examples/invoice_examples.rb
@@ -254,6 +256,7 @@ test_files:
254
256
  - spec/shared_stripe_examples/card_examples.rb
255
257
  - spec/shared_stripe_examples/card_token_examples.rb
256
258
  - spec/shared_stripe_examples/charge_examples.rb
259
+ - spec/shared_stripe_examples/coupon_examples.rb
257
260
  - spec/shared_stripe_examples/customer_examples.rb
258
261
  - spec/shared_stripe_examples/error_mock_examples.rb
259
262
  - spec/shared_stripe_examples/invoice_examples.rb