activemerchant 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +9 -0
  3. data/MIT-LICENSE +1 -1
  4. data/lib/active_merchant.rb +6 -26
  5. data/lib/active_merchant/billing.rb +9 -0
  6. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +12 -1
  7. data/lib/active_merchant/billing/gateways/skip_jack.rb +2 -1
  8. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +40 -1
  9. data/lib/active_merchant/billing/integrations/two_checkout.rb +1 -1
  10. metadata +9 -173
  11. metadata.gz.sig +0 -0
  12. data/Rakefile +0 -153
  13. data/init.rb +0 -3
  14. data/script/destroy +0 -14
  15. data/script/generate +0 -14
  16. data/test/fixtures.yml +0 -355
  17. data/test/remote/gateways/remote_authorize_net_cim_test.rb +0 -460
  18. data/test/remote/gateways/remote_authorize_net_test.rb +0 -145
  19. data/test/remote/gateways/remote_beanstream_interac_test.rb +0 -53
  20. data/test/remote/gateways/remote_beanstream_test.rb +0 -150
  21. data/test/remote/gateways/remote_braintree_test.rb +0 -147
  22. data/test/remote/gateways/remote_card_stream_test.rb +0 -148
  23. data/test/remote/gateways/remote_cyber_source_test.rb +0 -144
  24. data/test/remote/gateways/remote_data_cash_test.rb +0 -356
  25. data/test/remote/gateways/remote_efsnet_test.rb +0 -81
  26. data/test/remote/gateways/remote_elavon_test.rb +0 -66
  27. data/test/remote/gateways/remote_eway_test.rb +0 -74
  28. data/test/remote/gateways/remote_exact_test.rb +0 -60
  29. data/test/remote/gateways/remote_first_pay_test.rb +0 -87
  30. data/test/remote/gateways/remote_instapay_test.rb +0 -61
  31. data/test/remote/gateways/remote_jetpay_test.rb +0 -103
  32. data/test/remote/gateways/remote_linkpoint_test.rb +0 -121
  33. data/test/remote/gateways/remote_merchant_e_solutions_test.rb +0 -173
  34. data/test/remote/gateways/remote_merchant_ware_test.rb +0 -113
  35. data/test/remote/gateways/remote_modern_payments_cim_test.rb +0 -58
  36. data/test/remote/gateways/remote_modern_payments_test.rb +0 -57
  37. data/test/remote/gateways/remote_moneris_test.rb +0 -82
  38. data/test/remote/gateways/remote_net_registry_test.rb +0 -85
  39. data/test/remote/gateways/remote_netbilling_test.rb +0 -70
  40. data/test/remote/gateways/remote_ogone_test.rb +0 -115
  41. data/test/remote/gateways/remote_pay_junction_test.rb +0 -143
  42. data/test/remote/gateways/remote_pay_secure_test.rb +0 -39
  43. data/test/remote/gateways/remote_payflow_express_test.rb +0 -50
  44. data/test/remote/gateways/remote_payflow_test.rb +0 -237
  45. data/test/remote/gateways/remote_payflow_uk_test.rb +0 -173
  46. data/test/remote/gateways/remote_payment_express_test.rb +0 -136
  47. data/test/remote/gateways/remote_paypal_express_test.rb +0 -49
  48. data/test/remote/gateways/remote_paypal_test.rb +0 -191
  49. data/test/remote/gateways/remote_plugnpay_test.rb +0 -72
  50. data/test/remote/gateways/remote_psigate_test.rb +0 -50
  51. data/test/remote/gateways/remote_psl_card_test.rb +0 -123
  52. data/test/remote/gateways/remote_quickpay_test.rb +0 -190
  53. data/test/remote/gateways/remote_realex_test.rb +0 -224
  54. data/test/remote/gateways/remote_sage_bankcard_test.rb +0 -109
  55. data/test/remote/gateways/remote_sage_pay_test.rb +0 -219
  56. data/test/remote/gateways/remote_sage_test.rb +0 -87
  57. data/test/remote/gateways/remote_sage_virtual_check_test.rb +0 -62
  58. data/test/remote/gateways/remote_sallie_mae_test.rb +0 -51
  59. data/test/remote/gateways/remote_secure_pay_au_test.rb +0 -40
  60. data/test/remote/gateways/remote_secure_pay_tech_test.rb +0 -37
  61. data/test/remote/gateways/remote_secure_pay_test.rb +0 -28
  62. data/test/remote/gateways/remote_skipjack_test.rb +0 -105
  63. data/test/remote/gateways/remote_trans_first_test.rb +0 -34
  64. data/test/remote/gateways/remote_transax_test.rb +0 -112
  65. data/test/remote/gateways/remote_trust_commerce_test.rb +0 -152
  66. data/test/remote/gateways/remote_usa_epay_test.rb +0 -46
  67. data/test/remote/gateways/remote_verifi_test.rb +0 -107
  68. data/test/remote/gateways/remote_viaklix_test.rb +0 -43
  69. data/test/remote/gateways/remote_wirecard_test.rb +0 -111
  70. data/test/remote/integrations/remote_gestpay_integration_test.rb +0 -37
  71. data/test/remote/integrations/remote_paypal_integration_test.rb +0 -26
  72. data/test/test_helper.rb +0 -184
  73. data/test/unit/avs_result_test.rb +0 -59
  74. data/test/unit/base_test.rb +0 -54
  75. data/test/unit/check_test.rb +0 -88
  76. data/test/unit/connection_test.rb +0 -129
  77. data/test/unit/country_code_test.rb +0 -33
  78. data/test/unit/country_test.rb +0 -64
  79. data/test/unit/credit_card_formatting_test.rb +0 -19
  80. data/test/unit/credit_card_methods_test.rb +0 -179
  81. data/test/unit/credit_card_test.rb +0 -318
  82. data/test/unit/cvv_result_test.rb +0 -33
  83. data/test/unit/expiry_date_test.rb +0 -32
  84. data/test/unit/gateways/authorize_net_cim_test.rb +0 -676
  85. data/test/unit/gateways/authorize_net_test.rb +0 -290
  86. data/test/unit/gateways/beanstream_interac_test.rb +0 -51
  87. data/test/unit/gateways/beanstream_test.rb +0 -108
  88. data/test/unit/gateways/bogus_test.rb +0 -46
  89. data/test/unit/gateways/braintree_test.rb +0 -118
  90. data/test/unit/gateways/card_stream_test.rb +0 -90
  91. data/test/unit/gateways/cyber_source_test.rb +0 -188
  92. data/test/unit/gateways/data_cash_test.rb +0 -133
  93. data/test/unit/gateways/efsnet_test.rb +0 -123
  94. data/test/unit/gateways/elavon_test.rb +0 -139
  95. data/test/unit/gateways/eway_test.rb +0 -118
  96. data/test/unit/gateways/exact_test.rb +0 -156
  97. data/test/unit/gateways/first_pay_test.rb +0 -125
  98. data/test/unit/gateways/gateway_test.rb +0 -48
  99. data/test/unit/gateways/instapay_test.rb +0 -102
  100. data/test/unit/gateways/jetpay_test.rb +0 -185
  101. data/test/unit/gateways/linkpoint_test.rb +0 -197
  102. data/test/unit/gateways/merchant_e_solutions_test.rb +0 -169
  103. data/test/unit/gateways/merchant_ware_test.rb +0 -188
  104. data/test/unit/gateways/modern_payments_cim_test.rb +0 -162
  105. data/test/unit/gateways/moneris_test.rb +0 -158
  106. data/test/unit/gateways/net_registry_test.rb +0 -416
  107. data/test/unit/gateways/netbilling_test.rb +0 -54
  108. data/test/unit/gateways/ogone_test.rb +0 -319
  109. data/test/unit/gateways/pay_junction_test.rb +0 -123
  110. data/test/unit/gateways/pay_secure_test.rb +0 -71
  111. data/test/unit/gateways/payflow_express_test.rb +0 -173
  112. data/test/unit/gateways/payflow_express_uk_test.rb +0 -86
  113. data/test/unit/gateways/payflow_test.rb +0 -305
  114. data/test/unit/gateways/payflow_uk_test.rb +0 -30
  115. data/test/unit/gateways/payment_express_test.rb +0 -195
  116. data/test/unit/gateways/paypal_express_test.rb +0 -382
  117. data/test/unit/gateways/paypal_test.rb +0 -569
  118. data/test/unit/gateways/plugnpay_test.rb +0 -86
  119. data/test/unit/gateways/psigate_test.rb +0 -169
  120. data/test/unit/gateways/psl_card_test.rb +0 -64
  121. data/test/unit/gateways/quickpay_test.rb +0 -112
  122. data/test/unit/gateways/realex_test.rb +0 -151
  123. data/test/unit/gateways/sage_bankcard_test.rb +0 -196
  124. data/test/unit/gateways/sage_pay_test.rb +0 -139
  125. data/test/unit/gateways/sage_virtual_check_test.rb +0 -71
  126. data/test/unit/gateways/sallie_mae_test.rb +0 -53
  127. data/test/unit/gateways/secure_pay_au_test.rb +0 -207
  128. data/test/unit/gateways/secure_pay_tech_test.rb +0 -44
  129. data/test/unit/gateways/secure_pay_test.rb +0 -101
  130. data/test/unit/gateways/skip_jack_test.rb +0 -213
  131. data/test/unit/gateways/trans_first_test.rb +0 -112
  132. data/test/unit/gateways/trust_commerce_test.rb +0 -90
  133. data/test/unit/gateways/usa_epay_test.rb +0 -128
  134. data/test/unit/gateways/verifi_test.rb +0 -96
  135. data/test/unit/gateways/viaklix_test.rb +0 -78
  136. data/test/unit/gateways/wirecard_test.rb +0 -250
  137. data/test/unit/generators/test_gateway_generator.rb +0 -46
  138. data/test/unit/generators/test_generator_helper.rb +0 -20
  139. data/test/unit/generators/test_integration_generator.rb +0 -53
  140. data/test/unit/integrations/action_view_helper_test.rb +0 -50
  141. data/test/unit/integrations/bogus_module_test.rb +0 -20
  142. data/test/unit/integrations/chronopay_module_test.rb +0 -13
  143. data/test/unit/integrations/gestpay_module_test.rb +0 -14
  144. data/test/unit/integrations/helpers/bogus_helper_test.rb +0 -28
  145. data/test/unit/integrations/helpers/chronopay_helper_test.rb +0 -67
  146. data/test/unit/integrations/helpers/gestpay_helper_test.rb +0 -100
  147. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +0 -16
  148. data/test/unit/integrations/helpers/nochex_helper_test.rb +0 -53
  149. data/test/unit/integrations/helpers/paypal_helper_test.rb +0 -171
  150. data/test/unit/integrations/helpers/quickpay_helper_test.rb +0 -40
  151. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +0 -92
  152. data/test/unit/integrations/hi_trust_module_test.rb +0 -13
  153. data/test/unit/integrations/nochex_module_test.rb +0 -13
  154. data/test/unit/integrations/notifications/chronopay_notification_test.rb +0 -66
  155. data/test/unit/integrations/notifications/gestpay_notification_test.rb +0 -60
  156. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +0 -59
  157. data/test/unit/integrations/notifications/nochex_notification_test.rb +0 -51
  158. data/test/unit/integrations/notifications/notification_test.rb +0 -54
  159. data/test/unit/integrations/notifications/paypal_notification_test.rb +0 -85
  160. data/test/unit/integrations/notifications/quickpay_notification_test.rb +0 -69
  161. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +0 -55
  162. data/test/unit/integrations/paypal_module_test.rb +0 -28
  163. data/test/unit/integrations/quickpay_module_test.rb +0 -9
  164. data/test/unit/integrations/returns/chronopay_return_test.rb +0 -11
  165. data/test/unit/integrations/returns/gestpay_return_test.rb +0 -10
  166. data/test/unit/integrations/returns/hi_trust_return_test.rb +0 -24
  167. data/test/unit/integrations/returns/nochex_return_test.rb +0 -10
  168. data/test/unit/integrations/returns/paypal_return_test.rb +0 -10
  169. data/test/unit/integrations/returns/return_test.rb +0 -11
  170. data/test/unit/integrations/returns/two_checkout_return_test.rb +0 -24
  171. data/test/unit/integrations/two_checkout_module_test.rb +0 -13
  172. data/test/unit/post_data_test.rb +0 -55
  173. data/test/unit/posts_data_test.rb +0 -48
  174. data/test/unit/response_test.rb +0 -28
  175. data/test/unit/utils_test.rb +0 -7
  176. data/test/unit/validateable_test.rb +0 -60
