vaulted_billing 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/LICENSE +19 -0
  2. data/lib/vaulted_billing/gateways/bogus.rb +2 -0
  3. data/lib/vaulted_billing/version.rb +1 -1
  4. data/spec/certification/ipcommerce/README.md +9 -0
  5. data/spec/certification/ipcommerce/TODO.md +1 -0
  6. data/spec/certification/ipcommerce/host_capture_ecommerce.rb +318 -0
  7. data/spec/certification/ipcommerce/ipcommerce_transaction.rb +28 -0
  8. data/spec/certification/ipcommerce/terminal_capture_ecommerce.rb +298 -0
  9. data/spec/config.example.yml +18 -0
  10. data/spec/factories/credit_cards.rb +38 -0
  11. data/spec/factories/customers.rb +7 -0
  12. data/spec/factories/sequences.rb +22 -0
  13. data/spec/fixtures/net/authorize_net_cim/add_customer/failure.yml +38 -0
  14. data/spec/fixtures/net/authorize_net_cim/add_customer/success.yml +39 -0
  15. data/spec/fixtures/net/authorize_net_cim/add_customer_credit_card/failure.yml +83 -0
  16. data/spec/fixtures/net/authorize_net_cim/add_customer_credit_card/success.yml +81 -0
  17. data/spec/fixtures/net/authorize_net_cim/authorize/failure.yml +121 -0
  18. data/spec/fixtures/net/authorize_net_cim/authorize/success.yml +121 -0
  19. data/spec/fixtures/net/authorize_net_cim/capture/failure.yml +161 -0
  20. data/spec/fixtures/net/authorize_net_cim/capture/success.yml +160 -0
  21. data/spec/fixtures/net/authorize_net_cim/purchase/failure.yml +122 -0
  22. data/spec/fixtures/net/authorize_net_cim/purchase/success.yml +122 -0
  23. data/spec/fixtures/net/authorize_net_cim/refund/failure.yml +123 -0
  24. data/spec/fixtures/net/authorize_net_cim/refund/failure_2.yml +43 -0
  25. data/spec/fixtures/net/authorize_net_cim/remove_customer/failure.yml +76 -0
  26. data/spec/fixtures/net/authorize_net_cim/remove_customer/success.yml +75 -0
  27. data/spec/fixtures/net/authorize_net_cim/remove_customer_credit_card/failure.yml +156 -0
  28. data/spec/fixtures/net/authorize_net_cim/remove_customer_credit_card/success.yml +118 -0
  29. data/spec/fixtures/net/authorize_net_cim/update_customer/failure.yml +77 -0
  30. data/spec/fixtures/net/authorize_net_cim/update_customer/success.yml +76 -0
  31. data/spec/fixtures/net/authorize_net_cim/update_customer_credit_card/failure.yml +125 -0
  32. data/spec/fixtures/net/authorize_net_cim/update_customer_credit_card/success.yml +124 -0
  33. data/spec/fixtures/net/authorize_net_cim/void/success.yml +159 -0
  34. data/spec/fixtures/net/ipcommerce/add_customer_credit_card/failure.yml +53 -0
  35. data/spec/fixtures/net/ipcommerce/add_customer_credit_card/success.yml +103 -0
  36. data/spec/fixtures/net/ipcommerce/authorize/existing/failure.yml +51 -0
  37. data/spec/fixtures/net/ipcommerce/authorize/existing/success.yml +105 -0
  38. data/spec/fixtures/net/ipcommerce/authorize/new/avs/bad_format.yml +53 -0
  39. data/spec/fixtures/net/ipcommerce/authorize/new/avs/issuer_not_certified.yml +53 -0
  40. data/spec/fixtures/net/ipcommerce/authorize/new/avs/match.yml +53 -0
  41. data/spec/fixtures/net/ipcommerce/authorize/new/avs/no_match.yml +53 -0
  42. data/spec/fixtures/net/ipcommerce/authorize/new/avs/no_response_from_card_association.yml +53 -0
  43. data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_included.yml +53 -0
  44. data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_sent.yml +53 -0
  45. data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_verified.yml +53 -0
  46. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/invalid.yml +53 -0
  47. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/issuer_not_certified.yml +53 -0
  48. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_code_present.yml +53 -0
  49. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_match.yml +53 -0
  50. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_response.yml +53 -0
  51. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/not_applicable.yml +53 -0
  52. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/not_processed.yml +53 -0
  53. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/should_have_been_present.yml +53 -0
  54. data/spec/fixtures/net/ipcommerce/authorize/new/failure.yml +53 -0
  55. data/spec/fixtures/net/ipcommerce/authorize/new/success.yml +53 -0
  56. data/spec/fixtures/net/ipcommerce/capture/failure.yml +78 -0
  57. data/spec/fixtures/net/ipcommerce/capture/invalid.yml +78 -0
  58. data/spec/fixtures/net/ipcommerce/capture/success.yml +78 -0
  59. data/spec/fixtures/net/ipcommerce/failover.yml +53 -0
  60. data/spec/fixtures/net/ipcommerce/purchase/existing/failure.yml +51 -0
  61. data/spec/fixtures/net/ipcommerce/purchase/existing/success.yml +105 -0
  62. data/spec/fixtures/net/ipcommerce/purchase/new/failure.yml +53 -0
  63. data/spec/fixtures/net/ipcommerce/purchase/new/success.yml +53 -0
  64. data/spec/fixtures/net/ipcommerce/refund/failure.yml +78 -0
  65. data/spec/fixtures/net/ipcommerce/refund/success.yml +80 -0
  66. data/spec/fixtures/net/ipcommerce/update_customer_credit_card/failure.yml +53 -0
  67. data/spec/fixtures/net/ipcommerce/update_customer_credit_card/success.yml +103 -0
  68. data/spec/fixtures/net/ipcommerce/void/failure.yml +78 -0
  69. data/spec/fixtures/net/ipcommerce/void/success.yml +78 -0
  70. data/spec/fixtures/net/nmi_customer_vault/add_customer_credit_card/failure.yml +26 -0
  71. data/spec/fixtures/net/nmi_customer_vault/add_customer_credit_card/success.yml +26 -0
  72. data/spec/fixtures/net/nmi_customer_vault/authorize/decline.yml +51 -0
  73. data/spec/fixtures/net/nmi_customer_vault/authorize/success.yml +51 -0
  74. data/spec/fixtures/net/nmi_customer_vault/capture/failure.yml +76 -0
  75. data/spec/fixtures/net/nmi_customer_vault/capture/success.yml +76 -0
  76. data/spec/fixtures/net/nmi_customer_vault/purchase/decline.yml +51 -0
  77. data/spec/fixtures/net/nmi_customer_vault/purchase/success.yml +51 -0
  78. data/spec/fixtures/net/nmi_customer_vault/refund/failure.yml +101 -0
  79. data/spec/fixtures/net/nmi_customer_vault/remove_customer_credit_card/failure.yml +26 -0
  80. data/spec/fixtures/net/nmi_customer_vault/remove_customer_credit_card/success.yml +51 -0
  81. data/spec/fixtures/net/nmi_customer_vault/update_customer_credit_card/success.yml +51 -0
  82. data/spec/fixtures/net/nmi_customer_vault/void/failure.yml +26 -0
  83. data/spec/fixtures/net/nmi_customer_vault/void/success.yml +76 -0
  84. data/spec/models/vaulted_billing/configuration_spec.rb +62 -0
  85. data/spec/models/vaulted_billing/core_ext/hash_spec.rb +47 -0
  86. data/spec/models/vaulted_billing/credit_card_spec.rb +61 -0
  87. data/spec/models/vaulted_billing/gateway_spec.rb +115 -0
  88. data/spec/models/vaulted_billing/http_spec.rb +154 -0
  89. data/spec/models/vaulted_billing/transaction_spec.rb +60 -0
  90. data/spec/models/vaulted_billing_spec.rb +16 -0
  91. data/spec/requests/authorize_net_cim_spec.rb +506 -0
  92. data/spec/requests/bogus_spec.rb +144 -0
  93. data/spec/requests/ipcommerce_spec.rb +518 -0
  94. data/spec/requests/nmi_customer_vault_spec.rb +390 -0
  95. data/spec/spec_helper.rb +12 -0
  96. data/spec/support/_vaulted_billing.rb +8 -0
  97. data/spec/support/factory_girl.rb +5 -0
  98. data/spec/support/faker.rb +1 -0
  99. data/spec/support/helpers.rb +46 -0
  100. data/spec/support/logging.rb +2 -0
  101. data/spec/support/test_exception.rb +1 -0
  102. data/spec/support/vcr.rb +49 -0
  103. data/spec/support/webmock.rb +7 -0
  104. metadata +312 -37
