rainforest 1.0.1 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4ab37f7ce8b3ac359e5808731670e7ff2a52cbc
4
- data.tar.gz: 3dd6db625d4cfe6630d1bbaf4fab5721229b8ecc
3
+ metadata.gz: d6cbbfc3410b0696d478289fce462b081c2dc5f6
4
+ data.tar.gz: 3f665a7a8ffb46ec8fc23d6dde9c296ca55cd474
5
5
  SHA512:
6
- metadata.gz: 0a4dcabfbfebd8118c8fb7516bfbc7dcfa1dd378e2c22389de90b25fc088d6e8060acb926322b6f55a28767010d98e3ad255ca9eae87a1f2eba4a319acb9a0b5
7
- data.tar.gz: d45e3fd64c0133b0d0aebba5e8e6ea1e47ecc354e2ccacc24ccd9e81b6e41491ccc6f8001477b3d6b744b694512d63ae96fa80157d8d2d0c89ce3237ac2dbfa0
6
+ metadata.gz: 442f253755bb2bcabeb923ce94e6cf1f6018f88317eeeeb5cea7d9ea75d461c85390346c44b94ff24813a79ddc4caeee7a17a1eb343fc1b858b9c7de29319fb8
7
+ data.tar.gz: e4a9787bdd2fa079adce0bc6a7ad26c83a3c62d09f91bfb3becefece959f3fdfafbc1ec94dcc096b82bd575673bfdfe9f7192aa4d0eb678a46be2fdf7af28bfe
data/README.md CHANGED
@@ -26,6 +26,12 @@ Development
26
26
  Test cases can be run with: `bundle exec rake test`
27
27
 
28
28
 
29
+ Docs
30
+ ----
31
+
32
+ You can find the Rainforest docs here: https://app.rainforestqa.com/docs
33
+
34
+
29
35
  Examples
30
36
  --------
31
37
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.3
Binary file
data/rainforest.gemspec CHANGED
@@ -9,7 +9,7 @@ spec = Gem::Specification.new do |s|
9
9
  s.description = 'Rainforest allows you to create tests for your website in plain English, then run them across all major browsers with a single click. See https://www.rainforestqa.com/ for details.'
10
10
  s.authors = ['Jon Calhon']
11
11
  s.email = ['joncalhoun@gmail.com']
12
- s.homepage = 'https://app.rainforestqa.com/docs/ruby'
12
+ s.homepage = 'https://github.com/joncalhoun/rainforest-ruby'
13
13
 
14
14
  s.add_dependency('rest-client', '~> 1.4')
15
15
  s.add_dependency('multi_json', '>= 1.0.4', '< 2')
data/test/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../../test_helper', __FILE__)
3
+
4
+ module Rainforest
5
+ class ApiResourceTest < ::Test::Unit::TestCase
6
+ should "creating a new APIResource should not fetch over the network" do
7
+ @mock.expects(:get).never
8
+ c = Rainforest::Test.new("someid")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Rainforest
4
+ class ListObjectTest < ::Test::Unit::TestCase
5
+ should_eventually "implement some tests"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Rainforest
4
+ class MetadataTest < ::Test::Unit::TestCase
5
+ should_eventually "implement some tests"
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Rainforest
4
+ # Dear god this name is odd.. :( - jon
5
+ class TestTest < ::Test::Unit::TestCase
6
+ should_eventually "implement some tests"
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Rainforest
4
- class UtilTest < Test::Unit::TestCase
4
+ class UtilTest < ::Test::Unit::TestCase
5
5
  should "symbolize_names should convert names to symbols" do
