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.
- data/LICENSE +19 -0
- data/lib/vaulted_billing/gateways/bogus.rb +2 -0
- data/lib/vaulted_billing/version.rb +1 -1
- data/spec/certification/ipcommerce/README.md +9 -0
- data/spec/certification/ipcommerce/TODO.md +1 -0
- data/spec/certification/ipcommerce/host_capture_ecommerce.rb +318 -0
- data/spec/certification/ipcommerce/ipcommerce_transaction.rb +28 -0
- data/spec/certification/ipcommerce/terminal_capture_ecommerce.rb +298 -0
- data/spec/config.example.yml +18 -0
- data/spec/factories/credit_cards.rb +38 -0
- data/spec/factories/customers.rb +7 -0
- data/spec/factories/sequences.rb +22 -0
- data/spec/fixtures/net/authorize_net_cim/add_customer/failure.yml +38 -0
- data/spec/fixtures/net/authorize_net_cim/add_customer/success.yml +39 -0
- data/spec/fixtures/net/authorize_net_cim/add_customer_credit_card/failure.yml +83 -0
- data/spec/fixtures/net/authorize_net_cim/add_customer_credit_card/success.yml +81 -0
- data/spec/fixtures/net/authorize_net_cim/authorize/failure.yml +121 -0
- data/spec/fixtures/net/authorize_net_cim/authorize/success.yml +121 -0
- data/spec/fixtures/net/authorize_net_cim/capture/failure.yml +161 -0
- data/spec/fixtures/net/authorize_net_cim/capture/success.yml +160 -0
- data/spec/fixtures/net/authorize_net_cim/purchase/failure.yml +122 -0
- data/spec/fixtures/net/authorize_net_cim/purchase/success.yml +122 -0
- data/spec/fixtures/net/authorize_net_cim/refund/failure.yml +123 -0
- data/spec/fixtures/net/authorize_net_cim/refund/failure_2.yml +43 -0
- data/spec/fixtures/net/authorize_net_cim/remove_customer/failure.yml +76 -0
- data/spec/fixtures/net/authorize_net_cim/remove_customer/success.yml +75 -0
- data/spec/fixtures/net/authorize_net_cim/remove_customer_credit_card/failure.yml +156 -0
- data/spec/fixtures/net/authorize_net_cim/remove_customer_credit_card/success.yml +118 -0
- data/spec/fixtures/net/authorize_net_cim/update_customer/failure.yml +77 -0
- data/spec/fixtures/net/authorize_net_cim/update_customer/success.yml +76 -0
- data/spec/fixtures/net/authorize_net_cim/update_customer_credit_card/failure.yml +125 -0
- data/spec/fixtures/net/authorize_net_cim/update_customer_credit_card/success.yml +124 -0
- data/spec/fixtures/net/authorize_net_cim/void/success.yml +159 -0
- data/spec/fixtures/net/ipcommerce/add_customer_credit_card/failure.yml +53 -0
- data/spec/fixtures/net/ipcommerce/add_customer_credit_card/success.yml +103 -0
- data/spec/fixtures/net/ipcommerce/authorize/existing/failure.yml +51 -0
- data/spec/fixtures/net/ipcommerce/authorize/existing/success.yml +105 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/bad_format.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/issuer_not_certified.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/match.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/no_match.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/no_response_from_card_association.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_included.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_sent.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_verified.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/invalid.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/issuer_not_certified.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_code_present.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_match.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_response.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/not_applicable.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/not_processed.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/cvv/should_have_been_present.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/failure.yml +53 -0
- data/spec/fixtures/net/ipcommerce/authorize/new/success.yml +53 -0
- data/spec/fixtures/net/ipcommerce/capture/failure.yml +78 -0
- data/spec/fixtures/net/ipcommerce/capture/invalid.yml +78 -0
- data/spec/fixtures/net/ipcommerce/capture/success.yml +78 -0
- data/spec/fixtures/net/ipcommerce/failover.yml +53 -0
- data/spec/fixtures/net/ipcommerce/purchase/existing/failure.yml +51 -0
- data/spec/fixtures/net/ipcommerce/purchase/existing/success.yml +105 -0
- data/spec/fixtures/net/ipcommerce/purchase/new/failure.yml +53 -0
- data/spec/fixtures/net/ipcommerce/purchase/new/success.yml +53 -0
- data/spec/fixtures/net/ipcommerce/refund/failure.yml +78 -0
- data/spec/fixtures/net/ipcommerce/refund/success.yml +80 -0
- data/spec/fixtures/net/ipcommerce/update_customer_credit_card/failure.yml +53 -0
- data/spec/fixtures/net/ipcommerce/update_customer_credit_card/success.yml +103 -0
- data/spec/fixtures/net/ipcommerce/void/failure.yml +78 -0
- data/spec/fixtures/net/ipcommerce/void/success.yml +78 -0
- data/spec/fixtures/net/nmi_customer_vault/add_customer_credit_card/failure.yml +26 -0
- data/spec/fixtures/net/nmi_customer_vault/add_customer_credit_card/success.yml +26 -0
- data/spec/fixtures/net/nmi_customer_vault/authorize/decline.yml +51 -0
- data/spec/fixtures/net/nmi_customer_vault/authorize/success.yml +51 -0
- data/spec/fixtures/net/nmi_customer_vault/capture/failure.yml +76 -0
- data/spec/fixtures/net/nmi_customer_vault/capture/success.yml +76 -0
- data/spec/fixtures/net/nmi_customer_vault/purchase/decline.yml +51 -0
- data/spec/fixtures/net/nmi_customer_vault/purchase/success.yml +51 -0
- data/spec/fixtures/net/nmi_customer_vault/refund/failure.yml +101 -0
- data/spec/fixtures/net/nmi_customer_vault/remove_customer_credit_card/failure.yml +26 -0
- data/spec/fixtures/net/nmi_customer_vault/remove_customer_credit_card/success.yml +51 -0
- data/spec/fixtures/net/nmi_customer_vault/update_customer_credit_card/success.yml +51 -0
- data/spec/fixtures/net/nmi_customer_vault/void/failure.yml +26 -0
- data/spec/fixtures/net/nmi_customer_vault/void/success.yml +76 -0
- data/spec/models/vaulted_billing/configuration_spec.rb +62 -0
- data/spec/models/vaulted_billing/core_ext/hash_spec.rb +47 -0
- data/spec/models/vaulted_billing/credit_card_spec.rb +61 -0
- data/spec/models/vaulted_billing/gateway_spec.rb +115 -0
- data/spec/models/vaulted_billing/http_spec.rb +154 -0
- data/spec/models/vaulted_billing/transaction_spec.rb +60 -0
- data/spec/models/vaulted_billing_spec.rb +16 -0
- data/spec/requests/authorize_net_cim_spec.rb +506 -0
- data/spec/requests/bogus_spec.rb +144 -0
- data/spec/requests/ipcommerce_spec.rb +518 -0
- data/spec/requests/nmi_customer_vault_spec.rb +390 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/_vaulted_billing.rb +8 -0
- data/spec/support/factory_girl.rb +5 -0
- data/spec/support/faker.rb +1 -0
- data/spec/support/helpers.rb +46 -0
- data/spec/support/logging.rb +2 -0
- data/spec/support/test_exception.rb +1 -0
- data/spec/support/vcr.rb +49 -0
- data/spec/support/webmock.rb +7 -0
- metadata +312 -37
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe VaultedBilling::CoreExt::Hash do
|
4
|
+
context 'to_querystring' do
|
5
|
+
it 'converts an empty hash' do
|
6
|
+
{}.to_querystring.should == ''
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'converts a one key hash' do
|
10
|
+
{'foo' => 'bar' }.to_querystring.should == 'foo=bar'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'converts numeric keys' do
|
14
|
+
{1 => 2}.to_querystring.should == '1=2'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'converts multi-key hashes' do
|
18
|
+
{'foo' => 'bar', 'faz' => 'baz'}.to_querystring.should == 'faz=baz&foo=bar'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sorts by key name' do
|
22
|
+
{'z' => 1, 'y' => 1, 'a' => 1}.to_querystring.should == 'a=1&y=1&z=1'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'from_querystring' do
|
27
|
+
it 'converts an empty string' do
|
28
|
+
Hash.from_querystring('').should == Hash.new
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'converts a one key string' do
|
32
|
+
Hash.from_querystring('foo=bar').should == {'foo' => 'bar'}
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'converts a multi-key string' do
|
36
|
+
Hash.from_querystring('foo=bar&faz=baz').should == {'foo' => 'bar', 'faz' => 'baz'}
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns empty strings for no-value keys' do
|
40
|
+
Hash.from_querystring('foo=&bar=').should == {'foo' => '', 'bar' => ''}
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns an empty hash with a nil value given' do
|
44
|
+
Hash.from_querystring(nil).should == {}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VaultedBilling::CreditCard do
|
4
|
+
let(:credit_card) { Factory.build :credit_card }
|
5
|
+
subject { credit_card }
|
6
|
+
|
7
|
+
context '#country' do
|
8
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'US' }
|
9
|
+
subject { credit_card.country }
|
10
|
+
|
11
|
+
it { should eql 'US' }
|
12
|
+
its(:to_iso_3166) { should == 840 }
|
13
|
+
its(:to_ipcommerce_id) { should == 234 }
|
14
|
+
|
15
|
+
context 'with a bad country code' do
|
16
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'BADCOUNTRY' }
|
17
|
+
|
18
|
+
it { should eql 'BADCOUNTRY' }
|
19
|
+
its(:to_iso_3166) { should be_nil }
|
20
|
+
its(:to_ipcommerce_id) { should == 0 }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "in Australia" do
|
24
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'AU' }
|
25
|
+
its(:to_ipcommerce_id) { should == 14 }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "in Canada" do
|
29
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'CA' }
|
30
|
+
its(:to_ipcommerce_id) { should == 39 }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "in France" do
|
34
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'FR' }
|
35
|
+
its(:to_ipcommerce_id) { should == 74 }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "in Mexico" do
|
39
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'MX' }
|
40
|
+
its(:to_ipcommerce_id) { should == 143 }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "in New Zealand" do
|
44
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'NZ' }
|
45
|
+
its(:to_ipcommerce_id) { should == 159 }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "in United Kingdom" do
|
49
|
+
let(:credit_card) { Factory.build :credit_card, :country => 'GB' }
|
50
|
+
its(:to_ipcommerce_id) { should == 233 }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context '#to_vaulted_billing' do
|
55
|
+
subject { credit_card.to_vaulted_billing }
|
56
|
+
|
57
|
+
it 'returns itself' do
|
58
|
+
subject.object_id.should == credit_card.object_id
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestGateway
|
4
|
+
include VaultedBilling::Gateway
|
5
|
+
end
|
6
|
+
|
7
|
+
class TestResponseObject
|
8
|
+
include VaultedBilling::Gateway::Response
|
9
|
+
end
|
10
|
+
|
11
|
+
describe VaultedBilling::Gateway do
|
12
|
+
let(:gateway) { TestGateway.new }
|
13
|
+
let(:customer) { Factory.build(:customer) }
|
14
|
+
let(:credit_card) { Factory.build(:credit_card) }
|
15
|
+
|
16
|
+
subject { gateway }
|
17
|
+
|
18
|
+
context 'add_customer' do
|
19
|
+
it 'raises NotImplementedError' do
|
20
|
+
expect { gateway.add_customer(customer) }.to raise_error(NotImplementedError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'update_customer' do
|
25
|
+
it 'raises NotImplementedError' do
|
26
|
+
expect { gateway.update_customer(customer) }.to raise_error(NotImplementedError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'remove_customer' do
|
31
|
+
it 'raises NotImplementedError' do
|
32
|
+
expect { gateway.remove_customer(customer) }.to raise_error(NotImplementedError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'add_customer_credit_card' do
|
37
|
+
it 'raises NotImplementedError' do
|
38
|
+
expect { gateway.add_customer_credit_card(customer, credit_card) }.to raise_error(NotImplementedError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'update_customer_credit_card' do
|
43
|
+
it 'raises NotImplementedError' do
|
44
|
+
expect { gateway.update_customer_credit_card(customer, credit_card) }.to raise_error(NotImplementedError)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'remove_customer_credit_card' do
|
49
|
+
it 'raises NotImplementedError' do
|
50
|
+
expect { gateway.remove_customer_credit_card(customer, credit_card) }.to raise_error(NotImplementedError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'authorize' do
|
55
|
+
it 'raises NotImplementedError' do
|
56
|
+
expect { gateway.authorize(customer, credit_card, 1) }.to raise_error(NotImplementedError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'capture' do
|
61
|
+
it 'raises NotImplementedError' do
|
62
|
+
expect { gateway.capture('transactionid', 1) }.to raise_error(NotImplementedError)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'purchase' do
|
67
|
+
it 'raises NotImplementedError' do
|
68
|
+
expect { gateway.purchase(customer, credit_card, 1) }.to raise_error(NotImplementedError)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'refund' do
|
73
|
+
it 'raises NotImplementedError' do
|
74
|
+
expect { gateway.refund('transactionid', 1) }.to raise_error(NotImplementedError)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'void' do
|
79
|
+
it 'raises NotImplementedError' do
|
80
|
+
expect { gateway.void('transactionid') }.to raise_error(NotImplementedError)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe VaultedBilling::Gateway::Response do
|
86
|
+
subject { TestResponseObject.new }
|
87
|
+
|
88
|
+
it 'returns the set response_message' do
|
89
|
+
expect {
|
90
|
+
subject.response_message = 'test'
|
91
|
+
subject.response_message.should == 'test'
|
92
|
+
}.to_not raise_error(NoMethodError)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns the set raw_response' do
|
96
|
+
expect {
|
97
|
+
subject.raw_response = 'test'
|
98
|
+
subject.raw_response.should == 'test'
|
99
|
+
}.to_not raise_error(NoMethodError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns the set error_code' do
|
103
|
+
expect {
|
104
|
+
subject.error_code = 'test'
|
105
|
+
subject.error_code.should == 'test'
|
106
|
+
}.to_not raise_error(NoMethodError)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'sets the success state' do
|
110
|
+
expect {
|
111
|
+
subject.success = true
|
112
|
+
subject.should be_success
|
113
|
+
}.to_not raise_error(NoMethodError)
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
class CallerObject
|
4
|
+
def before_request(request); end
|
5
|
+
def on_complete(response); end
|
6
|
+
def on_success(response); end
|
7
|
+
def on_error(response, error); end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe VaultedBilling::HTTP do
|
11
|
+
let(:http) { VaultedBilling::HTTP.new(callback_object, url, {
|
12
|
+
:before_request => :before_request,
|
13
|
+
:on_complete => :on_complete,
|
14
|
+
:on_success => :on_success,
|
15
|
+
:on_error => :on_error
|
16
|
+
}) }
|
17
|
+
|
18
|
+
let(:callback_object) { CallerObject.new }
|
19
|
+
|
20
|
+
let(:url) { 'https://1.2.3.4/' }
|
21
|
+
|
22
|
+
after(:each) { WebMock.reset! }
|
23
|
+
|
24
|
+
shared_examples_for "a request with callbacks" do |net_request|
|
25
|
+
it 'runs the before_request callback before submission' do
|
26
|
+
callback_object.should_receive(:before_request).with(an_instance_of(net_request)).and_raise(RuntimeError)
|
27
|
+
expect {
|
28
|
+
subject
|
29
|
+
}.to raise_error(RuntimeError)
|
30
|
+
WebMock.should_not have_requested(:any, url)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'runs the on_success callback after submission' do
|
34
|
+
callback_object.should_receive(:on_success).with(an_instance_of(VaultedBilling::HTTP::Response))
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'runs the on_complete callback after submission' do
|
39
|
+
callback_object.should_receive(:on_complete).with(an_instance_of(VaultedBilling::HTTP::Response))
|
40
|
+
subject
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'runs the on_error callback after submission' do
|
44
|
+
WebMock.stub_request(:any, url).to_raise(Timeout::Error.new('Test Exception'))
|
45
|
+
callback_object.should_receive(:on_error).with(an_instance_of(VaultedBilling::HTTP::Response), an_instance_of(Timeout::Error))
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
shared_examples_for "a request with timeout errors" do
|
51
|
+
context 'with Timeout errors' do
|
52
|
+
before(:each) do
|
53
|
+
WebMock.stub_request(:any, url).to_raise(Timeout::Error.new('Test Exception'))
|
54
|
+
end
|
55
|
+
|
56
|
+
after(:each) { WebMock.reset! }
|
57
|
+
|
58
|
+
it { should be_kind_of VaultedBilling::HTTP::Response}
|
59
|
+
it { should_not be_success }
|
60
|
+
|
61
|
+
it 'returns the error information' do
|
62
|
+
subject.message.tap do |message|
|
63
|
+
message.should match 'Timeout::Error'
|
64
|
+
message.should match 'Test Exception'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
shared_examples_for 'a request with a custom user agent' do
|
71
|
+
it 'sets the library name' do
|
72
|
+
subject
|
73
|
+
WebMock.should have_requested(:any, url).with(:headers => {'User-Agent' => /^vaulted_billing\b/})
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets the library version' do
|
77
|
+
subject
|
78
|
+
WebMock.should have_requested(:any, url).with(:headers => {'User-Agent' => /\b#{Regexp.escape(VaultedBilling::Version)}\b/})
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets the Ruby version' do
|
82
|
+
subject
|
83
|
+
WebMock.should have_requested(:any, url).with(:headers => {'User-Agent' => /\b#{Regexp.escape(RUBY_VERSION)}\b/})
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'sets the Ruby platform' do
|
87
|
+
subject
|
88
|
+
WebMock.should have_requested(:any, url).with(:headers => {'User-Agent' => /\b#{Regexp.escape(RUBY_PLATFORM)}\b/})
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context '#post' do
|
93
|
+
subject { http.post('fubar') }
|
94
|
+
|
95
|
+
before(:each) { WebMock.stub_request(:any, url) }
|
96
|
+
|
97
|
+
it 'posts the given data' do
|
98
|
+
subject
|
99
|
+
WebMock.should have_requested(:post, url).with(:body => 'fubar')
|
100
|
+
end
|
101
|
+
|
102
|
+
it_should_behave_like 'a request with a custom user agent'
|
103
|
+
it_should_behave_like "a request with callbacks", Net::HTTP::Post
|
104
|
+
it_should_behave_like "a request with timeout errors"
|
105
|
+
end
|
106
|
+
|
107
|
+
context '#get' do
|
108
|
+
subject { http.get }
|
109
|
+
|
110
|
+
before(:each) { WebMock.stub_request(:any, url) }
|
111
|
+
|
112
|
+
it 'gets the given url' do
|
113
|
+
subject
|
114
|
+
WebMock.should have_requested(:get, url)
|
115
|
+
end
|
116
|
+
|
117
|
+
it_should_behave_like 'a request with a custom user agent'
|
118
|
+
it_should_behave_like "a request with callbacks", Net::HTTP::Get
|
119
|
+
it_should_behave_like "a request with timeout errors"
|
120
|
+
end
|
121
|
+
|
122
|
+
context '#put' do
|
123
|
+
subject { http.put('bar') }
|
124
|
+
|
125
|
+
before(:each) { WebMock.stub_request(:any, url) }
|
126
|
+
|
127
|
+
it 'posts the given data' do
|
128
|
+
subject
|
129
|
+
WebMock.should have_requested(:put, url).with(:body => 'bar')
|
130
|
+
end
|
131
|
+
|
132
|
+
it_should_behave_like 'a request with a custom user agent'
|
133
|
+
it_should_behave_like "a request with callbacks", Net::HTTP::Put
|
134
|
+
it_should_behave_like "a request with timeout errors"
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'fails over to subsequent URIs with HTTP ERRORs raised' do
|
138
|
+
WebMock.stub_request(:any, /.*/).to_timeout
|
139
|
+
|
140
|
+
VaultedBilling::HTTP.new(callback_object, ['https://example1.com', 'https://example2.com']).tap do |http|
|
141
|
+
http.get
|
142
|
+
WebMock.should have_requested(:get, 'https://example1.com/')
|
143
|
+
WebMock.should have_requested(:get, 'https://example2.com/')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'returns connection error response when all URIs return HTTP ERRORs' do
|
148
|
+
WebMock.stub_request(:any, /.*/).to_timeout
|
149
|
+
|
150
|
+
VaultedBilling::HTTP.new(callback_object, ['https://example1.com', 'https://example2.com']).tap do |http|
|
151
|
+
http.get.should be_connection_error
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe VaultedBilling::Transaction do
|
4
|
+
subject { VaultedBilling::Transaction.new }
|
5
|
+
|
6
|
+
context 'to_vaulted_billing' do
|
7
|
+
it 'returns itself' do
|
8
|
+
subject.to_vaulted_billing.should == subject
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context '==' do
|
13
|
+
let(:attributes) { {:id => '123', :authcode => 'ABC'} }
|
14
|
+
|
15
|
+
it 'is true for Transactions with identical attributes' do
|
16
|
+
VaultedBilling::Transaction.new(attributes).
|
17
|
+
should == VaultedBilling::Transaction.new(attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'is false for Transactions with differing attributes' do
|
21
|
+
VaultedBilling::Transaction.new(attributes).
|
22
|
+
should_not == VaultedBilling::Transaction.
|
23
|
+
new(attributes.merge(:authcode => 'BAD'))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with attributes defined' do
|
28
|
+
let(:attributes) do
|
29
|
+
{ :id => '123',
|
30
|
+
:authcode => 'ABC',
|
31
|
+
:avs_response => true,
|
32
|
+
:cvv_response => true,
|
33
|
+
:code => '100',
|
34
|
+
:message => 'Test Message',
|
35
|
+
:masked_card_number => 'XXXX1234'
|
36
|
+
}
|
37
|
+
end
|
38
|
+
subject { VaultedBilling::Transaction.new(attributes) }
|
39
|
+
|
40
|
+
its(:id) { should == '123' }
|
41
|
+
its(:authcode) { should == 'ABC' }
|
42
|
+
its(:avs_response) { should be_true }
|
43
|
+
its(:cvv_response) { should be_true }
|
44
|
+
its(:code) { should == '100' }
|
45
|
+
its(:message) { should == 'Test Message' }
|
46
|
+
its(:masked_card_number) { should == 'XXXX1234' }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'attributes' do
|
50
|
+
subject { VaultedBilling::Transaction.new.attributes }
|
51
|
+
it { should be_kind_of Hash }
|
52
|
+
its(:keys) { should include :id }
|
53
|
+
its(:keys) { should include :authcode }
|
54
|
+
its(:keys) { should include :avs_response }
|
55
|
+
its(:keys) { should include :cvv_response }
|
56
|
+
its(:keys) { should include :code }
|
57
|
+
its(:keys) { should include :message }
|
58
|
+
its(:keys) { should include :masked_card_number }
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe VaultedBilling do
|
4
|
+
it "returns the requested Gateway" do
|
5
|
+
VaultedBilling.gateway(:bogus).should == VaultedBilling::Gateways::Bogus
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'config' do
|
9
|
+
subject { VaultedBilling.config }
|
10
|
+
it { should be_kind_of VaultedBilling::Configuration }
|
11
|
+
|
12
|
+
it 'return a consistant instance' do
|
13
|
+
subject.object_id.should == VaultedBilling.config.object_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|