|
6 | 6 | defined?(AuthorizeNet).should be_truthy |
7 | 7 | AuthorizeNet.class.should equal(Module) |
8 | 8 | end |
9 | | - |
| 9 | + |
10 | 10 | it "should have a module called AIM" do |
11 | 11 | defined?(AuthorizeNet::AIM).should be_truthy |
12 | 12 | AuthorizeNet::AIM.class.should equal(Module) |
|
15 | 15 | end |
16 | 16 |
|
17 | 17 | describe AuthorizeNet::CreditCard do |
18 | | - |
| 18 | + |
19 | 19 | before do |
20 | 20 | @card_number = '4111111111111111' |
21 | 21 | @expiry = '01' + (Time.now + (3600 * 24 * 365)).strftime('%y') |
22 | 22 | end |
23 | | - |
| 23 | + |
24 | 24 | it "should support instantiation" do |
25 | 25 | AuthorizeNet::CreditCard.new(@card_number, @expiry).should be_instance_of(AuthorizeNet::CreditCard) |
26 | 26 | end |
27 | | - |
| 27 | + |
28 | 28 | it "should support converting itself into a hash" do |
29 | 29 | card = AuthorizeNet::CreditCard.new(@card_number, @expiry) |
30 | 30 | card.should respond_to(:to_hash) |
31 | 31 | card.to_hash.should be_kind_of(Hash) |
32 | 32 | end |
33 | | - |
| 33 | + |
34 | 34 | it "should have the right payment method type" do |
35 | 35 | card = AuthorizeNet::CreditCard.new(@card_number, @expiry) |
36 | 36 | fields = card.to_hash |
37 | 37 | fields[:method].should == AuthorizeNet::PaymentMethodType::CREDIT_CARD |
38 | 38 | end |
39 | | - |
| 39 | + |
40 | 40 | it "should respond to attributes" do |
41 | 41 | card = AuthorizeNet::CreditCard.new(@card_number, @expiry) |
42 | 42 | card.card_number.should == @card_number |
43 | 43 | card.expiration.should == @expiry |
44 | 44 | card.card_code.should be_nil |
45 | 45 | end |
46 | 46 | =begin |
47 | | - it 'should clean the track' do |
| 47 | + it 'should clean the track' do |
48 | 48 | card = AuthorizeNet::CreditCard.new(@card_number, @expiry, track_1: '%1111111111111111=11111111111111111111?3', track_2: ';2222222222222222=22222222222222222222?3') |
49 | 49 | card_hash = card.to_hash |
50 | 50 | expect(card_hash[:track_1]).to eq('1111111111111111=11111111111111111111') |
51 | 51 | expect(card_hash[:track_2]).to eq('2222222222222222=22222222222222222222') |
52 | | - |
| 52 | +
|
53 | 53 | card = AuthorizeNet::CreditCard.new(@card_number, @expiry, track_1: '1111111111111111=11111111111111111111', track_2: '2222222222222222=22222222222222222222') |
54 | 54 | card_hash = card.to_hash |
55 | 55 | expect(card_hash[:track_1]).to eq('1111111111111111=11111111111111111111') |
|
59 | 59 | end |
60 | 60 |
|
61 | 61 | describe AuthorizeNet::ECheck do |
62 | | - |
| 62 | + |
63 | 63 | before do |
64 | 64 | @routing_number = '322271627' |
65 | 65 | @account_number = '123456789' |
66 | 66 | @bank_name = 'JPMorgan Chase Bank' |
67 | 67 | @account_holder_name = 'John Doe' |
68 | 68 | end |
69 | | - |
| 69 | + |
70 | 70 | it "should support instantiation" do |
71 | 71 | AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name).should be_instance_of(AuthorizeNet::ECheck) |
72 | 72 | end |
73 | | - |
| 73 | + |
74 | 74 | it "should support converting itself into a hash" do |
75 | 75 | echeck = AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name) |
76 | 76 | echeck.should respond_to(:to_hash) |
77 | 77 | echeck.to_hash.should be_kind_of(Hash) |
78 | 78 | end |
79 | | - |
| 79 | + |
80 | 80 | it "should support payment method code retrival" do |
81 | 81 | echeck = AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name) |
82 | 82 | fields = echeck.to_hash |
|
85 | 85 | end |
86 | 86 |
|
87 | 87 | describe AuthorizeNet::Address do |
88 | | - |
| 88 | + |
89 | 89 | before do |
90 | 90 | end |
91 | | - |
| 91 | + |
92 | 92 | it "should support instantiation" do |
93 | 93 | AuthorizeNet::Address.new.should be_instance_of(AuthorizeNet::Address) |
94 | 94 | end |
95 | | - |
| 95 | + |
96 | 96 | it "should support converting itself into a hash" do |
97 | 97 | address = AuthorizeNet::Address.new |
98 | 98 | address.should respond_to(:to_hash) |
99 | 99 | address.to_hash.should be_kind_of(Hash) |
100 | 100 | end |
101 | | - |
| 101 | + |
102 | 102 | it "should ignore unknown fields" do |
103 | 103 | address = AuthorizeNet::Address.new(:tax => '123') |
104 | 104 | hash = address.to_hash |
105 | 105 | hash.should be_kind_of(Hash) |
106 | 106 | hash.should == {} |
107 | 107 | end |
108 | | - |
| 108 | + |
109 | 109 | it "should accept known fields" do |
110 | 110 | address = AuthorizeNet::Address.new(:first_name => '123') |
111 | 111 | hash = address.to_hash |
|
115 | 115 | end |
116 | 116 |
|
117 | 117 | describe AuthorizeNet::ShippingAddress do |
118 | | - |
| 118 | + |
119 | 119 | before do |
120 | 120 | end |
121 | | - |
| 121 | + |
122 | 122 | it "should support instantiation" do |
123 | 123 | AuthorizeNet::ShippingAddress.new.should be_instance_of(AuthorizeNet::ShippingAddress) |
124 | 124 | end |
125 | | - |
| 125 | + |
126 | 126 | it "should support converting itself into a hash" do |
127 | 127 | address = AuthorizeNet::ShippingAddress.new |
128 | 128 | address.should respond_to(:to_hash) |
129 | 129 | address.to_hash.should be_kind_of(Hash) |
130 | 130 | end |
131 | | - |
| 131 | + |
132 | 132 | it "should ignore unknown fields" do |
133 | 133 | address = AuthorizeNet::ShippingAddress.new(:pie => '123') |
134 | 134 | hash = address.to_hash |
135 | 135 | hash.should be_kind_of(Hash) |
136 | 136 | hash.should == {} |
137 | 137 | end |
138 | | - |
| 138 | + |
139 | 139 | it "should accept known fields" do |
140 | 140 | address = AuthorizeNet::ShippingAddress.new(:first_name => '123') |
141 | 141 | hash = address.to_hash |
|
145 | 145 | end |
146 | 146 |
|
147 | 147 | describe AuthorizeNet::Customer do |
148 | | - |
| 148 | + |
149 | 149 | before do |
150 | 150 | end |
151 | | - |
| 151 | + |
152 | 152 | it "should support instantiation" do |
153 | 153 | AuthorizeNet::Customer.new.should be_instance_of(AuthorizeNet::Customer) |
154 | 154 | end |
155 | | - |
| 155 | + |
156 | 156 | it "should support converting itself into a hash" do |
157 | 157 | customer = AuthorizeNet::Customer.new |
158 | 158 | customer.should respond_to(:to_hash) |
159 | 159 | customer.to_hash.should be_kind_of(Hash) |
160 | 160 | end |
161 | | - |
| 161 | + |
162 | 162 | it "should ignore unknown fields" do |
163 | 163 | customer = AuthorizeNet::Customer.new(:name => '123') |
164 | 164 | hash = customer.to_hash |
165 | 165 | hash.should be_kind_of(Hash) |
166 | 166 | hash.should == {} |
167 | 167 | end |
168 | | - |
| 168 | + |
169 | 169 | it "should accept known fields" do |
170 | 170 | customer = AuthorizeNet::Customer.new(:id => '123') |
171 | 171 | hash = customer.to_hash |
172 | 172 | hash.should be_kind_of(Hash) |
173 | 173 | hash.should == {:cust_id => '123'} |
174 | 174 | end |
175 | | - |
| 175 | + |
176 | 176 | it "should accept an address record" do |
177 | 177 | address = AuthorizeNet::Address.new(:first_name => 'Tester', :last_name => 'Testerson') |
178 | 178 | customer = AuthorizeNet::Customer.new(:address => address) |
|
183 | 183 | end |
184 | 184 |
|
185 | 185 | describe AuthorizeNet::EmailReceipt do |
186 | | - |
| 186 | + |
187 | 187 | before do |
188 | 188 | end |
189 | | - |
| 189 | + |
190 | 190 | it "should support instantiation" do |
191 | 191 | AuthorizeNet::EmailReceipt.new.should be_instance_of(AuthorizeNet::EmailReceipt) |
192 | 192 | end |
193 | | - |
| 193 | + |
194 | 194 | it "should support converting itself into a hash" do |
195 | 195 | email = AuthorizeNet::EmailReceipt.new |
196 | 196 | email.should respond_to(:to_hash) |
197 | 197 | email.to_hash.should be_kind_of(Hash) |
198 | 198 | end |
199 | | - |
| 199 | + |
200 | 200 | it "should ignore unknown fields" do |
201 | 201 | email = AuthorizeNet::EmailReceipt.new(:name => '123') |
202 | 202 | hash = email.to_hash |
203 | 203 | hash.should be_kind_of(Hash) |
204 | 204 | hash.should == {} |
205 | 205 | end |
206 | | - |
| 206 | + |
207 | 207 | it "should accept known fields" do |
208 | 208 | email = AuthorizeNet::EmailReceipt.new(:header => '123') |
209 | 209 | hash = email.to_hash |
210 | 210 | hash.should be_kind_of(Hash) |
211 | 211 | hash.should == {:header => '123'} |
212 | 212 | end |
213 | 213 | end |
| 214 | + |
| 215 | +describe AuthorizeNet::TypeConversions do |
| 216 | + |
| 217 | + subject do |
| 218 | + Object.new.extend(described_class) |
| 219 | + end |
| 220 | + |
| 221 | + it 'should convert decimal strings' do |
| 222 | + subject.value_to_decimal('1.2345').should == BigDecimal.new('1.2345') |
| 223 | + end |
| 224 | + |
| 225 | + it 'should convert empty decimal strings' do |
| 226 | + subject.value_to_decimal('').should == BigDecimal.new('0.0') |
| 227 | + end |
| 228 | +end |
0 commit comments