6
6
  start = {
7
7
  'foo' => 'bar',
data/test/test_helper.rb CHANGED
@@ -34,308 +34,107 @@ def test_response(body, code=200)
34
34
  m
35
35
  end
36
36
 
37
- def test_balance(params={})
38
- {
39
- :pending => [
40
- {:amount => 12345, :currency => "usd"}
41
- ],
42
- :available => [
43
- {:amount => 6789, :currency => "usd"}
37
+ def test_test(params={})
38
+ {
39
+ id: 2181,
40
+ created_at: "2013-11-05T04:57:55Z",
41
+ test_id: 2181,
42
+ site_id: 860,
43
+ title: "shit works",
44
+ result: "no_result",
45
+ start_uri: "/ghost/signin",
46
+ run_mode: "default",
47
+ deleted: false,
48
+ deletable: true,
49
+ editable: true,
50
+ browsers: [
51
+ {
52
+ name: "chrome",
53
+ state: "enabled"
54
+ },{
55
+ name: "firefox",
56
+ state: "enabled"
57
+ },{
58
+ name: "ie8",
59
+ state: "enabled"
60
+ },{
61
+ name: "ie9",
62
+ state: "enabled"
63
+ },{
64
+ name: "safari",
65
+ state: "enabled"
66
+ }
44
67
  ],
45
- :livemode => false,
46
- :object => "balance"
47
- }.merge(params)
48
- end
49
-
50
- def test_balance_transaction(params={})
51
- {
52
- :amount => 100,
53
- :net => 41,
54
- :currency => "usd",
55
- :type => "charge",
56
- :created => 1371945005,
57
- :available_on => 1372549805,
58
- :status => "pending",
59
- :description => "A test balance transaction",
60
- :fee => 59,
61
- :object => "balance_transaction"
62
- }.merge(params)
63
- end
64
-
65
- def test_balance_transaction_array
66
- {
67
- :data => [test_balance_transaction, test_balance_transaction, test_balance_transaction],
68
- :object => "list",
69
- :url => "/v1/balance/history"
70
- }
71
- end
72
-
73
- def test_customer(params={})
74
- {
75
- :subscription_history => [],
76
- :bills => [],
77
- :charges => [],
78
- :livemode => false,
79
- :object => "customer",
80
- :id => "c_test_customer",
81
- :default_card => "cc_test_card",
82
- :created => 1304114758,
83
- :cards => test_card_array('c_test_customer'),
84
- :metadata => {}
85
- }.merge(params)
86
- end
87
-
88
- def test_customer_array
89
- {
90
- :data => [test_customer, test_customer, test_customer],
91
- :object => 'list',
92
- :url => '/v1/customers'
93
- }
94
- end
95
-
96
- def test_charge(params={})
97
- {
98
- :refunded => false,
99
- :paid => true,
100
- :amount => 100,
101
- :card => {
102
- :type => "Visa",
103
- :last4 => "4242",
104
- :exp_month => 11,
105
- :country => "US",
106
- :exp_year => 2012,
107
- :id => "cc_test_card",
108
- :object => "card"
109
- },
110
- :id => "ch_test_charge",
111
- :reason => "execute_charge",
112
- :livemode => false,
113
- :currency => "usd",
114
- :object => "charge",
115
- :created => 1304114826,
116
- :metadata => {}
117
- }.merge(params)
118
- end
119
-
120
- def test_charge_array
121
- {
122
- :data => [test_charge, test_charge, test_charge],
123
- :object => 'list',
124
- :url => '/v1/charges'
125
- }
126
- end
127
-
128
- def test_card_array(customer_id)
129
- {
130
- :data => [test_card, test_card, test_card],
131
- :object => 'list',
132
- :url => '/v1/customers/' + customer_id + '/cards'
133
- }
134
- end
135
-
136
- def test_card(params={})
137
- {
138
- :type => "Visa",
139
- :last4 => "4242",
140
- :exp_month => 11,
141
- :country => "US",
142
- :exp_year => 2012,
143
- :id => "cc_test_card",
144
- :customer => 'c_test_customer',
145
- :object => "card"
146
- }.merge(params)
147
- end
148
-
149
- def test_coupon(params={})
150
- {
151
- :duration => 'repeating',
152
- :duration_in_months => 3,
153
- :percent_off => 25,
154
- :id => "co_test_coupon",
155
- :object => "coupon"
156
- }.merge(params)
157
- end
158
-
159
- #FIXME nested overrides would be better than hardcoding plan_id
160
- def test_subscription(plan_id="gold")
161
- {
162
- :current_period_end => 1308681468,
163
- :status => "trialing",
164
- :plan => {
165
- :interval => "month",
166
- :amount => 7500,
167
- :trial_period_days => 30,
168
- :object => "plan",
169
- :identifier => plan_id
170
- },
171
- :current_period_start => 1308595038,
172
- :start => 1308595038,
173
- :object => "subscription",
174
- :trial_start => 1308595038,
175
- :trial_end => 1308681468,
176
- :customer => "c_test_customer"
177
- }
178
- end
179
-
180
- def test_invoice
181
- {
182
- :id => 'in_test_invoice',
183
- :object => 'invoice',
184
- :livemode => false,
185
- :amount_due => 1000,
186
- :attempt_count => 0,
187
- :attempted => false,
188
- :closed => false,
189
- :currency => 'usd',
190
- :customer => 'c_test_customer',
191
- :date => 1349738950,
192
- :lines => {
193
- "invoiceitems" => [
194
- {
195
- :id => 'ii_test_invoice_item',
196
- :object => '',
197
- :livemode => false,
198
- :amount => 1000,
199
- :currency => 'usd',
200
- :customer => 'c_test_customer',
201
- :date => 1349738950,
202
- :description => "A Test Invoice Item",
203
- :invoice => 'in_test_invoice'
204
- },
205
- ],
206
- },
207
- :paid => false,
208
- :period_end => 1349738950,
209
- :period_start => 1349738950,
210
- :starting_balance => 0,
211
- :subtotal => 1000,
212
- :total => 1000,
213
- :charge => nil,
214
- :discount => nil,
215
- :ending_balance => nil,
216
- :next_payemnt_attempt => 1349825350,
217
- }
218
- end
219
-
220
- def test_paid_invoice
221
- test_invoice.merge({
222
- :attempt_count => 1,
223
- :attempted => true,
224
- :closed => true,
225
- :paid => true,
226
- :charge => 'ch_test_charge',
227
- :ending_balance => 0,
228
- :next_payment_attempt => nil,
229
- })
230
- end
231
-
232
- def test_invoice_customer_array
233
- {
234
- :data => [test_invoice],
235
- :object => 'list',
236
- :url => '/v1/invoices?customer=test_customer'
237
- }
238
- end
239
-
240
- def test_recipient(params={})
241
- {
242
- :name => "Rainforest User",
243
- :type => "individual",
244
- :livemode => false,
245
- :object => "recipient",
246
- :id => "rp_test_recipient",
247
- :active_account => {
248
- :last4 => "6789",
249
- :bank_name => "STRIPE TEST BANK",
250
- :country => "US",
251
- :object => "bank_account"
252
- },
253
- :created => 1304114758,
254
- :verified => true,
255
- :metadata => {}
256
- }.merge(params)
257
- end
258
-
259
- def test_recipient_array
260
- {
261
- :data => [test_recipient, test_recipient, test_recipient],
262
- :object => 'list',
263
- :url => '/v1/recipients'
264
- }
265
- end
266
-
267
- def test_transfer(params={})
268
- {
269
- :status => 'pending',
270
- :amount => 100,
271
- :account => {
272
- :object => 'bank_account',
273
- :country => 'US',
274
- :bank_name => 'STRIPE TEST BANK',
275
- :last4 => '6789'
276
- },
277
- :recipient => 'test_recipient',
278
- :fee => 0,
279
- :fee_details => [],
280
- :id => "tr_test_transfer",
281
- :livemode => false,
282
- :currency => "usd",
283
- :object => "transfer",
284
- :date => 1304114826,
285
- :metadata => {}
286
- }.merge(params)
287
- end
288
-
289
- def test_transfer_array
290
- {
291
- :data => [test_transfer, test_transfer, test_transfer],
292
- :object => 'list',
293
- :url => '/v1/transfers'
294
- }
295
- end
296
-
297
- def test_invalid_api_key_error
298
- {
299
- "error" => {
300
- "type" => "invalid_request_error",
301
- "message" => "Invalid API Key provided: invalid"
302
- }
303
- }
304
- end
305
-
306
- def test_invalid_exp_year_error
307
- {
308
- "error" => {
309
- "code" => "invalid_expiry_year",
310
- "param" => "exp_year",
311
- "type" => "card_error",
312
- "message" => "Your card's expiration year is invalid"
68
+ tags: [],
69
+ dry_run_url: "https://fierce-thicket-5713.herokuapp.com/turker/dry_run/L4nI_HqGn6ZT4fvecPmDng?turkSubmitTo=%2Fthanks",
70
+ last_run: {
71
+ id: 4244,
72
+ created_at: "2013-11-13T14:38:01Z",
73
+ state: "in_progress"
313
74
  }
314
75
  }
315
76
  end
316
77
 
317
- def test_missing_id_error
318
- {
319
- :error => {
320
- :param => "id",
321
- :type => "invalid_request_error",
322
- :message => "Missing id"
323
- }
324
- }
325
- end
326
-
327
- def test_api_error
328
- {
329
- :error => {
330
- :type => "api_error"
331
- }
78
+ def test_run(params={})
79
+ {
80
+ id: 4244,
81
+ created_at: "2013-11-13T14:38:01Z",
82
+ environment_id: 1144,
83
+ test_count: 1,
84
+ state_log: [
85
+ {
86
+ id: 11741379,
87
+ created_at: "2013-11-13T14:38:04Z",
88
+ event: "validate_run!",
89
+ from: "queued",
90
+ state_column: "state",
91
+ stateful_id: 4244,
92
+ stateful_type: "Run",
93
+ to: "validating",
94
+ transitioned_at: "2013-11-13T14:38:04Z",
95
+ updated_at: "2013-11-13T14:38:04Z"
96
+ },{
97
+ id: 11741378,
98
+ created_at: "2013-11-13T14:38:04Z",
99
+ event: "validated!",
100
+ from: "validating",
101
+ state_column: "state",
102
+ stateful_id: 4244,
103
+ stateful_type: "Run",
104
+ to: "in_progress",
105
+ transitioned_at: "2013-11-13T14:38:04Z",
106
+ updated_at: "2013-11-13T14:38:04Z"
107
+ }
108
+ ],
109
+ state: "in_progress",
110
+ result: "no_result",
111
+ expected_wait_time: 5400.0,
112
+ browsers: [
113
+ {
114
+ name: "chrome",
115
+ state: "enabled"
116
+ },{
117
+ name: "firefox",
118
+ state: "enabled"
119
+ },{
120
+ name: "ie8",
121
+ state: "enabled"
122
+ },{
123
+ name: "ie9",
124
+ state: "enabled"
125
+ },{
126
+ name: "safari",
127
+ state: "enabled"
128
+ }
129
+ ],
130
+ requested_tests: [2181]
332
131
  }
333
132
  end
334
133
 
335
- def test_delete_discount_response
134
+ def test_run_array
336
135
  {
337
- :deleted => true,
338
- :id => "di_test_coupon"
136
+ data: [test_run, test_run, test_run],
137
+ url: '/1/runs'
339
138
  }
340
139
  end
341
140
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainforest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Calhon
@@ -126,6 +126,7 @@ files:
126
126
  - lib/.DS_Store
127
127
  - lib/data/ca-certificates.crt
128
128
  - lib/rainforest.rb
129
+ - lib/rainforest/.DS_Store
129
130
  - lib/rainforest/api_operations/create.rb
130
131
  - lib/rainforest/api_operations/delete.rb
131
132
  - lib/rainforest/api_operations/list.rb
@@ -145,17 +146,15 @@ files:
145
146
  - lib/rainforest/util.rb
146
147
  - lib/rainforest/version.rb
147
148
  - rainforest.gemspec
148
- - test/stripe/account_test.rb
149
- - test/stripe/api_resource_test.rb
150
- - test/stripe/charge_test.rb
151
- - test/stripe/coupon_test.rb
152
- - test/stripe/customer_test.rb
153
- - test/stripe/invoice_test.rb
154
- - test/stripe/list_object_test.rb
155
- - test/stripe/metadata_test.rb
156
- - test/stripe/util_test.rb
149
+ - test/.DS_Store
150
+ - test/rainforest/.DS_Store
151
+ - test/rainforest/api_resource_test.rb
152
+ - test/rainforest/list_object_test.rb
153
+ - test/rainforest/metadata_test.rb
154
+ - test/rainforest/test_test.rb
155
+ - test/rainforest/util_test.rb
157
156
  - test/test_helper.rb
158
- homepage: https://app.rainforestqa.com/docs/ruby
157
+ homepage: https://github.com/joncalhoun/rainforest-ruby
159
158
  licenses: []
160
159
  metadata: {}
161
160
  post_install_message:
@@ -179,13 +178,10 @@ signing_key:
179
178
  specification_version: 4
180
179
  summary: Ruby bindings for the Rainforest API
181
180
  test_files:
182
- - test/stripe/account_test.rb
183
- - test/stripe/api_resource_test.rb
184
- - test/stripe/charge_test.rb
185
- - test/stripe/coupon_test.rb
186
- - test/stripe/customer_test.rb
187
- - test/stripe/invoice_test.rb
188
- - test/stripe/list_object_test.rb
189
- - test/stripe/metadata_test.rb
190
- - test/stripe/util_test.rb
181
+ - test/rainforest/.DS_Store
182
+ - test/rainforest/api_resource_test.rb
183
+ - test/rainforest/list_object_test.rb
184
+ - test/rainforest/metadata_test.rb
185
+ - test/rainforest/test_test.rb
186
+ - test/rainforest/util_test.rb
191
187
  - test/test_helper.rb
@@ -1,14 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Rainforest
4
- class AccountTest < Test::Unit::TestCase
5
- should "account should be retrievable" do
6
- resp = {:email => "test+bindings@rainforest.com", :charge_enabled => false, :details_submitted => false}
7
- @mock.expects(:get).once.returns(test_response(resp))
8
- a = Rainforest::Account.retrieve
9
- assert_equal "test+bindings@rainforest.com", a.email
10
- assert !a.charge_enabled
11
- assert !a.details_submitted
12
- end
13
- end
14
- end
@@ -1,345 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path('../../test_helper', __FILE__)
3
-
4
- module Rainforest
5
- class ApiResourceTest < Test::Unit::TestCase
6
- should "creating a new APIResource should not fetch over the network" do
7
- @mock.expects(:get).never
8
- c = Rainforest::Customer.new("someid")
9
- end
10
-
11
- should "creating a new APIResource from a hash should not fetch over the network" do
12
- @mock.expects(:get).never
13
- c = Rainforest::Customer.construct_from({
14
- :id => "somecustomer",
15
- :card => {:id => "somecard", :object => "card"},
16
- :object => "customer"
17
- })
18
- end
19
-
20
- should "setting an attribute should not cause a network request" do
21
- @mock.expects(:get).never
22
- @mock.expects(:post).never
23
- c = Rainforest::Customer.new("test_customer");
24
- c.card = {:id => "somecard", :object => "card"}
25
- end
26
-
27
- should "accessing id should not issue a fetch" do
28
- @mock.expects(:get).never
29
- c = Rainforest::Customer.new("test_customer");
30
- c.id
31
- end
32
-
33
- should "not specifying api credentials should raise an exception" do
34
- Rainforest.api_key = nil
35
- assert_raises Rainforest::AuthenticationError do
36
- Rainforest::Customer.new("test_customer").refresh
37
- end
38
- end
39
-
40
- should "specifying api credentials containing whitespace should raise an exception" do
41
- Rainforest.api_key = "key "
42
- assert_raises Rainforest::AuthenticationError do
43
- Rainforest::Customer.new("test_customer").refresh
44
- end
45
- end
46
-
47
- should "specifying invalid api credentials should raise an exception" do
48
- Rainforest.api_key = "invalid"
49
- response = test_response(test_invalid_api_key_error, 401)
50
- assert_raises Rainforest::AuthenticationError do
51
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
52
- Rainforest::Customer.retrieve("failing_customer")
53
- end
54
- end
55
-
56
- should "AuthenticationErrors should have an http status, http body, and JSON body" do
57
- Rainforest.api_key = "invalid"
58
- response = test_response(test_invalid_api_key_error, 401)
59
- begin
60
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
61
- Rainforest::Customer.retrieve("failing_customer")
62
- rescue Rainforest::AuthenticationError => e
63
- assert_equal(401, e.http_status)
64
- assert_equal(true, !!e.http_body)
65
- assert_equal(true, !!e.json_body[:error][:message])
66
- assert_equal(test_invalid_api_key_error['error']['message'], e.json_body[:error][:message])
67
- end
68
- end
69
-
70
- context "when specifying per-object credentials" do
71
- context "with no global API key set" do
72
- should "use the per-object credential when creating" do
73
- Rainforest.expects(:execute_request).with do |opts|
74
- opts[:headers][:authorization] == 'Bearer sk_test_local'
75
- end.returns(test_response(test_charge))
76
-
77
- Rainforest::Charge.create({:card => {:number => '4242424242424242'}},
78
- 'sk_test_local')
79
- end
80
- end
81
-
82
- context "with a global API key set" do
83
- setup do
84
- Rainforest.api_key = "global"
85
- end
86
-
87
- teardown do
88
- Rainforest.api_key = nil
89
- end
90
-
91
- should "use the per-object credential when creating" do
92
- Rainforest.expects(:execute_request).with do |opts|
93
- opts[:headers][:authorization] == 'Bearer local'
94
- end.returns(test_response(test_charge))
95
-
96
- Rainforest::Charge.create({:card => {:number => '4242424242424242'}},
97
- 'local')
98
- end
99
-
100
- should "use the per-object credential when retrieving and making other calls" do
101
- Rainforest.expects(:execute_request).with do |opts|
102
- opts[:url] == "#{Rainforest.api_base}/v1/charges/ch_test_charge" &&
103
- opts[:headers][:authorization] == 'Bearer local'
104
- end.returns(test_response(test_charge))
105
- Rainforest.expects(:execute_request).with do |opts|
106
- opts[:url] == "#{Rainforest.api_base}/v1/charges/ch_test_charge/refund" &&
107
- opts[:headers][:authorization] == 'Bearer local'
108
- end.returns(test_response(test_charge))
109
-
110
- ch = Rainforest::Charge.retrieve('ch_test_charge', 'local')
111
- ch.refund
112
- end
113
- end
114
- end
115
-
116
- context "with valid credentials" do
117
- should "urlencode values in GET params" do
118
- response = test_response(test_charge_array)
119
- @mock.expects(:get).with("#{Rainforest.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
120
- charges = Rainforest::Charge.all(:customer => 'test customer').data
121
- assert charges.kind_of? Array
122
- end
123
-
124
- should "construct URL properly with base query parameters" do
125
- response = test_response(test_invoice_customer_array)
126
- @mock.expects(:get).with("#{Rainforest.api_base}/v1/invoices?customer=test_customer", nil, nil).returns(response)
127
- invoices = Rainforest::Invoice.all(:customer => 'test_customer')
128
-
129
- @mock.expects(:get).with("#{Rainforest.api_base}/v1/invoices?customer=test_customer&paid=true", nil, nil).returns(response)
130
- invoices.all(:paid => true)
131
- end
132
-
133
- should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
134
- response = test_response(test_missing_id_error, 400)
135
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
136
- begin
137
- Rainforest::Customer.retrieve("foo")
138
- rescue Rainforest::InvalidRequestError => e
139
- assert_equal(400, e.http_status)
140
- assert_equal(true, !!e.http_body)
141
- assert_equal(true, e.json_body.kind_of?(Hash))
142
- end
143
- end
144
-
145
- should "a 401 should give an AuthenticationError with http status, body, and JSON body" do
146
- response = test_response(test_missing_id_error, 401)
147
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
148
- begin
149
- Rainforest::Customer.retrieve("foo")
150
- rescue Rainforest::AuthenticationError => e
151
- assert_equal(401, e.http_status)
152
- assert_equal(true, !!e.http_body)
153
- assert_equal(true, e.json_body.kind_of?(Hash))
154
- end
155
- end
156
-
157
- should "a 402 should give a CardError with http status, body, and JSON body" do
158
- response = test_response(test_missing_id_error, 402)
159
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
160
- begin
161
- Rainforest::Customer.retrieve("foo")
162
- rescue Rainforest::CardError => e
163
- assert_equal(402, e.http_status)
164
- assert_equal(true, !!e.http_body)
165
- assert_equal(true, e.json_body.kind_of?(Hash))
166
- end
167
- end
168
-
169
- should "a 404 should give an InvalidRequestError with http status, body, and JSON body" do
170
- response = test_response(test_missing_id_error, 404)
171
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
172
- begin
173
- Rainforest::Customer.retrieve("foo")
174
- rescue Rainforest::InvalidRequestError => e
175
- assert_equal(404, e.http_status)
176
- assert_equal(true, !!e.http_body)
177
- assert_equal(true, e.json_body.kind_of?(Hash))
178
- end
179
- end
180
-
181
- should "setting a nil value for a param should exclude that param from the request" do
182
- @mock.expects(:get).with do |url, api_key, params|
183
- uri = URI(url)
184
- query = CGI.parse(uri.query)
185
- (url =~ %r{^#{Rainforest.api_base}/v1/charges?} &&
186
- query.keys.sort == ['offset', 'sad'])
187
- end.returns(test_response({ :count => 1, :data => [test_charge] }))
188
- c = Rainforest::Charge.all(:count => nil, :offset => 5, :sad => false)
189
-
190
- @mock.expects(:post).with do |url, api_key, params|
191
- url == "#{Rainforest.api_base}/v1/charges" &&
192
- api_key.nil? &&
193
- CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] }
194
- end.returns(test_response({ :count => 1, :data => [test_charge] }))
195
- c = Rainforest::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
196
- end
197
-
198
- should "requesting with a unicode ID should result in a request" do
199
- response = test_response(test_missing_id_error, 404)
200
- @mock.expects(:get).once.with("#{Rainforest.api_base}/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
201
- c = Rainforest::Customer.new("☃")
202
- assert_raises(Rainforest::InvalidRequestError) { c.refresh }
203
- end
204
-
205
- should "requesting with no ID should result in an InvalidRequestError with no request" do
206
- c = Rainforest::Customer.new
207
- assert_raises(Rainforest::InvalidRequestError) { c.refresh }
208
- end
209
-
210
- should "making a GET request with parameters should have a query string and no body" do
211
- params = { :limit => 1 }
212
- @mock.expects(:get).once.with("#{Rainforest.api_base}/v1/charges?limit=1", nil, nil).returns(test_response([test_charge]))
213
- c = Rainforest::Charge.all(params)
214
- end
215
-
216
- should "making a POST request with parameters should have a body and no query string" do
217
- params = { :amount => 100, :currency => 'usd', :card => 'sc_token' }
218
- @mock.expects(:post).once.with do |url, get, post|
219
- get.nil? && CGI.parse(post) == {'amount' => ['100'], 'currency' => ['usd'], 'card' => ['sc_token']}
220
- end.returns(test_response(test_charge))
221
- c = Rainforest::Charge.create(params)
222
- end
223
-
224
- should "loading an object should issue a GET request" do
225
- @mock.expects(:get).once.returns(test_response(test_customer))
226
- c = Rainforest::Customer.new("test_customer")
227
- c.refresh
228
- end
229
-
230
- should "using array accessors should be the same as the method interface" do
231
- @mock.expects(:get).once.returns(test_response(test_customer))
232
- c = Rainforest::Customer.new("test_customer")
233
- c.refresh
234
- assert_equal c.created, c[:created]
235
- assert_equal c.created, c['created']
236
- c['created'] = 12345
237
- assert_equal c.created, 12345
238
- end
239
-
240
- should "accessing a property other than id or parent on an unfetched object should fetch it" do
241
- @mock.expects(:get).once.returns(test_response(test_customer))
242
- c = Rainforest::Customer.new("test_customer")
243
- c.charges
244
- end
245
-
246
- should "updating an object should issue a POST request with only the changed properties" do
247
- @mock.expects(:post).with do |url, api_key, params|
248
- url == "#{Rainforest.api_base}/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'description' => ['another_mn']}
249
- end.once.returns(test_response(test_customer))
250
- c = Rainforest::Customer.construct_from(test_customer)
251
- c.description = "another_mn"
252
- c.save
253
- end
254
-
255
- should "updating should merge in returned properties" do
256
- @mock.expects(:post).once.returns(test_response(test_customer))
257
- c = Rainforest::Customer.new("c_test_customer")
258
- c.description = "another_mn"
259
- c.save
260
- assert_equal false, c.livemode
261
- end
262
-
263
- should "deleting should send no props and result in an object that has no props other deleted" do
264
- @mock.expects(:get).never
265
- @mock.expects(:post).never
266
- @mock.expects(:delete).with("#{Rainforest.api_base}/v1/customers/c_test_customer", nil, nil).once.returns(test_response({ "id" => "test_customer", "deleted" => true }))
267
-
268
- c = Rainforest::Customer.construct_from(test_customer)
269
- c.delete
270
- assert_equal true, c.deleted
271
-
272
- assert_raises NoMethodError do
273
- c.livemode
274
- end
275
- end
276
-
277
- should "loading an object with properties that have specific types should instantiate those classes" do
278
- @mock.expects(:get).once.returns(test_response(test_charge))
279
- c = Rainforest::Charge.retrieve("test_charge")
280
- assert c.card.kind_of?(Rainforest::RainforestObject) && c.card.object == 'card'
281
- end
282
-
283
- should "loading all of an APIResource should return an array of recursively instantiated objects" do
284
- @mock.expects(:get).once.returns(test_response(test_charge_array))
285
- c = Rainforest::Charge.all.data
286
- assert c.kind_of? Array
287
- assert c[0].kind_of? Rainforest::Charge
288
- assert c[0].card.kind_of?(Rainforest::RainforestObject) && c[0].card.object == 'card'
289
- end
290
-
291
- context "error checking" do
292
-
293
- should "404s should raise an InvalidRequestError" do
294
- response = test_response(test_missing_id_error, 404)
295
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
296
-
297
- begin
298
- Rainforest::Customer.new("test_customer").refresh
299
- assert false #shouldn't get here either
300
- rescue Rainforest::InvalidRequestError => e # we don't use assert_raises because we want to examine e
301
- assert e.kind_of? Rainforest::InvalidRequestError
302
- assert_equal "id", e.param
303
- assert_equal "Missing id", e.message
304
- return
305
- end
306
-
307
- assert false #shouldn't get here
308
- end
309
-
310
- should "5XXs should raise an APIError" do
311
- response = test_response(test_api_error, 500)
312
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
313
-
314
- begin
315
- Rainforest::Customer.new("test_customer").refresh
316
- assert false #shouldn't get here either
317
- rescue Rainforest::APIError => e # we don't use assert_raises because we want to examine e
318
- assert e.kind_of? Rainforest::APIError
319
- return
320
- end
321
-
322
- assert false #shouldn't get here
323
- end
324
-
325
- should "402s should raise a CardError" do
326
- response = test_response(test_invalid_exp_year_error, 402)
327
- @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 402))
328
-
329
- begin
330
- Rainforest::Customer.new("test_customer").refresh
331
- assert false #shouldn't get here either
332
- rescue Rainforest::CardError => e # we don't use assert_raises because we want to examine e
333
- assert e.kind_of? Rainforest::CardError
334
- assert_equal "invalid_expiry_year", e.code
335
- assert_equal "exp_year", e.param
336
- assert_equal "Your card's expiration year is invalid", e.message
337
- return
338
- end
339
-
340
- assert false #shouldn't get here
341
- end
342
- end
343
- end
344
- end
345
- end
@@ -1,67 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Rainforest
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 = Rainforest::Charge.all
8
- assert c.data.kind_of? Array
9
- c.each do |charge|
10
- assert charge.kind_of?(Rainforest::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 = Rainforest::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 = Rainforest::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 = Rainforest::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 = Rainforest::Charge.retrieve("test_charge")
42
- assert c.card.kind_of?(Rainforest::RainforestObject) && 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 == "#{Rainforest.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 = Rainforest::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
@@ -1,11 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Rainforest
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 = Rainforest::Coupon.create
8
- assert_equal "co_test_coupon", c.id
9
- end
10
- end
11
- end
@@ -1,70 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Rainforest
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 = Rainforest::Customer.all.data
8
- assert c.kind_of? Array
9
- assert c[0].kind_of? Rainforest::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 = Rainforest::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 = Rainforest::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 = Rainforest::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 = Rainforest::Customer.retrieve("test_customer")
38
-
39
- @mock.expects(:post).once.with do |url, api_key, params|
40
- url == "#{Rainforest.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 = Rainforest::Customer.retrieve("test_customer")
51
-
52
- # Not an accurate response, but whatever
53
-
54
- @mock.expects(:delete).once.with("#{Rainforest.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("#{Rainforest.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 = Rainforest::Customer.retrieve("test_customer")
64
-
65
- @mock.expects(:delete).once.with("#{Rainforest.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
@@ -1,20 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Rainforest
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 = Rainforest::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 = Rainforest::Invoice.retrieve('in_test_invoice')
14
-
15
- @mock.expects(:post).once.with('https://api.rainforest.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
@@ -1,16 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Rainforest
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 = Rainforest::Charge.all
8
- assert c.kind_of?(Rainforest::ListObject)
9
- assert_equal('/v1/charges', c.url)
10
- all = c.all
11
- assert all.kind_of?(Rainforest::ListObject)
12
- assert_equal('/v1/charges', all.url)
13
- assert all.data.kind_of?(Array)
14
- end
15
- end
16
- end
@@ -1,114 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Rainforest
4
- class MetadataTest < Test::Unit::TestCase
5
- setup do
6
- @metadata_supported = {
7
- :charge => {
8
- :new => Rainforest::Charge.method(:new),
9
- :test => method(:test_charge),
10
- :url => "/v1/charges/#{test_charge()[:id]}"
11
- },
12
- :customer => {
13
- :new => Rainforest::Customer.method(:new),
14
- :test => method(:test_customer),
15
- :url => "/v1/customers/#{test_customer()[:id]}"
16
- },
17
- :recipient => {
18
- :new => Rainforest::Recipient.method(:new),
19
- :test => method(:test_recipient),
20
- :url => "/v1/recipients/#{test_recipient()[:id]}"
21
- },
22
- :transfer => {
23
- :new => Rainforest::Transfer.method(:new),
24
- :test => method(:test_transfer),
25
- :url => "/v1/transfers/#{test_transfer()[:id]}"
26
- }
27
- }
28
-
29
- @base_url = 'https://api.rainforest.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 = Rainforest.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