stripe-ruby-mock 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ rvm:
6
6
  before_script:
7
7
  - "sudo touch /var/log/stripe-mock-server.log"
8
8
  - "sudo chown travis /var/log/stripe-mock-server.log"
9
- script: "bundle exec rspec"
9
+ script: "bundle exec rspec; bundle exec rspec -t live"
10
10
  notifications:
11
11
  webhooks:
12
12
  urls:
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  In your gemfile:
10
10
 
11
- gem 'stripe-ruby-mock', '~> 2.1.0', :require => 'stripe_mock'
11
+ gem 'stripe-ruby-mock', '~> 2.1.1', :require => 'stripe_mock'
12
12
 
13
13
  ## Features
14
14
 
@@ -125,7 +125,7 @@ it "mocks a declined card error" do
125
125
  # Prepares an error for the next create charge request
126
126
  StripeMock.prepare_card_error(:card_declined)
127
127
 
128
- expect { Stripe::Charge.create }.to raise_error {|e|
128
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
129
129
  expect(e).to be_a Stripe::CardError
130
130
  expect(e.http_status).to eq(402)
131
131
  expect(e.code).to eq('card_declined')
@@ -181,7 +181,7 @@ it "raises a custom error for specific actions" do
181
181
 
182
182
  StripeMock.prepare_error(custom_error, :new_customer)
183
183
 
184
- expect { Stripe::Charge.create }.to_not raise_error
184
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to_not raise_error
185
185
  expect { Stripe::Customer.create }.to raise_error {|e|
186
186
  expect(e).to be_a StandardError
187
187
  expect(e.message).to eq("Please knock first.")
@@ -27,6 +27,8 @@ module StripeMock
27
27
  raise Stripe::InvalidRequestError.new("Invalid token id: #{params[:card]}", 'card', 400)
28
28
  end
29
29
 
30
+ ensure_required_params(params)
31
+
30
32
  charges[id] = Data.mock_charge(params.merge :id => id, :balance_transaction => new_balance_transaction('txn'))
31
33
  end
32
34
 
@@ -88,6 +90,31 @@ module StripeMock
88
90
  refund
89
91
  end
90
92
 
93
+ private
94
+
95
+ def ensure_required_params(params)
96
+ if params[:amount].nil?
97
+ require_param(:amount)
98
+ elsif params[:currency].nil?
99
+ require_param(:currency)
100
+ elsif non_integer_charge_amount?(params)
101
+ raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', 400)
102
+ elsif non_positive_charge_amount?(params)
103
+ raise Stripe::InvalidRequestError.new('Invalid positive integer', 'amount', 400)
104
+ end
105
+ end
106
+
107
+ def non_integer_charge_amount?(params)
108
+ params[:amount] && !params[:amount].is_a?(Integer)
109
+ end
110
+
111
+ def non_positive_charge_amount?(params)
112
+ params[:amount] && params[:amount] < 1
113
+ end
114
+
115
+ def require_param(param)
116
+ raise Stripe::InvalidRequestError.new("Missing required param: #{param}", param.to_s, 400)
117
+ end
91
118
  end
92
119
  end
93
120
  end
@@ -6,8 +6,13 @@ module StripeMock
6
6
  cards = object[:cards] || object[:sources]
7
7
  card = cards[:data].find{|cc| cc[:id] == card_id }
8
8
  if card.nil?
9
- msg = "#{class_name} #{object[:id]} does not have card #{card_id}"
10
- raise Stripe::InvalidRequestError.new(msg, 'card', 404)
9
+ if class_name == 'Recipient'
10
+ msg = "#{class_name} #{object[:id]} does not have a card with ID #{card_id}"
11
+ raise Stripe::InvalidRequestError.new(msg, 'card', 404)
12
+ else
13
+ msg = "There is no source with ID #{card_id}"
14
+ raise Stripe::InvalidRequestError.new(msg, 'id', 404)
15
+ end
11
16
  end
12
17
  card
13
18
  end
@@ -22,13 +27,14 @@ module StripeMock
22
27
  cards_or_sources[:data].delete_if {|card| card[:id] == object[:default_card]}
23
28
  object[:default_card] = card[:id] unless is_customer
24
29
  object[:default_source] = card[:id] if is_customer
30
+ cards_or_sources[:data] = [card]
25
31
  else
26
32
  cards_or_sources[:total_count] += 1
33
+ cards_or_sources[:data] << card
27
34
  end
28
35
 
29
36
  object[:default_card] = card[:id] if !is_customer && object[:default_card].nil?
30
37
  object[:default_source] = card[:id] if is_customer && object[:default_source].nil?
31
- cards_or_sources[:data] << card
32
38
 
33
39
  card
34
40
  end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "2.1.0"
3
+ VERSION = "2.1.1"
4
4
  end
@@ -33,9 +33,9 @@ describe StripeMock::Data::List do
33
33
  end
34
34
 
35
35
  it "eventually gets turned into a hash" do
36
- charge1 = Stripe::Charge.create
37
- charge2 = Stripe::Charge.create
38
- charge3 = Stripe::Charge.create
36
+ charge1 = Stripe::Charge.create(amount: 1, currency: 'usd')
37
+ charge2 = Stripe::Charge.create(amount: 1, currency: 'usd')
38
+ charge3 = Stripe::Charge.create(amount: 1, currency: 'usd')
39
39
  list = StripeMock::Data::List.new([charge1, charge2, charge3])
40
40
  hash = list.to_h
41
41
 
@@ -95,15 +95,15 @@ describe StripeMock::Data::List do
95
95
 
96
96
  context "pagination" do
97
97
  it "has a has_more field when it has more" do
98
- list = StripeMock::Data::List.new([Stripe::Charge.create] * 256)
98
+ list = StripeMock::Data::List.new([Stripe::Charge.create(amount: 1, currency: 'usd')] * 256)
99
99
 
100
100
  expect(list).to have_more
101
101
  end
102
102
 
103
103
  it "accepts a starting_after parameter" do
104
104
  data = []
105
- 255.times { data << Stripe::Charge.create }
106
- new_charge = Stripe::Charge.create
105
+ 255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd') }
106
+ new_charge = Stripe::Charge.create(amount: 1, currency: 'usd')
107
107
  data[89] = new_charge
108
108
  list = StripeMock::Data::List.new(data, starting_after: new_charge.id)
109
109
  hash = list.to_h
@@ -114,7 +114,7 @@ describe StripeMock::Data::List do
114
114
 
115
115
  it "raises an error if starting_after cursor is not found" do
116
116
  data = []
117
- 255.times { data << Stripe::Charge.create }
117
+ 255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd') }
118
118
  list = StripeMock::Data::List.new(data, starting_after: "test_ch_unknown")
119
119
 
120
120
  expect { list.to_h }.to raise_error
@@ -20,7 +20,7 @@ describe 'README examples' do
20
20
  # Prepares an error for the next create charge request
21
21
  StripeMock.prepare_card_error(:card_declined)
22
22
 
23
- expect { Stripe::Charge.create }.to raise_error {|e|
23
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
24
24
  expect(e).to be_a Stripe::CardError
25
25
  expect(e.http_status).to eq(402)
26
26
  expect(e.code).to eq('card_declined')
@@ -221,8 +221,8 @@ shared_examples 'Card API' do
221
221
  card_id = "card_123"
222
222
  expect { customer.sources.retrieve(card_id) }.to raise_error {|e|
223
223
  expect(e).to be_a Stripe::InvalidRequestError
224
- expect(e.message).to include "Customer", customer.id, "does not have", card_id
225
- expect(e.param).to eq 'card'
224
+ expect(e.message).to include "no source", card_id
225
+ expect(e.param).to eq 'id'
226
226
  expect(e.http_status).to eq 404
227
227
  }
228
228
  end
@@ -7,7 +7,7 @@ shared_examples 'Card Token Mocking' do
7
7
  it "generates and reads a card token for create charge" do
8
8
  card_token = StripeMock.generate_card_token(last4: "2244", exp_month: 33, exp_year: 2255)
9
9
 
10
- charge = Stripe::Charge.create(amount: 500, source: card_token)
10
+ charge = Stripe::Charge.create(amount: 500, currency: 'usd', source: card_token)
11
11
  card = charge.source
12
12
  expect(card.last4).to eq("2244")
13
13
  expect(card.exp_month).to eq(33)
@@ -12,6 +12,44 @@ shared_examples 'Charge API' do
12
12
  }.to raise_error(Stripe::InvalidRequestError, /token/i)
13
13
  end
14
14
 
15
+ it "requires presence of amount", :live => true do
16
+ expect {
17
+ charge = Stripe::Charge.create(
18
+ currency: 'usd',
19
+ card: stripe_helper.generate_card_token
20
+ )
21
+ }.to raise_error(Stripe::InvalidRequestError, /missing required param: amount/i)
22
+ end
23
+
24
+ it "requires presence of currency", :live => true do
25
+ expect {
26
+ charge = Stripe::Charge.create(
27
+ amount: 99,
28
+ card: stripe_helper.generate_card_token
29
+ )
30
+ }.to raise_error(Stripe::InvalidRequestError, /missing required param: currency/i)
31
+ end
32
+
33
+ it "requires a valid positive amount", :live => true do
34
+ expect {
35
+ charge = Stripe::Charge.create(
36
+ amount: -99,
37
+ currency: 'usd',
38
+ card: stripe_helper.generate_card_token
39
+ )
40
+ }.to raise_error(Stripe::InvalidRequestError, /invalid positive integer/i)
41
+ end
42
+
43
+ it "requires a valid integer amount", :live => true do
44
+ expect {
45
+ charge = Stripe::Charge.create(
46
+ amount: 99.0,
47
+ currency: 'usd',
48
+ card: stripe_helper.generate_card_token
49
+ )
50
+ }.to raise_error(Stripe::InvalidRequestError, /invalid integer/i)
51
+ end
52
+
15
53
  it "creates a stripe charge item with a card token" do
16
54
  charge = Stripe::Charge.create(
17
55
  amount: 999,
@@ -116,8 +154,8 @@ shared_examples 'Charge API' do
116
154
  context "retrieving a list of charges" do
117
155
  before do
118
156
  @customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
119
- @charge = Stripe::Charge.create(customer: @customer.id)
120
- @charge2 = Stripe::Charge.create
157
+ @charge = Stripe::Charge.create(amount: 1, currency: 'usd', customer: @customer.id)
158
+ @charge2 = Stripe::Charge.create(amount: 1, currency: 'usd')
121
159
  end
122
160
 
123
161
  it "stores charges for a customer in memory" do
@@ -129,12 +167,12 @@ shared_examples 'Charge API' do
129
167
  end
130
168
 
131
169
  it "defaults count to 10 charges" do
132
- 11.times { Stripe::Charge.create }
170
+ 11.times { Stripe::Charge.create(amount: 1, currency: 'usd') }
133
171
  expect(Stripe::Charge.all.data.count).to eq(10)
134
172
  end
135
173
 
136
174
  it "is marked as having more when more objects exist" do
137
- 11.times { Stripe::Charge.create }
175
+ 11.times { Stripe::Charge.create(amount: 1, currency: 'usd') }
138
176
 
139
177
  expect(Stripe::Charge.all.has_more).to eq(true)
140
178
  end
@@ -226,7 +226,7 @@ shared_examples 'Customer API' do
226
226
  original.save
227
227
 
228
228
  new_card = original.sources.data.last
229
- expect(original.sources.count).to eq(2)
229
+ expect(original.sources.count).to eq(1)
230
230
  expect(original.default_source).to_not eq(card.id)
231
231
 
232
232
  expect(new_card.id).to_not eq(card.id)
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  def expect_card_error(code, param)
4
- expect { Stripe::Charge.create() }.to raise_error {|e|
4
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
5
5
  expect(e).to be_a(Stripe::CardError)
6
6
  expect(e.http_status).to eq(402)
7
7
  expect(e.code).to eq(code)
@@ -33,7 +33,7 @@ shared_examples 'Stripe Error Mocking' do
33
33
  error = Stripe::InvalidRequestError.new('Test Invalid', 'param', 987, 'ibody', 'json ibody')
34
34
  StripeMock.prepare_error(error)
35
35
 
36
- expect { Stripe::Charge.create() }.to raise_error {|e|
36
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
37
37
  expect(e).to be_a(Stripe::InvalidRequestError)
38
38
  expect(e.param).to eq('param')
39
39
  expect(e.message).to eq('Test Invalid')
@@ -64,7 +64,7 @@ shared_examples 'Stripe Error Mocking' do
64
64
  custom_error = StandardError.new("Please knock first.")
65
65
  StripeMock.prepare_error(custom_error, :new_customer)
66
66
 
67
- expect { Stripe::Charge.create }.to_not raise_error
67
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to_not raise_error
68
68
  expect { Stripe::Customer.create }.to raise_error {|e|
69
69
  expect(e).to be_a StandardError
70
70
  expect(e.message).to eq("Please knock first.")
@@ -84,12 +84,12 @@ shared_examples 'Stripe Error Mocking' do
84
84
  it "only raises a card error when a card charge is attempted" do
85
85
  StripeMock.prepare_card_error(:card_declined)
86
86
  expect { Stripe::Customer.create(id: 'x') }.to_not raise_error
87
- expect { Stripe::Charge.create() }.to raise_error Stripe::CardError
87
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error Stripe::CardError
88
88
  end
89
89
 
90
90
  it "mocks a card error with a given handler" do
91
91
  StripeMock.prepare_card_error(:incorrect_cvc, :new_customer)
92
- expect { Stripe::Charge.create() }.to_not raise_error
92
+ expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to_not raise_error
93
93
 
94
94
  expect { Stripe::Customer.create() }.to raise_error {|e|
95
95
  expect(e).to be_a(Stripe::CardError)
@@ -568,8 +568,7 @@ shared_examples 'Customer Subscriptions' do
568
568
  :interval => 'month',
569
569
  :name => 'Sample Plan',
570
570
  :currency => 'usd',
571
- :id => 'Sample5',
572
- :statement_description => "Plan Statement"
571
+ :id => 'Sample5'
573
572
  )
574
573
 
575
574
  customer = Stripe::Customer.create({
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency 'stripe', '>= 1.20.1'
20
+ gem.add_dependency 'stripe', '= 1.20.1'
21
21
  gem.add_dependency 'jimson-temp'
22
22
  gem.add_dependency 'dante', '>= 0.2.0'
23
23
 
metadata CHANGED
@@ -1,60 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Gilbert
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-02-27 00:00:00.000000000 Z
12
+ date: 2015-03-19 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: stripe
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - '='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 1.20.1
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - '='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.20.1
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: jimson-temp
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: dante
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: 0.2.0
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: 0.2.0
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rspec
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rubygems-tasks
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
@@ -83,15 +94,17 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: thin
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - '>='
99
+ - - ! '>='
88
100
  - !ruby/object:Gem::Version
89
101
  version: '0'
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - '>='
107
+ - - ! '>='
95
108
  - !ruby/object:Gem::Version
96
109
  version: '0'
97
110
  description: A drop-in library to test stripe without hitting their servers
@@ -232,26 +245,27 @@ files:
232
245
  homepage: https://github.com/rebelidealist/stripe-ruby-mock
233
246
  licenses:
234
247
  - MIT
235
- metadata: {}
236
248
  post_install_message:
237
249
  rdoc_options: []
238
250
  require_paths:
239
251
  - lib
240
252
  required_ruby_version: !ruby/object:Gem::Requirement
253
+ none: false
241
254
  requirements:
242
- - - '>='
255
+ - - ! '>='
243
256
  - !ruby/object:Gem::Version
244
257
  version: '0'
245
258
  required_rubygems_version: !ruby/object:Gem::Requirement
259
+ none: false
246
260
  requirements:
247
- - - '>='
261
+ - - ! '>='
248
262
  - !ruby/object:Gem::Version
249
263
  version: '0'
250
264
  requirements: []
251
265
  rubyforge_project:
252
- rubygems_version: 2.2.2
266
+ rubygems_version: 1.8.25
253
267
  signing_key:
254
- specification_version: 4
268
+ specification_version: 3
255
269
  summary: TDD with stripe
256
270
  test_files:
257
271
  - spec/_dummy/webhooks/dummy.event.json
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 78209961f8a5b11ad4a2146246a6162b534af59e
4
- data.tar.gz: 3192d4420c6f44537422804b4b60fb479584f6db
5
- SHA512:
6
- metadata.gz: fcec4c716ccd97608cb2e81c001baf9e174cc32e29d7578dd1ff5cb2eff1b412ba74299c5e0ae913e4f4fab01951cc3ea3f7f2927f040c6eca9b62891f30ad3a
7
- data.tar.gz: 4a643be3f0acca2ad89dfc44dc76484df58c400f0bfcafca62338a0095dafdd4d7f5104ed9fa200d1cd6321db6dab616032bdbb6c6c8a88bb33f60117f510664