stripe-ruby-mock 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a938c591e648a2e11b45f6ef5fe9501960b8ef9
4
- data.tar.gz: 128f7dd797e0dc2e3e308228187326eb9fbd953a
3
+ metadata.gz: 1a65b2647db5f0f6f73a77e652adff727dd79961
4
+ data.tar.gz: c099d2e35303617b14ed7a7a02d26f62db3277fd
5
5
  SHA512:
6
- metadata.gz: 55bdfab487061c0be56698383d87b2b7641d3dedf1925cc18e0de75837f1179438442aaf4234fc590fe5f325414ba7dc5ec3fc427f8e6c88061d735ec81d8534
7
- data.tar.gz: 76f52b22076b7bea8f6c8b2206e2bf3933911ea63f42f7bb88021e6b76b5bf802805101cbe61dbcb29369559437020eec06c6721c5e27933db69f11352b4efd3
6
+ metadata.gz: e1740053ed12209ef9ffceb2df5a136226a3bee058e212b86a2cf0d0079b3ad12598cadc3e4912b14e3b53bbc892679d6c15c97404147cc4cad6cbcbab845902
7
+ data.tar.gz: 16df616215aae851e27b6d16f18855a5c78bc1014448cdb83b14becc5e860b88c772a2e3f7c633227164c4069acc6b3314a5c5286d2b56c9dc3a4face61e0ded
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ stripe-mock-server.pid
5
5
  Gemfile.lock
6
6
  stripe-mock-server.log
7
7
  .idea
8
+ .ruby-version
data/README.md CHANGED
@@ -12,7 +12,7 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'
12
12
 
13
13
  In your gemfile:
14
14
 
15
- gem 'stripe-ruby-mock', '~> 2.2.0', :require => 'stripe_mock'
15
+ gem 'stripe-ruby-mock', '~> 2.2.1', :require => 'stripe_mock'
16
16
 
17
17
  ## Features
18
18
 
@@ -23,7 +23,7 @@ In your gemfile:
23
23
 
24
24
  ### Specifications
25
25
 
26
- **STRIPE API TARGET VERSION:** 2015-02-18 (master)
26
+ **STRIPE API TARGET VERSION:** 2015-09-08 (master)
27
27
 
28
28
  Older API version branches:
29
29
 
@@ -58,10 +58,21 @@ module StripeMock
58
58
  def update_customer(route, method_url, params, headers)
59
59
  route =~ method_url
60
60
  cus = assert_existence :customer, $1, customers[$1]
61
+
62
+ # Delete those params if their value is nil. Workaround of the problematic way Stripe serialize objects
63
+ params.delete(:sources) if params[:sources] && params[:sources][:data].nil?
64
+ params.delete(:subscriptions) if params[:subscriptions] && params[:subscriptions][:data].nil?
61
65
  cus.merge!(params)
62
66
 
63
- if params[:source]
64
- new_card = get_card_by_token(params.delete(:source))
67
+ if params[:source]
68
+ if params[:source].is_a?(String)
69
+ new_card = get_card_by_token(params.delete(:source))
70
+ elsif params[:source].is_a?(Hash)
71
+ unless params[:source][:object] && params[:source][:number] && params[:source][:exp_month] && params[:source][:exp_year]
72
+ raise Stripe::InvalidRequestError.new('You must supply a valid card', nil, 400)
73
+ end
74
+ new_card = card_from_params(params.delete(:source))
75
+ end
65
76
  add_card_to_object(:customer, new_card, cus, true)
66
77
  cus[:default_source] = new_card[:id]
67
78
  end
@@ -20,6 +20,12 @@ module StripeMock
20
20
  # params[:card] is an id; grab it from the db
21
21
  customer_card = get_card(customer, params[:source])
22
22
  assert_existence :card, params[:source], customer_card
23
+ elsif params[:card].is_a?(String)
24
+ customer = assert_existence :customer, cus_id, customers[cus_id]
25
+
26
+ # params[:card] is an id; grab it from the db
27
+ customer_card = get_card(customer, params[:card])
28
+ assert_existence :card, params[:card], customer_card
23
29
  elsif params[:card]
24
30
  # params[:card] is a hash of cc info; "Sanitize" the card number
25
31
  params[:card][:fingerprint] = StripeMock::Util.fingerprint(params[:card][:number])
@@ -26,7 +26,7 @@ module StripeMock
26
26
  _transfers = _transfers.first([params[:limit], _transfers.size].min)
27
27
  end
28
28
 
29
- _transfers
29
+ Data.mock_list_object(_transfers, params)
30
30
  end
31
31
 
32
32
  def new_transfer(route, method_url, params, headers)
@@ -15,7 +15,7 @@ module StripeMock
15
15
  def generate_card_token(card_params={})
16
16
  card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => 2018, :cvc => "999" }
17
17
  card = StripeMock::Util.card_merge(card_data, card_params)
18
- card[:fingerprint] = StripeMock::Util.fingerprint(card[:number])
18
+ card[:fingerprint] = StripeMock::Util.fingerprint(card[:number]) if StripeMock.state == 'local'
19
19
 
20
20
  stripe_token = Stripe::Token.create(:card => card)
21
21
  stripe_token.id
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "2.2.0"
3
+ VERSION = "2.2.1"
4
4
  end
@@ -106,6 +106,64 @@ shared_examples 'Card Token Mocking' do
106
106
  expect(card_token.object).to eq("token")
107
107
  end
108
108
 
