stripe 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class ChargeTest < Test::Unit::TestCase
5
+ should "charges should be listable" do
6
+ @mock.expects(:get).once.returns(test_response(test_charge_array))
7
+ c = Stripe::Charge.all
8
+ assert c.data.kind_of? Array
9
+ c.each do |charge|
10
+ assert charge.kind_of?(Stripe::Charge)
11
+ end
12
+ end
13
+
14
+ should "charges should be refundable" do
15
+ @mock.expects(:get).never
16
+ @mock.expects(:post).once.returns(test_response({:id => "ch_test_charge", :refunded => true}))
17
+ c = Stripe::Charge.new("test_charge")
18
+ c.refund
19
+ assert c.refunded
20
+ end
21
+
22
+ should "charges should not be deletable" do
23
+ assert_raises NoMethodError do
24
+ @mock.expects(:get).once.returns(test_response(test_charge))
25
+ c = Stripe::Charge.retrieve("test_charge")
26
+ c.delete
27
+ end
28
+ end
29
+
30
+ should "charges should be updateable" do
31
+ @mock.expects(:get).once.returns(test_response(test_charge))
32
+ @mock.expects(:post).once.returns(test_response(test_charge))
33
+ c = Stripe::Charge.new("test_charge")
34
+ c.refresh
35
+ c.mnemonic = "New charge description"
36
+ c.save
37
+ end
38
+
39
+ should "charges should have Card objects associated with their Card property" do
40
+ @mock.expects(:get).once.returns(test_response(test_charge))
41
+ c = Stripe::Charge.retrieve("test_charge")
42
+ assert c.card.kind_of?(Stripe::StripeObject) && c.card.object == 'card'
43
+ end
44
+
45
+ should "execute should return a new, fully executed charge when passed correct parameters" do
46
+ @mock.expects(:post).with do |url, api_key, params|
47
+ url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
48
+ 'currency' => ['usd'], 'amount' => ['100'],
49
+ 'card[exp_year]' => ['2012'],
50
+ 'card[number]' => ['4242424242424242'],
51
+ 'card[exp_month]' => ['11']
52
+ }
53
+ end.once.returns(test_response(test_charge))
54
+
55
+ c = Stripe::Charge.create({
56
+ :amount => 100,
57
+ :card => {
58
+ :number => "4242424242424242",
59
+ :exp_month => 11,
60
+ :exp_year => 2012,
61
+ },
62
+ :currency => "usd"
63
+ })
64
+ assert c.paid
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class CouponTest < Test::Unit::TestCase
5
+ should "create should return a new coupon" do
6
+ @mock.expects(:post).once.returns(test_response(test_coupon))
7
+ c = Stripe::Coupon.create
8
+ assert_equal "co_test_coupon", c.id
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class CustomerTest < Test::Unit::TestCase
5
+ should "customers should be listable" do
6
+ @mock.expects(:get).once.returns(test_response(test_customer_array))
7
+ c = Stripe::Customer.all.data
8
+ assert c.kind_of? Array
9
+ assert c[0].kind_of? Stripe::Customer
10
+ end
11
+
12
+ should "customers should be deletable" do
13
+ @mock.expects(:delete).once.returns(test_response(test_customer({:deleted => true})))
14
+ c = Stripe::Customer.new("test_customer")
15
+ c.delete
16
+ assert c.deleted
17
+ end
18
+
19
+ should "customers should be updateable" do
20
+ @mock.expects(:get).once.returns(test_response(test_customer({:mnemonic => "foo"})))
21
+ @mock.expects(:post).once.returns(test_response(test_customer({:mnemonic => "bar"})))
22
+ c = Stripe::Customer.new("test_customer").refresh
23
+ assert_equal c.mnemonic, "foo"
24
+ c.mnemonic = "bar"
25
+ c.save
26
+ assert_equal c.mnemonic, "bar"
27
+ end
28
+
29
+ should "create should return a new customer" do
30
+ @mock.expects(:post).once.returns(test_response(test_customer))
31
+ c = Stripe::Customer.create
32
+ assert_equal "c_test_customer", c.id
33
+ end
34
+
35
+ should "be able to update a customer's subscription" do
36
+ @mock.expects(:get).once.returns(test_response(test_customer))
37
+ c = Stripe::Customer.retrieve("test_customer")
38
+
39
+ @mock.expects(:post).once.with do |url, api_key, params|
40
+ url == "#{Stripe.api_base}/v1/customers/c_test_customer/subscription" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
41
+ end.returns(test_response(test_subscription('silver')))
42
+ s = c.update_subscription({:plan => 'silver'})
43
+
44
+ assert_equal 'subscription', s.object
45
+ assert_equal 'silver', s.plan.identifier
46
+ end
47
+
48
+ should "be able to cancel a customer's subscription" do
49
+ @mock.expects(:get).once.returns(test_response(test_customer))
50
+ c = Stripe::Customer.retrieve("test_customer")
51
+
52
+ # Not an accurate response, but whatever
53
+
54
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription?at_period_end=true", nil, nil).returns(test_response(test_subscription('silver')))
55
+ s = c.cancel_subscription({:at_period_end => 'true'})
56
+
57
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription", nil, nil).returns(test_response(test_subscription('silver')))
58
+ s = c.cancel_subscription
59
+ end
60
+
61
+ should "be able to delete a customer's discount" do
62
+ @mock.expects(:get).once.returns(test_response(test_customer))
63
+ c = Stripe::Customer.retrieve("test_customer")
64
+
65
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/discount", nil, nil).returns(test_response(test_delete_discount_response))
66
+ s = c.delete_discount
67
+ assert_equal nil, c.discount
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class InvoiceTest < Test::Unit::TestCase
5
+ should "retrieve should retrieve invoices" do
6
+ @mock.expects(:get).once.returns(test_response(test_invoice))
7
+ i = Stripe::Invoice.retrieve('in_test_invoice')
8
+ assert_equal 'in_test_invoice', i.id
9
+ end
10
+
11
+ should "pay should pay an invoice" do
12
+ @mock.expects(:get).once.returns(test_response(test_invoice))
13
+ i = Stripe::Invoice.retrieve('in_test_invoice')
14
+
15
+ @mock.expects(:post).once.with('https://api.stripe.com/v1/invoices/in_test_invoice/pay', nil, '').returns(test_response(test_paid_invoice))
16
+ i.pay
17
+ assert_equal i.next_payment_attempt, nil
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class ListObjectTest < Test::Unit::TestCase
5
+ should "be able to retrieve full lists given a listobject" do
6
+ @mock.expects(:get).twice.returns(test_response(test_charge_array))
7
+ c = Stripe::Charge.all
8
+ assert c.kind_of?(Stripe::ListObject)
9
+ assert_equal('/v1/charges', c.url)
10
+ all = c.all
11
+ assert all.kind_of?(Stripe::ListObject)
12
+ assert_equal('/v1/charges', all.url)
13
+ assert all.data.kind_of?(Array)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,114 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class MetadataTest < Test::Unit::TestCase
5
+ setup do
6
+ @metadata_supported = {
7
+ :charge => {
8
+ :new => Stripe::Charge.method(:new),
9
+ :test => method(:test_charge),
10
+ :url => "/v1/charges/#{test_charge()[:id]}"
11
+ },
12
+ :customer => {
13
+ :new => Stripe::Customer.method(:new),
14
+ :test => method(:test_customer),
15
+ :url => "/v1/customers/#{test_customer()[:id]}"
16
+ },
17
+ :recipient => {
18
+ :new => Stripe::Recipient.method(:new),
19
+ :test => method(:test_recipient),
20
+ :url => "/v1/recipients/#{test_recipient()[:id]}"
21
+ },
22
+ :transfer => {
23
+ :new => Stripe::Transfer.method(:new),
24
+ :test => method(:test_transfer),
25
+ :url => "/v1/transfers/#{test_transfer()[:id]}"
26
+ }
27
+ }
28
+
29
+ @base_url = 'https://api.stripe.com'
30
+ end
31
+
32
+ should "not touch metadata" do
33
+ update_actions = lambda {|obj| obj.description = 'test'}
34
+ check_metadata({:metadata => {'initial' => 'true'}},
35
+ 'description=test',
36
+ update_actions)
37
+ end
38
+
39
+
40
+ should "update metadata as a whole" do
41
+ update_actions = lambda {|obj| obj.metadata = {'uuid' => '6735'}}
42
+ check_metadata({:metadata => {}},
43
+ 'metadata[uuid]=6735',
44
+ update_actions)
45
+
46
+ if is_greater_than_ruby_1_9?
47
+ check_metadata({:metadata => {:initial => 'true'}},
48
+ 'metadata[uuid]=6735&metadata[initial]=',
49
+ update_actions)
50
+ end
51
+ end
52
+
53
+ should "update metadata keys individually" do
54
+ update_actions = lambda {|obj| obj.metadata['txn_id'] = '134a13'}
55
+ check_metadata({:metadata => {'initial' => 'true'}},
56
+ 'metadata[txn_id]=134a13',
57
+ update_actions)
58
+ end
59
+
60
+ should "clear metadata as a whole" do
61
+ update_actions = lambda {|obj| obj.metadata = nil}
62
+ check_metadata({:metadata => {'initial' => 'true'}},
63
+ 'metadata=',
64
+ update_actions)
65
+ end
66
+
67
+ should "clear metadata keys individually" do
68
+ update_actions = lambda {|obj| obj.metadata['initial'] = nil}
69
+ check_metadata({:metadata => {'initial' => 'true'}},
70
+ 'metadata[initial]=',
71
+ update_actions)
72
+ end
73
+
74
+ should "handle combinations of whole and partial metadata updates" do
75
+ if is_greater_than_ruby_1_9?
76
+ update_actions = lambda do |obj|
77
+ obj.metadata = {'type' => 'summer'}
78
+ obj.metadata['uuid'] = '6735'
79
+ end
80
+ params = {:metadata => {'type' => 'summer', 'uuid' => '6735'}}
81
+ curl_args = Stripe.uri_encode(params)
82
+ check_metadata({:metadata => {'type' => 'christmas'}},
83
+ curl_args,
84
+ update_actions)
85
+ end
86
+ end
87
+
88
+ def check_metadata (initial_params, curl_args, metadata_update)
89
+ @metadata_supported.each do |name, methods|
90
+ neu = methods[:new]
91
+ test = methods[:test]
92
+ url = @base_url + methods[:url]
93
+
94
+ initial_test_obj = test.call(initial_params)
95
+ @mock.expects(:get).once.returns(test_response(initial_test_obj))
96
+
97
+ final_test_obj = test.call()
98
+ @mock.expects(:post).once.
99
+ returns(test_response(final_test_obj)).
100
+ with(url, nil, curl_args)
101
+
102
+ obj = neu.call("test")
103
+ obj.refresh()
104
+ metadata_update.call(obj)
105
+ obj.save
106
+ end
107
+ end
108
+
109
+ def is_greater_than_ruby_1_9?
110
+ version = RUBY_VERSION.dup # clone preserves frozen state
111
+ Gem::Version.new(version) >= Gem::Version.new('1.9')
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class UtilTest < Test::Unit::TestCase
5
+ should "symbolize_names should convert names to symbols" do
6
+ start = {
7
+ 'foo' => 'bar',
8
+ 'array' => [{ 'foo' => 'bar' }],
9
+ 'nested' => {
10
+ 1 => 2,
11
+ :symbol => 9,
12
+ 'string' => nil
13
+ }
14
+ }
15
+ finish = {
16
+ :foo => 'bar',
17
+ :array => [{ :foo => 'bar' }],
18
+ :nested => {
19
+ 1 => 2,
20
+ :symbol => 9,
21
+ :string => nil
22
+ }
23
+ }
24
+
25
+ symbolized = Stripe::Util.symbolize_names(start)
26
+ assert_equal(finish, symbolized)
27
+ end
28
+ end
29
+ end
@@ -1,8 +1,8 @@
1
- require 'stringio'
2
- require 'test/unit'
3
1
  require 'stripe'