@@ -0,0 +1,390 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe VaultedBilling::Gateways::NmiCustomerVault do
4
+ let(:gateway) { VaultedBilling.gateway(:nmi_customer_vault).new }
5
+
6
+ it 'uses the correct URI in test mode' do
7
+ gateway.use_test_uri = true
8
+ gateway.uri.to_s.should == 'https://secure.nmi.com/api/transact.php'
9
+ end
10
+
11
+ it 'uses the correct URI in live mode' do
12
+ gateway.use_test_uri = false
13
+ gateway.uri.to_s.should == 'https://secure.nmi.com/api/transact.php'
14
+ end
15
+
16
+ context 'add_customer' do
17
+ let(:customer) { Factory.build(:customer) }
18
+ subject { gateway.add_customer(customer) }
19
+
20
+ it 'returns a Customer' do
21
+ subject.should be_kind_of VaultedBilling::Customer
22
+ end
23
+
24
+ it 'is successful' do
25
+ subject.should be_success
26
+ end
27
+
28
+ it 'does not make a service request' do
29
+ WebMock.should_not have_requested(:post, gateway.uri.to_s)
30
+ end
31
+ end
32
+
33
+ context 'update_customer' do
34
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
35
+ subject { gateway.update_customer(customer) }
36
+
37
+ it 'returns a Customer' do
38
+ subject.should be_kind_of VaultedBilling::Customer
39
+ end
40
+
41
+ it 'is successful' do
42
+ subject.should be_success
43
+ end
44
+
45
+ it 'does not make a service request' do
46
+ WebMock.should_not have_requested(:post, gateway.uri.to_s)
47
+ end
48
+ end
49
+
50
+ context 'remove_customer' do
51
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
52
+ subject { gateway.remove_customer(customer) }
53
+
54
+ it 'returns a Customer' do
55
+ subject.should be_kind_of VaultedBilling::Customer
56
+ end
57
+
58
+ it 'is successful' do
59
+ subject.should be_success
60
+ end
61
+
62
+ it 'does not make a service request' do
63
+ WebMock.should_not have_requested(:post, gateway.uri.to_s)
64
+ end
65
+ end
66
+
67
+ context 'add_customer_credit_card' do
68
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
69
+ let(:credit_card) { Factory.build(:credit_card) }
70
+
71
+ context 'with a successful result' do
72
+ use_vcr_cassette 'nmi_customer_vault/add_customer_credit_card/success'
73
+
74
+ subject { gateway.add_customer_credit_card(customer, credit_card) }
75
+ it_should_behave_like 'a credit card request'
76
+
77
+ it 'is successful' do
78
+ subject.should be_success
79
+ end
80
+
81
+ its(:response_message) { should == 'Customer Added' }
82
+ its(:error_code) { should be_nil }
83
+ end
84
+
85
+ context 'with an unsuccessful result' do
86
+ use_vcr_cassette 'nmi_customer_vault/add_customer_credit_card/failure'
87
+ let(:credit_card) { Factory.build(:credit_card, :card_number => nil) }
88
+ subject { gateway.add_customer_credit_card(customer, credit_card) }
89
+
90
+ it 'returns a CreditCard' do
91
+ subject.should be_kind_of VaultedBilling::CreditCard
92
+ end
93
+
94
+ it 'is unsuccessful' do
95
+ subject.should_not be_success
96
+ end
97
+
98
+ its(:response_message) { should =~ /Required Field cc_number is Missing or Empty REFID:.+/ }
99
+ its(:error_code) { should == '300' }
100
+ end
101
+
102
+ request_exception_context do
103
+ let(:credit_card) { Factory.build(:credit_card, :card_number => nil) }
104
+ subject { gateway.add_customer_credit_card(customer, credit_card) }
105
+ it_should_behave_like 'a failed connection attempt'
106
+ end
107
+ end
108
+
109
+ context 'update_customer_credit_card' do
110
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
111
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
112
+
113
+ context 'with a successful result' do
114
+ use_vcr_cassette 'nmi_customer_vault/update_customer_credit_card/success'
115
+ subject { gateway.update_customer_credit_card(customer, credit_card) }
116
+ it_should_behave_like 'a credit card request'
117
+
118
+ it 'is successful' do
119
+ should be_success
120
+ end
121
+ end
122
+
123
+ context 'with an unsuccessful result' do
124
+ use_vcr_cassette 'nmi_customer_vault/update_customer_credit_card/failure'
125
+ before(:each) { pending "The NMI Customer Vault currently *always* returns a successful response, even with obviously invalid data." }
126
+ let(:customer) { VaultedBilling::Customer.new }
127
+ let(:credit_card) { VaultedBilling::CreditCard.new }
128
+ subject { gateway.update_customer_credit_card(customer, credit_card) }
129
+ it_should_behave_like 'a credit card request'
130
+
131
+ it 'is unsuccessful' do
132
+ should_not be_success
133
+ end
134
+ end
135
+
136
+ request_exception_context do
137
+ let(:customer) { VaultedBilling::Customer.new }
138
+ let(:credit_card) { VaultedBilling::CreditCard.new }
139
+ subject { gateway.update_customer_credit_card(customer, credit_card) }
140
+ it_should_behave_like 'a failed connection attempt'
141
+ end
142
+ end
143
+
144
+ context 'remove_customer_credit_card' do
145
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
146
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
147
+
148
+ context 'with a successful result' do
149
+ use_vcr_cassette 'nmi_customer_vault/remove_customer_credit_card/success'
150
+ subject { gateway.remove_customer_credit_card(customer, credit_card) }
151
+ it_should_behave_like 'a credit card request'
152
+
153
+ it 'is successful' do
154
+ should be_success
155
+ end
156
+ end
157
+
158
+ context 'with an unsuccessful result' do
159
+ use_vcr_cassette 'nmi_customer_vault/remove_customer_credit_card/failure'
160
+ let(:credit_card) { Factory.build(:existing_credit_card, :vault_id => 'VERYBADIDENTIFIER!') }
161
+ subject { gateway.remove_customer_credit_card(customer, credit_card) }
162
+ it_should_behave_like 'a credit card request'
163
+
164
+ it 'is unsuccessful' do
165
+ should_not be_success
166
+ end
167
+ end
168
+
169
+ request_exception_context do
170
+ let(:credit_card) { Factory.build(:existing_credit_card, :vault_id => 'VERYBADIDENTIFIER!') }
171
+ subject { gateway.remove_customer_credit_card(customer, credit_card) }
172
+ it_should_behave_like 'a failed connection attempt'
173
+ end
174
+ end
175
+
176
+ context 'purchase' do
177
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
178
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
179
+
180
+ context 'with a successful result' do
181
+ use_vcr_cassette 'nmi_customer_vault/purchase/success'
182
+ subject { gateway.purchase(customer, credit_card, 1.00) }
183
+ it_should_behave_like 'a transaction request'
184
+
185
+ it 'is successful' do
186
+ should be_success
187
+ end
188
+
189
+ it('has an false AVS response') { subject.avs_response.should be_false }
190
+ it('has a false CVV response') { subject.cvv_response.should be_false }
191
+ it('has an authcode') { subject.authcode.should be_present }
192
+ it('has a message') { subject.message.should be_present }
193
+ it('has a response code') { subject.code.should be_present }
194
+ end
195
+
196
+ context 'with an DECLINE result' do
197
+ use_vcr_cassette 'nmi_customer_vault/purchase/decline'
198
+ subject { gateway.purchase(customer, credit_card, 0.01) }
199
+ it_should_behave_like 'a transaction request'
200
+
201
+ it 'is unsuccessful' do
202
+ should_not be_success
203
+ end
204
+ end
205
+
206
+ request_exception_context do
207
+ subject { gateway.purchase(customer, credit_card, 0.01) }
208
+ it_should_behave_like 'a failed connection attempt'
209
+ end
210
+ end
211
+
212
+ context 'authorize' do
213
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
214
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
215
+
216
+ context 'with a successful result' do
217
+ use_vcr_cassette 'nmi_customer_vault/authorize/success'
218
+ subject { gateway.authorize(customer, credit_card, 1.00) }
219
+ it_should_behave_like 'a transaction request'
220
+
221
+ it 'is successful' do
222
+ should be_success
223
+ end
224
+
225
+ it('has an false AVS response') { subject.avs_response.should be_false }
226
+ it('has a false CVV response') { subject.cvv_response.should be_false }
227
+ it('has an authcode') { subject.authcode.should be_present }
228
+ it('has a message') { subject.message.should be_present }
229
+ it('has a response code') { subject.code.should be_present }
230
+ end
231
+
232
+ context 'with an DECLINE result' do
233
+ use_vcr_cassette 'nmi_customer_vault/authorize/decline'
234
+ subject { gateway.authorize(customer, credit_card, 0.01) }
235
+ it_should_behave_like 'a transaction request'
236
+
237
+ it 'is unsuccessful' do
238
+ should_not be_success
239
+ end
240
+ end
241
+
242
+ request_exception_context do
243
+ subject { gateway.authorize(customer, credit_card, 0.01) }
244
+ it_should_behave_like 'a failed connection attempt'
245
+ end
246
+ end
247
+
248
+ context 'capture' do
249
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
250
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
251
+ let(:authorization) { gateway.authorize(customer, credit_card, 10.00) }
252
+
253
+ context 'with a successful result' do
254
+ use_vcr_cassette 'nmi_customer_vault/capture/success'
255
+ let(:capture) { gateway.capture(authorization.id, 5.00) }
256
+ subject { capture }
257
+ it_should_behave_like 'a transaction request'
258
+
259
+ it 'is successful' do
260
+ should be_success
261
+ end
262
+ end
263
+
264
+ context 'with a DECLINE result' do
265
+ use_vcr_cassette 'nmi_customer_vault/capture/failure'
266
+ let(:capture) { gateway.capture(authorization.id, 500.00) }
267
+ subject { capture }
268
+ it_should_behave_like 'a transaction request'
269
+
270
+ it 'is unsuccessful' do
271
+ should_not be_success
272
+ end
273
+ end
274
+
275
+ request_exception_context do
276
+ let(:capture) { gateway.capture(authorization.id, 500.00) }
277
+ subject { capture }
278
+ it_should_behave_like 'a failed connection attempt'
279
+ end
280
+ end
281
+
282
+ context 'refund' do
283
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
284
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
285
+ let(:authorization) { gateway.authorize(customer, credit_card, 5.00) }
286
+ let(:capture) { gateway.capture(authorization.id, 3.00) }
287
+
288
+ context 'with a successful result' do
289
+ use_vcr_cassette 'nmi_customer_vault/refund/success'
290
+ let(:refund) { gateway.refund(capture.id, 3.00) }
291
+ before(:each) do
292
+ pending 'Does not appear to allow me to immediately refund a capture'
293
+ end
294
+ subject { refund }
295
+ it_should_behave_like 'a transaction request'
296
+
297
+ it 'is successful' do
298
+ should be_success
299
+ end
300
+ end
301
+
302
+ context 'with a DECLINE result' do
303
+ use_vcr_cassette 'nmi_customer_vault/refund/failure'
304
+ let(:refund) { gateway.refund(capture.id, 300.00) }
305
+ subject { refund }
306
+
307
+ it 'returns a Transaction' do
308
+ subject.should be_kind_of VaultedBilling::Transaction
309
+ end
310
+
311
+ it 'returns a Transaction without an identifier' do
312
+ subject.id.should be_blank
313
+ end
314
+
315
+ it 'is unsuccessful' do
316
+ should_not be_success
317
+ end
318
+ end
319
+
320
+ request_exception_context do
321
+ let(:refund) { gateway.refund(capture.id, 300.00) }
322
+ subject { refund }
323
+ it_should_behave_like 'a failed connection attempt'
324
+ end
325
+ end
326
+
327
+ context 'void' do
328
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
329
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
330
+ let(:authorization) { gateway.authorize(customer, credit_card, 5.00) }
331
+
332
+ context 'with a successful result' do
333
+ use_vcr_cassette 'nmi_customer_vault/void/success'
334
+ let(:void) { gateway.void(authorization.id) }
335
+ subject { void }
336
+ it_should_behave_like 'a transaction request'
337
+
338
+ it 'is successful' do
339
+ should be_success
340
+ end
341
+ end
342
+
343
+ context 'with a DECLINE result' do
344
+ use_vcr_cassette 'nmi_customer_vault/void/failure'
345
+ let(:void) { gateway.void('INVALIDID') }
346
+ subject { void }
347
+
348
+ it 'returns a Transaction' do
349
+ subject.should be_kind_of VaultedBilling::Transaction
350
+ end
351
+
352
+ it 'returns a Transaction without an identifier' do
353
+ subject.id.should be_blank
354
+ end
355
+
356
+ it 'is unsuccessful' do
357
+ should_not be_success
358
+ end
359
+ end
360
+
361
+ request_exception_context do
362
+ let(:void) { gateway.void('INVALIDID') }
363
+ subject { void }
364
+ it_should_behave_like 'a failed connection attempt'
365
+ end
366
+ end
367
+
368
+ context 'with raw_options' do
369
+ context 'with a successful result' do
370
+ use_vcr_cassette 'nmi_customer_vault/authorize/success'
371
+ let(:gateway) { VaultedBilling.gateway(:nmi_customer_vault).new(:username => 'demo', :password => 'password', :raw_options => 'dup_seconds=1') }
372
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
373
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
374
+
375
+ it 'includes the options in the request' do
376
+ customer
377
+ credit_card
378
+
379
+ http = stub("http")
380
+ http.should_receive(:post).
381
+ with(%r{&dup_seconds=1}m).
382
+ and_raise(TestException)
383
+ gateway.should_receive(:http).
384
+ and_return(http)
385
+ expect { gateway.authorize(customer, credit_card, 10.00) }.
386
+ to raise_error(TestException)
387
+ end
388
+ end
389
+ end
390
+ end
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.expand_path('../../lib', __FILE__))
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ Bundler.require :default, :test
5
+
6
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].sort.each { |f| require f }
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_with :rspec
10
+ config.filter_run :focus => true
11
+ config.run_all_when_everything_filtered = true
12
+ end
@@ -0,0 +1,8 @@
1
+ require 'pathname'
2
+
3
+ path = Pathname.new(File.expand_path('../../config.yml', __FILE__))
4
+ if path.exist?
5
+ VaultedBilling.set_config(YAML.load_file(path.to_s))
6
+ else
7
+ abort "Please setup a #{path} file."
8
+ end
@@ -0,0 +1,5 @@
1
+ require 'factory_girl'
2
+
3
+ Dir[File.expand_path('../../factories/**/*.rb', __FILE__)].each do |factory|
4
+ require factory
5
+ end
@@ -0,0 +1 @@
1
+ require 'faker'
@@ -0,0 +1,46 @@
1
+ module RSpecHelpers
2
+ module InstanceMethods
3
+ shared_examples_for "a transaction request" do
4
+ it 'returns a Transaction' do
5
+ subject.should be_kind_of(VaultedBilling::Transaction)
6
+ end
7
+
8
+ it 'returns a Transaction with an identifier' do
9
+ subject.id.should_not be_blank
10
+ end
11
+ end
12
+
13
+ shared_examples_for 'a customer request' do
14
+ it 'returns a Customer' do
15
+ subject.should be_kind_of(VaultedBilling::Customer)
16
+ end
17
+
18
+ it 'returns a Customer with an identifier' do
19
+ subject.vault_id.should_not be_blank
20
+ end
21
+ end
22
+
23
+ shared_examples_for 'a credit card request' do
24
+ it 'returns a CreditCard' do
25
+ subject.should be_kind_of(VaultedBilling::CreditCard)
26
+ end
27
+
28
+ it 'returns a CreditCard with an identifier' do
29
+ subject.vault_id.should_not be_blank
30
+ end
31
+ end
32
+
33
+ shared_examples_for 'a failed connection attempt' do
34
+ it 'is unsuccessful' do
35
+ subject.should_not be_success
36
+ end
37
+ its(:response_message) { should == 'A communication problem has occurred.' }
38
+ its(:error_code) { should_not be_blank }
39
+ it { subject.should be_connection_error }
40
+ end
41
+ end
42
+ end
43
+
44
+ RSpec.configure do |config|
45
+ config.include RSpecHelpers::InstanceMethods
46
+ end