109
+ it "generates a card token from another card" do
110
+ token = StripeMock.generate_card_token(last4: "2244", exp_month: 33, exp_year: 2255)
111
+
112
+ cus1 = Stripe::Customer.create()
113
+ cus1.source = token
114
+ cus1.save
115
+
116
+ card1 = cus1.sources.data.first
117
+ expect(card1.last4).to eq("2244")
118
+ expect(card1.exp_month).to eq(33)
119
+ expect(card1.exp_year).to eq(2255)
120
+
121
+ card_token = Stripe::Token.create({
122
+ customer: cus1.id,
123
+ card: card1.id
124
+ })
125
+
126
+ cus2 = Stripe::Customer.create()
127
+ cus2.source = card_token.id
128
+ cus2.save
129
+
130
+ card2 = cus2.sources.data.first
131
+ expect(card2.last4).to eq("2244")
132
+ expect(card2.exp_month).to eq(33)
133
+ expect(card2.exp_year).to eq(2255)
134
+ end
135
+
136
+ it 'generates a card token from another card', oauth: true do
137
+ token = Stripe::Token.create(
138
+ card: {
139
+ exp_month: 10,
140
+ exp_year: 2016,
141
+ number: '4242424242424242'
142
+ }
143
+ )
144
+
145
+ cus1 = Stripe::Customer.create(source: token.id)
146
+
147
+ card1 = cus1.sources.data.first
148
+ expect(card1.last4).to eq('4242')
149
+ expect(card1.exp_month).to eq(10)
150
+ expect(card1.exp_year).to eq(2016)
151
+
152
+ card_token = Stripe::Token.create(
153
+ {
154
+ customer: cus1.id,
155
+ card: card1.id
156
+ },
157
+ ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
158
+
159
+ cus2 = Stripe::Customer.create({ source: card_token.id }, ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
160
+
161
+ card2 = cus2.sources.data.first
162
+ expect(card2.last4).to eq('4242')
163
+ expect(card2.exp_month).to eq(10)
164
+ expect(card2.exp_year).to eq(2016)
165
+ end
166
+
109
167
  it "throws an error if neither card nor customer are provided", :live => true do
110
168
  expect { Stripe::Token.create }.to raise_error(
111
169
  Stripe::InvalidRequestError, /must supply either a card, customer/
@@ -271,8 +271,18 @@ shared_examples 'Customer API' do
271
271
  expect(customer.discount.coupon).to be_a Stripe::Coupon
272
272
  end
273
273
 
274
- it "updates a stripe customer's card" do
275
- original = Stripe::Customer.create(id: 'test_customer_update', source: gen_card_tk)
274
+ it "retrieves the customer's default source after it was updated" do
275
+ customer = Stripe::Customer.create()
276
+ customer.source = gen_card_tk
277
+ customer.save
278
+ card = customer.sources.retrieve(customer.default_source)
279
+
280
+ expect(customer.sources).to be_a(Stripe::ListObject)
281
+ expect(card).to be_a(Stripe::Card)
282
+ end
283
+
284
+ it "updates a stripe customer's card from a token" do
285
+ original = Stripe::Customer.create( source: gen_card_tk)
276
286
  card = original.sources.data.first
277
287
  expect(original.default_source).to eq(card.id)
278
288
  expect(original.sources.data.count).to eq(1)
@@ -287,6 +297,27 @@ shared_examples 'Customer API' do
287
297
  expect(new_card.id).to_not eq(card.id)
288
298
  end
289
299
 
300
+ it "updates a stripe customer's card from a hash" do
301
+ original = Stripe::Customer.create( source: gen_card_tk)
302
+ card = original.sources.data.first
303
+ expect(original.default_source).to eq(card.id)
304
+ expect(original.sources.data.count).to eq(1)
305
+
306
+ original.source = {
307
+ object: 'card',
308
+ number: '4012888888881881',
309
+ exp_year: 2018,
310
+ exp_month: 12,
311
+ cvc: 666
312
+ }
313
+
314
+ original.save
315
+
316
+ new_card = original.sources.data.last
317
+ expect(original.sources.data.count).to eq(1)
318
+ expect(original.default_source).to_not eq(card.id)
319
+ end
320
+
290
321
  it "deletes a customer" do
291
322
  customer = Stripe::Customer.create(id: 'test_customer_sub')
292
323
  customer = customer.delete
@@ -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.27.0'
20
+ gem.add_dependency 'stripe', '1.31.0'
21
21
  gem.add_dependency 'jimson-temp'
22
22
  gem.add_dependency 'dante', '>= 0.2.0'
23
23
 
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-23 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stripe
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.27.0
19
+ version: 1.31.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.27.0
26
+ version: 1.31.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jimson-temp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dante
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.1.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubygems-tasks
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: thin
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: A drop-in library to test stripe without hitting their servers
@@ -101,9 +101,9 @@ executables:
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - ".gitignore"
105
- - ".rspec"
106
- - ".travis.yml"
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
107
  - ChangeLog.rdoc
108
108
  - Gemfile
109
109
  - LICENSE.txt
@@ -242,17 +242,17 @@ require_paths:
242
242
  - lib
243
243
  required_ruby_version: !ruby/object:Gem::Requirement
244
244
  requirements:
245
- - - ">="
245
+ - - '>='
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  required_rubygems_version: !ruby/object:Gem::Requirement
249
249
  requirements:
250
- - - ">="
250
+ - - '>='
251
251
  - !ruby/object:Gem::Version
252
252
  version: '0'
253
253
  requirements: []
254
254
  rubyforge_project:
255
- rubygems_version: 2.2.3
255
+ rubygems_version: 2.4.6
256
256
  signing_key:
257
257
  specification_version: 4
258
258
  summary: TDD with stripe