2
+ require 'test/unit'
4
3
  require 'mocha/setup'
5
- include Mocha
4
+ require 'stringio'
5
+ require 'shoulda'
6
6
 
7
7
  #monkeypatch request methods
8
8
  module Stripe
@@ -80,7 +80,8 @@ def test_customer(params={})
80
80
  :id => "c_test_customer",
81
81
  :default_card => "cc_test_card",
82
82
  :created => 1304114758,
83
- :cards => test_card_array('c_test_customer')
83
+ :cards => test_card_array('c_test_customer'),
84
+ :metadata => {}
84
85
  }.merge(params)
85
86
  end
86
87
 
@@ -111,7 +112,8 @@ def test_charge(params={})
111
112
  :livemode => false,
112
113
  :currency => "usd",
113
114
  :object => "charge",
114
- :created => 1304114826
115
+ :created => 1304114826,
116
+ :metadata => {}
115
117
  }.merge(params)
116
118
  end
117
119
 
@@ -249,7 +251,8 @@ def test_recipient(params={})
249
251
  :object => "bank_account"
250
252
  },
251
253
  :created => 1304114758,
252
- :verified => true
254
+ :verified => true,
255
+ :metadata => {}
253
256
  }.merge(params)
254
257
  end
255
258
 
@@ -278,7 +281,8 @@ def test_transfer(params={})
278
281
  :livemode => false,