@@ -1,179 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CreditCardMethodsTest < Test::Unit::TestCase
4
- include ActiveMerchant::Billing::CreditCardMethods
5
-
6
- class CreditCard
7
- include ActiveMerchant::Billing::CreditCardMethods
8
- end
9
-
10
- def maestro_card_numbers
11
- %w[
12
- 5000000000000000 5099999999999999 5600000000000000
13
- 5899999999999999 6000000000000000 6999999999999999
14
- ]
15
- end
16
-
17
- def non_maestro_card_numbers
18
- %w[
19
- 4999999999999999 5100000000000000 5599999999999999
20
- 5900000000000000 5999999999999999 7000000000000000
21
- ]
22
- end
23
-
24
- def test_should_be_able_to_identify_valid_expiry_months
25
- assert_false valid_month?(-1)
26
- assert_false valid_month?(13)
27
- assert_false valid_month?(nil)
28
- assert_false valid_month?('')
29
-
30
- 1.upto(12) { |m| assert valid_month?(m) }
31
- end
32
-
33
- def test_should_be_able_to_identify_valid_expiry_years
34
- assert_false valid_expiry_year?(-1)
35
- assert_false valid_expiry_year?(Time.now.year + 21)
36
-
37
- 0.upto(20) { |n| assert valid_expiry_year?(Time.now.year + n) }
38
- end
39
-
40
- def test_should_be_able_to_identify_valid_start_years
41
- assert valid_start_year?(1988)
42
- assert valid_start_year?(2007)
43
- assert valid_start_year?(3000)
44
-
45
- assert_false valid_start_year?(1987)
46
- end
47
-
48
- def test_should_be_able_to_identify_valid_issue_numbers
49
- assert valid_issue_number?(1)
50
- assert valid_issue_number?(10)
51
- assert valid_issue_number?('12')
52
- assert valid_issue_number?(0)
53
-
54
- assert_false valid_issue_number?(-1)
55
- assert_false valid_issue_number?(123)
56
- assert_false valid_issue_number?('CAT')
57
- end
58
-
59
- def test_should_ensure_type_from_credit_card_class_is_not_frozen
60
- assert_false CreditCard.type?('4242424242424242').frozen?
61
- end
62
-
63
- def test_should_be_dankort_card_type
64
- assert_equal 'dankort', CreditCard.type?('5019717010103742')
65
- end
66
-
67
- def test_should_detect_visa_dankort_as_visa
68
- assert_equal 'visa', CreditCard.type?('4571100000000000')
69
- end
70
-
71
- def test_should_detect_electron_dk_as_visa
72
- assert_equal 'visa', CreditCard.type?('4175001000000000')
73
- end
74
-
75
- def test_should_detect_diners_club
76
- assert_equal 'diners_club', CreditCard.type?('36148010000000')
77
- end
78
-
79
- def test_should_detect_diners_club_dk
80
- assert_equal 'diners_club', CreditCard.type?('30401000000000')
81
- end
82
-
83
- def test_should_detect_maestro_dk_as_maestro
84
- assert_equal 'maestro', CreditCard.type?('6769271000000000')
85
- end
86
-
87
- def test_should_detect_maestro_cards
88
- assert_equal 'maestro', CreditCard.type?('5020100000000000')
89
-
90
- maestro_card_numbers.each { |number| assert_equal 'maestro', CreditCard.type?(number) }
91
- non_maestro_card_numbers.each { |number| assert_not_equal 'maestro', CreditCard.type?(number) }
92
- end
93
-
94
- def test_should_detect_mastercard
95
- assert_equal 'master', CreditCard.type?('6771890000000000')
96
- assert_equal 'master', CreditCard.type?('5413031000000000')
97
- end
98
-
99
- def test_should_detect_forbrugsforeningen
100
- assert_equal 'forbrugsforeningen', CreditCard.type?('6007221000000000')
101
- end
102
-
103
- def test_should_detect_laser_card
104
- # 16 digits
105
- assert_equal 'laser', CreditCard.type?('6304985028090561')
106
-
107
- # 18 digits
108
- assert_equal 'laser', CreditCard.type?('630498502809056151')
109
-
110
- # 19 digits
111
- assert_equal 'laser', CreditCard.type?('6304985028090561515')
112
-
113
- # 17 digits
114
- assert_not_equal 'laser', CreditCard.type?('63049850280905615')
115
-
116
- # 15 digits
117
- assert_not_equal 'laser', CreditCard.type?('630498502809056')
118
-
119
- # Alternate format
120
- assert_equal 'laser', CreditCard.type?('6706950000000000000')
121
-
122
- # Alternate format (16 digits)
123
- assert_equal 'laser', CreditCard.type?('6706123456789012')
124
-
125
- # New format (16 digits)
126
- assert_equal 'laser', CreditCard.type?('6709123456789012')
127
-
128
- # Ulster bank (Ireland) with 12 digits
129
- assert_equal 'laser', CreditCard.type?('677117111234')
130
- end
131
-
132
- def test_should_detect_when_an_argument_type_does_not_match_calculated_type
133
- assert CreditCard.matching_type?('4175001000000000', 'visa')
134
- assert_false CreditCard.matching_type?('4175001000000000', 'master')
135
- end
136
-
137
- def test_detecting_full_range_of_maestro_card_numbers
138
- maestro = '50000000000'
139
-
140
- assert_equal 11, maestro.length
141
- assert_not_equal 'maestro', CreditCard.type?(maestro)
142
-
143
- while maestro.length < 19
144
- maestro << '0'
145
- assert_equal 'maestro', CreditCard.type?(maestro)
146
- end
147
-
148
- assert_equal 19, maestro.length
149
-
150
- maestro << '0'
151
- assert_not_equal 'maestro', CreditCard.type?(maestro)
152
- end
153
-
154
- def test_matching_discover_card
155
- assert CreditCard.matching_type?('6011000000000000', 'discover')
156
- assert CreditCard.matching_type?('6500000000000000', 'discover')
157
-
158
- assert_false CreditCard.matching_type?('6010000000000000', 'discover')
159
- assert_false CreditCard.matching_type?('6600000000000000', 'discover')
160
- end
161
-
162
- def test_16_digit_maestro_uk
163
- number = '6759000000000000'
164
- assert_equal 16, number.length
165
- assert_equal 'switch', CreditCard.type?(number)
166
- end
167
-
168
- def test_18_digit_maestro_uk
169
- number = '675900000000000000'
170
- assert_equal 18, number.length
171
- assert_equal 'switch', CreditCard.type?(number)
172
- end
173
-
174
- def test_19_digit_maestro_uk
175
- number = '6759000000000000000'
176
- assert_equal 19, number.length
177
- assert_equal 'switch', CreditCard.type?(number)
178
- end
179
- end
@@ -1,318 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CreditCardTest < Test::Unit::TestCase
4
- def setup
5
- CreditCard.require_verification_value = false
6
- @visa = credit_card("4779139500118580", :type => "visa")
7
- @solo = credit_card("676700000000000000", :type => "solo", :issue_number => '01')
8
- end
9
-
10
- def teardown
11
- CreditCard.require_verification_value = false
12
- end
13
-
14
- def test_constructor_should_properly_assign_values
15
- c = credit_card
16
-
17
- assert_equal "4242424242424242", c.number
18
- assert_equal 9, c.month
19
- assert_equal Time.now.year + 1, c.year
20
- assert_equal "Longbob Longsen", c.name
21
- assert_equal "visa", c.type
22
- assert_valid c
23
- end
24
-
25
- def test_new_credit_card_should_not_be_valid
26
- c = CreditCard.new
27
-
28
- assert_not_valid c
29
- assert_false c.errors.empty?
30
- end
31
-
32
- def test_should_be_a_valid_visa_card
33
- assert_valid @visa
34
- assert @visa.errors.empty?
35
- end
36
-
37
- def test_should_be_a_valid_solo_card
38
- assert_valid @solo
39
- assert @solo.errors.empty?
40
- end
41
-
42
- def test_cards_with_empty_names_should_not_be_valid
43
- @visa.first_name = ''
44
- @visa.last_name = ''
45
-
46
- assert_not_valid @visa
47
- assert_false @visa.errors.empty?
48
- end
49
-
50
- def test_should_be_able_to_access_errors_indifferently
51
- @visa.first_name = ''
52
-
53
- assert_not_valid @visa
54
- assert @visa.errors.on(:first_name)
55
- assert @visa.errors.on("first_name")
56
- end
57
-
58
- def test_should_be_able_to_liberate_a_bogus_card
59
- c = credit_card('', :type => 'bogus')
60
- assert_valid c
61
-
62
- c.type = 'visa'
63
- assert_not_valid c
64
- end
65
-
66
- def test_should_be_able_to_identify_invalid_card_numbers
67
- @visa.number = nil
68
- assert_not_valid @visa
69
-
70
- @visa.number = "11112222333344ff"
71
- assert_not_valid @visa
72
- assert_false @visa.errors.on(:type)
73
- assert @visa.errors.on(:number)
74
-
75
- @visa.number = "111122223333444"
76
- assert_not_valid @visa
77
- assert_false @visa.errors.on(:type)
78
- assert @visa.errors.on(:number)
79
-
80
- @visa.number = "11112222333344444"
81
- assert_not_valid @visa
82
- assert_false @visa.errors.on(:type)
83
- assert @visa.errors.on(:number)
84
- end
85
-
86
- def test_should_have_errors_with_invalid_card_type_for_otherwise_correct_number
87
- @visa.type = 'master'
88
-
89
- assert_not_valid @visa
90
- assert_not_equal @visa.errors.on(:number), @visa.errors.on(:type)
91
- end
92
-
93
- def test_should_be_invalid_when_type_cannot_be_detected
94
- @visa.number = nil
95
- @visa.type = nil
96
-
97
- assert_not_valid @visa
98
- assert_match /is required/, @visa.errors.on(:type)
99
- assert @visa.errors.on(:type)
100
- end
101
-
102
- def test_should_be_a_valid_card_number
103
- @visa.number = "4242424242424242"
104
-
105
- assert_valid @visa
106
- end
107
-
108
- def test_should_require_a_valid_card_month
109
- @visa.month = Time.now.month
110
- @visa.year = Time.now.year
111
-
112
- assert_valid @visa
113
- end
114
-
115
- def test_should_not_be_valid_with_empty_month
116
- @visa.month = ''
117
-
118
- assert_not_valid @visa
119
- assert @visa.errors.on('month')
120
- end
121
-
122
- def test_should_not_be_valid_for_edge_month_cases
123
- @visa.month = 13
124
- @visa.year = Time.now.year
125
- assert_not_valid @visa
126
- assert @visa.errors.on('month')
127
-
128
- @visa.month = 0
129
- @visa.year = Time.now.year
130
- assert_not_valid @visa
131
- assert @visa.errors.on('month')
132
- end
133
-
134
- def test_should_be_invalid_with_empty_year
135
- @visa.year = ''
136
- assert_not_valid @visa
137
- assert @visa.errors.on('year')
138
- end
139
-
140
- def test_should_not_be_valid_for_edge_year_cases
141
- @visa.year = Time.now.year - 1
142
- assert_not_valid @visa
143
- assert @visa.errors.on('year')
144
-
145
- @visa.year = Time.now.year + 21
146
- assert_not_valid @visa
147
- assert @visa.errors.on('year')
148
- end
149
-
150
- def test_should_be_a_valid_future_year
151
- @visa.year = Time.now.year + 1
152
- assert_valid @visa
153
- end
154
-
155
-
156
- def test_should_be_valid_with_start_month_and_year_as_string
157
- @solo.start_month = '2'
158
- @solo.start_year = '2007'
159
- assert_valid @solo
160
- end
161
-
162
- def test_should_identify_wrong_cardtype
163
- c = credit_card(:type => 'master')
164
- assert_not_valid c
165
- end
166
-
167
- def test_should_display_number
168
- assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1111222233331234').display_number
169
- assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '111222233331234').display_number
170
- assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1112223331234').display_number
171
-
172
- assert_equal 'XXXX-XXXX-XXXX-', CreditCard.new(:number => nil).display_number
173
- assert_equal 'XXXX-XXXX-XXXX-', CreditCard.new(:number => '').display_number
174
- assert_equal 'XXXX-XXXX-XXXX-123', CreditCard.new(:number => '123').display_number
175
- assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1234').display_number
176
- assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '01234').display_number
177
- end
178
-
179
- def test_should_correctly_identify_card_type
180
- assert_equal 'visa', CreditCard.type?('4242424242424242')
181
- assert_equal 'american_express', CreditCard.type?('341111111111111')
182
- assert_nil CreditCard.type?('')
183
- end
184
-
185
- def test_should_be_able_to_require_a_verification_value
186
- CreditCard.require_verification_value = true
187
- assert CreditCard.requires_verification_value?
188
- end
189
-
190
- def test_should_not_be_valid_when_requiring_a_verification_value
191
- CreditCard.require_verification_value = true
192
- card = credit_card('4242424242424242', :verification_value => nil)
193
- assert_not_valid card
194
-
195
- card.verification_value = '123'
196
- assert_valid card
197
- end
198
-
199
- def test_should_require_valid_start_date_for_solo_or_switch
200
- @solo.start_month = nil
201
- @solo.start_year = nil
202
- @solo.issue_number = nil
203
-
204
- assert_not_valid @solo
205
- assert @solo.errors.on('start_month')
206
- assert @solo.errors.on('start_year')
207
- assert @solo.errors.on('issue_number')
208
-
209
- @solo.start_month = 2
210
- @solo.start_year = 2007
211
- assert_valid @solo
212
- end
213
-
214
- def test_should_require_a_valid_issue_number_for_solo_or_switch
215
- @solo.start_month = nil
216
- @solo.start_year = 2005
217
- @solo.issue_number = nil
218
-
219
- assert_not_valid @solo
220
- assert @solo.errors.on('start_month')
221
- assert @solo.errors.on('issue_number')
222
-
223
- @solo.issue_number = 3
224
- assert_valid @solo
225
- end
226
-
227
- def test_should_return_last_four_digits_of_card_number
228
- ccn = CreditCard.new(:number => "4779139500118580")
229
- assert_equal "8580", ccn.last_digits
230
- end
231
-
232
- def test_bogus_last_digits
233
- ccn = CreditCard.new(:number => "1")
234
- assert_equal "1", ccn.last_digits
235
- end
236
-
237
- def test_should_be_true_when_credit_card_has_a_first_name
238
- c = CreditCard.new
239
- assert_false c.first_name?
240
-
241
- c = CreditCard.new(:first_name => 'James')
242
- assert c.first_name?
243
- end
244
-
245
- def test_should_be_true_when_credit_card_has_a_last_name
246
- c = CreditCard.new
247
- assert_false c.last_name?
248
-
249
- c = CreditCard.new(:last_name => 'Herdman')
250
- assert c.last_name?
251
- end
252
-
253
- def test_should_test_for_a_full_name
254
- c = CreditCard.new
255
- assert_false c.name?
256
-
257
- c = CreditCard.new(:first_name => 'James', :last_name => 'Herdman')
258
- assert c.name?
259
- end
260
-
261
- # The following is a regression for a bug that raised an exception when
262
- # a new credit card was validated
263
- def test_validate_new_card
264
- credit_card = CreditCard.new
265
-
266
- assert_nothing_raised do
267
- credit_card.validate
268
- end
269
- end
270
-
271
- # The following is a regression for a bug where the keys of the
272
- # credit card card_companies hash were not duped when detecting the type
273
- def test_create_and_validate_credit_card_from_type
274
- credit_card = CreditCard.new(:type => CreditCard.type?('4242424242424242'))
275
- assert_nothing_raised do
276
- credit_card.valid?
277
- end
278
- end
279
-
280
- def test_autodetection_of_credit_card_type
281
- credit_card = CreditCard.new(:number => '4242424242424242')
282
- credit_card.valid?
283
- assert_equal 'visa', credit_card.type
284
- end
285
-
286
- def test_card_type_should_not_be_autodetected_when_provided
287
- credit_card = CreditCard.new(:number => '4242424242424242', :type => 'master')
288
- credit_card.valid?
289
- assert_equal 'master', credit_card.type
290
- end
291
-
292
- def test_detecting_bogus_card
293
- credit_card = CreditCard.new(:number => '1')
294
- credit_card.valid?
295
- assert_equal 'bogus', credit_card.type
296
- end
297
-
298
- def test_validating_bogus_card
299
- credit_card = credit_card('1', :type => nil)
300
- assert credit_card.valid?
301
- end
302
-
303
- def test_mask_number
304
- assert_equal 'XXXX-XXXX-XXXX-5100', CreditCard.mask('5105105105105100')
305
- end
306
-
307
- def test_strip_non_digit_characters
308
- card = credit_card('4242-4242 %%%%%%4242......4242')
309
- assert card.valid?
310
- assert_equal "4242424242424242", card.number
311
- end
312
-
313
- def test_before_validate_handles_blank_number
314
- card = credit_card(nil)
315
- assert !card.valid?
316
- assert_equal "", card.number
317
- end
318
- end