279
282
  :currency => "usd",
280
283
  :object => "transfer",
281
- :date => 1304114826
284
+ :date => 1304114826,
285
+ :metadata => {}
282
286
  }.merge(params)
283
287
  end
284
288
 
@@ -334,3 +338,19 @@ def test_delete_discount_response
334
338
  :id => "di_test_coupon"
335
339
  }
336
340
  end
341
+
342
+ class Test::Unit::TestCase
343
+ include Mocha
344
+
345
+ setup do
346
+ @mock = mock
347
+ Stripe.mock_rest_client = @mock
348
+ Stripe.api_key="foo"
349
+ end
350
+
351
+ teardown do
352
+ Stripe.mock_rest_client = nil
353
+ Stripe.api_key=nil
354
+ end
355
+ end
356
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7
4
+ version: 1.8.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-20 00:00:00.000000000 Z
13
+ date: 2013-10-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -171,9 +171,16 @@ files:
171
171
  - lib/stripe/util.rb
172
172
  - lib/stripe/version.rb
173
173
  - stripe.gemspec
174
+ - test/stripe/account_test.rb
175
+ - test/stripe/api_resource_test.rb
176
+ - test/stripe/charge_test.rb
177
+ - test/stripe/coupon_test.rb
178
+ - test/stripe/customer_test.rb
179
+ - test/stripe/invoice_test.rb
180
+ - test/stripe/list_object_test.rb
181
+ - test/stripe/metadata_test.rb
182
+ - test/stripe/util_test.rb
174
183
  - test/test_helper.rb
175
- - test/test_stripe.rb
176
- - test/test_stripe_with_active_support.rb
177
184
  homepage: https://stripe.com/api
178
185
  licenses: []
179
186
  post_install_message:
@@ -199,6 +206,13 @@ signing_key:
199
206
  specification_version: 3
200
207
  summary: Ruby bindings for the Stripe API
201
208
  test_files:
209
+ - test/stripe/account_test.rb
210
+ - test/stripe/api_resource_test.rb
211
+ - test/stripe/charge_test.rb
212
+ - test/stripe/coupon_test.rb
213
+ - test/stripe/customer_test.rb
214
+ - test/stripe/invoice_test.rb
215
+ - test/stripe/list_object_test.rb
216
+ - test/stripe/metadata_test.rb
217
+ - test/stripe/util_test.rb
202
218
  - test/test_helper.rb
203
- - test/test_stripe.rb
204
- - test/test_stripe_with_active_support.rb