global_collect 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +11 -0
- data/README.markdown +109 -0
- data/Rakefile +34 -0
- data/VERSION +1 -0
- data/examples/cancel_payment.rb +14 -0
- data/examples/convert_amount.rb +14 -0
- data/examples/get_order_status.rb +15 -0
- data/examples/insert_order_with_payment.rb +37 -0
- data/examples/process_challenged.rb +13 -0
- data/examples/set_payment.rb +23 -0
- data/examples/test_connection.rb +13 -0
- data/global_collect.gemspec +170 -0
- data/lib/global_collect/api_client.rb +71 -0
- data/lib/global_collect/builders/do_refund/credit_card_payment.rb +12 -0
- data/lib/global_collect/builders/do_refund/payment.rb +39 -0
- data/lib/global_collect/builders/insert_order_with_payment/credit_card_online_payment.rb +38 -0
- data/lib/global_collect/builders/insert_order_with_payment/hosted_credit_card_online_payment.rb +4 -0
- data/lib/global_collect/builders/insert_order_with_payment/order.rb +75 -0
- data/lib/global_collect/builders/insert_order_with_payment/payment.rb +25 -0
- data/lib/global_collect/builders/set_payment/payment.rb +23 -0
- data/lib/global_collect/const/payment_product.rb +38 -0
- data/lib/global_collect/const/payment_status.rb +90 -0
- data/lib/global_collect/field_validator.rb +47 -0
- data/lib/global_collect/request_models/base.rb +37 -0
- data/lib/global_collect/request_models/do_refund/credit_card_payment.rb +12 -0
- data/lib/global_collect/request_models/do_refund/payment.rb +39 -0
- data/lib/global_collect/request_models/insert_order_with_payment/credit_card_online_payment.rb +44 -0
- data/lib/global_collect/request_models/insert_order_with_payment/hosted_credit_card_online_payment.rb +19 -0
- data/lib/global_collect/request_models/insert_order_with_payment/order.rb +67 -0
- data/lib/global_collect/request_models/insert_order_with_payment/payment.rb +17 -0
- data/lib/global_collect/request_models/set_payment/payment.rb +17 -0
- data/lib/global_collect/requests/base.rb +43 -0
- data/lib/global_collect/requests/cancel_payment.rb +22 -0
- data/lib/global_collect/requests/composite.rb +23 -0
- data/lib/global_collect/requests/convert_amount.rb +29 -0
- data/lib/global_collect/requests/do_refund.rb +8 -0
- data/lib/global_collect/requests/get_order_status.rb +24 -0
- data/lib/global_collect/requests/insert_order_with_payment.rb +10 -0
- data/lib/global_collect/requests/process_challenged.rb +22 -0
- data/lib/global_collect/requests/set_payment.rb +9 -0
- data/lib/global_collect/requests/simple.rb +39 -0
- data/lib/global_collect/requests/test_connection.rb +8 -0
- data/lib/global_collect/responses/base.rb +73 -0
- data/lib/global_collect/responses/convert_amount/response_methods.rb +8 -0
- data/lib/global_collect/responses/do_refund/response_methods.rb +24 -0
- data/lib/global_collect/responses/get_order_status/v1_response_methods.rb +49 -0
- data/lib/global_collect/responses/get_order_status/v2_response_methods.rb +67 -0
- data/lib/global_collect/responses/insert_order_with_payment/credit_card_online_payment_response_methods.rb +31 -0
- data/lib/global_collect/responses/insert_order_with_payment/hosted_merchant_link_payment_response_methods.rb +16 -0
- data/lib/global_collect/responses/success_row.rb +15 -0
- data/lib/global_collect.rb +81 -0
- data/spec/api_client_spec.rb +93 -0
- data/spec/builders/do_refund/credit_card_payment_spec.rb +32 -0
- data/spec/builders/do_refund/payment_spec.rb +51 -0
- data/spec/builders/insert_order_with_payment/credit_card_online_payment_spec.rb +59 -0
- data/spec/builders/insert_order_with_payment/hosted_credit_card_online_payment_spec.rb +59 -0
- data/spec/builders/insert_order_with_payment/order_spec.rb +88 -0
- data/spec/builders/insert_order_with_payment/payment_spec.rb +37 -0
- data/spec/builders/set_payment/payment_spec.rb +35 -0
- data/spec/field_validator_spec.rb +79 -0
- data/spec/global_collect_spec.rb +43 -0
- data/spec/request_models/base_spec.rb +31 -0
- data/spec/request_models/insert_order_with_payment/credit_card_online_payment_spec.rb +11 -0
- data/spec/request_models/insert_order_with_payment/hosted_credit_card_online_payment_spec.rb +38 -0
- data/spec/requests/base_spec.rb +40 -0
- data/spec/requests/composite_spec.rb +48 -0
- data/spec/requests/convert_amount.rb +34 -0
- data/spec/requests/insert_order_with_payment_spec.rb +60 -0
- data/spec/requests/simple_spec.rb +37 -0
- data/spec/responses/base_spec.rb +59 -0
- data/spec/responses/convert_amount/response_methods_spec.rb +13 -0
- data/spec/responses/do_refund/response_methods_spec.rb +15 -0
- data/spec/responses/get_order_status/v1_response_methods_spec.rb +28 -0
- data/spec/responses/get_order_status/v2_response_methods_spec.rb +28 -0
- data/spec/responses/insert_order_with_payment/credit_card_online_payment_response_methods_spec.rb +13 -0
- data/spec/responses/insert_order_with_payment/hosted_merchant_link_payment_response_methods_spec.rb +13 -0
- data/spec/responses/succcess_row_spec.rb +26 -0
- data/spec/spec_helper.rb +130 -0
- data/spec/support/challenged_iowp_response.xml +51 -0
- data/spec/support/successful_convert_amount_response.xml +29 -0
- data/spec/support/successful_do_refund_response.xml +36 -0
- data/spec/support/successful_get_order_status_v1_response.xml +72 -0
- data/spec/support/successful_get_order_status_v2_response.xml +50 -0
- data/spec/support/successful_hosted_iowp_response.xml +60 -0
- data/spec/support/successful_iowp_response.xml +49 -0
- data/spec/support/successful_process_challenged_response.xml +26 -0
- data/spec/support/unsuccessful_do_refund_response.xml +29 -0
- data/spec/support/unsuccessful_iowp_response.xml +42 -0
- data/spec/support/unsuccessful_process_challenged_response.xml +30 -0
- metadata +213 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the DO_REFUND credit card payment builder" do
|
4
|
+
before(:each) do
|
5
|
+
@node = Builder::XmlMarkup.new
|
6
|
+
end
|
7
|
+
it "should not build unknown keys" do
|
8
|
+
@builder = GlobalCollect::Builders::DoRefund::CreditCardPayment.new('foo' => 'bar')
|
9
|
+
@builder.build(@node)
|
10
|
+
xml = @node.target!
|
11
|
+
|
12
|
+
xml.should have_xpath("/PAYMENT")
|
13
|
+
xml.should_not have_xpath("/PAYMENT/foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build cc-specific keys" do
|
17
|
+
fields = %w[
|
18
|
+
PAYMENTPRODUCTID
|
19
|
+
CREDITCARDNUMBER
|
20
|
+
EXPIRYDATE
|
21
|
+
]
|
22
|
+
@builder = GlobalCollect::Builders::DoRefund::CreditCardPayment.new(
|
23
|
+
fields.inject({}) {|m,k| m[k] = k; m }
|
24
|
+
)
|
25
|
+
@builder.build(@node)
|
26
|
+
xml = @node.target!
|
27
|
+
xml.should have_xpath("/PAYMENT")
|
28
|
+
fields.each do |field|
|
29
|
+
xml.should match_xpath("/PAYMENT/#{field}", field)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the DO_REFUND payment builder" do
|
4
|
+
before(:each) do
|
5
|
+
@node = Builder::XmlMarkup.new
|
6
|
+
end
|
7
|
+
it "should not build unknown keys" do
|
8
|
+
@builder = GlobalCollect::Builders::DoRefund::Payment.new('foo' => 'bar')
|
9
|
+
@builder.build(@node)
|
10
|
+
xml = @node.target!
|
11
|
+
|
12
|
+
xml.should have_xpath("/PAYMENT")
|
13
|
+
xml.should_not have_xpath("/PAYMENT/foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build known keys" do
|
17
|
+
fields = %w[
|
18
|
+
ORDERID
|
19
|
+
EFFORTID
|
20
|
+
MERCHANTREFERENCE
|
21
|
+
REFERENCEORIGPAYMENT
|
22
|
+
CURRENCYCODE
|
23
|
+
AMOUNT
|
24
|
+
COUNTRYCODE
|
25
|
+
REFUNDDATE
|
26
|
+
SURNAME
|
27
|
+
FIRSTNAME
|
28
|
+
PREFIXSURNAME
|
29
|
+
TITLE
|
30
|
+
COMPANYNAME
|
31
|
+
COMPANYDATA
|
32
|
+
STREET
|
33
|
+
HOUSENUMBER
|
34
|
+
ADDITIONALADDRESSINFO
|
35
|
+
ZIP
|
36
|
+
CITY
|
37
|
+
STATE
|
38
|
+
EMAILADDRESS
|
39
|
+
EMAILTYPEINDICATOR
|
40
|
+
]
|
41
|
+
@builder = GlobalCollect::Builders::DoRefund::Payment.new(
|
42
|
+
fields.inject({}) {|m,k| m[k] = k; m }
|
43
|
+
)
|
44
|
+
@builder.build(@node)
|
45
|
+
xml = @node.target!
|
46
|
+
xml.should have_xpath("/PAYMENT")
|
47
|
+
fields.each do |field|
|
48
|
+
xml.should match_xpath("/PAYMENT/#{field}", field)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the IOWP credit card online payment builder" do
|
4
|
+
before(:each) do
|
5
|
+
@node = Builder::XmlMarkup.new
|
6
|
+
end
|
7
|
+
it "should not build unknown keys" do
|
8
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::CreditCardOnlinePayment.new('foo' => 'bar')
|
9
|
+
@builder.build(@node)
|
10
|
+
xml = @node.target!
|
11
|
+
|
12
|
+
xml.should have_xpath("/PAYMENT")
|
13
|
+
xml.should_not have_xpath("/PAYMENT/foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build cc-specific keys" do
|
17
|
+
fields = %w[
|
18
|
+
EXPIRYDATE
|
19
|
+
CREDITCARDNUMBER
|
20
|
+
ISSUENUMBER
|
21
|
+
CVV
|
22
|
+
CVVINDICATOR
|
23
|
+
AVSINDICATOR
|
24
|
+
AUTHENTICATIONINDICATOR
|
25
|
+
STTINDICATOR
|
26
|
+
FIRSTNAME
|
27
|
+
PREFIXSURNAME
|
28
|
+
SURNAME
|
29
|
+
STREET
|
30
|
+
HOUSENUMBER
|
31
|
+
CUSTOMERIPADDRESS
|
32
|
+
ADDITIONALADDRESSINFO
|
33
|
+
ZIP
|
34
|
+
CITY
|
35
|
+
STATE
|
36
|
+
PHONENUMBER
|
37
|
+
EMAIL
|
38
|
+
BIRTHDATE
|
39
|
+
DCCINDICATOR
|
40
|
+
ISSUERAMOUNT
|
41
|
+
ISSUERCURRENCYCODE
|
42
|
+
MARGINRATEPERCENTAGE
|
43
|
+
EXCHANGERATESOURCENAME
|
44
|
+
EXCHANGERATE
|
45
|
+
EXCHANGERATEVALIDTO
|
46
|
+
MAC
|
47
|
+
]
|
48
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::CreditCardOnlinePayment.new(
|
49
|
+
fields.inject({}) {|m,k| m[k] = k; m }
|
50
|
+
)
|
51
|
+
@builder.build(@node)
|
52
|
+
xml = @node.target!
|
53
|
+
|
54
|
+
xml.should have_xpath("/PAYMENT")
|
55
|
+
fields.each do |field|
|
56
|
+
xml.should match_xpath("/PAYMENT/#{field}", field)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the hosted IOWP credit card online payment builder" do
|
4
|
+
before(:each) do
|
5
|
+
@node = Builder::XmlMarkup.new
|
6
|
+
end
|
7
|
+
it "should not build unknown keys" do
|
8
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::HostedCreditCardOnlinePayment.new('foo' => 'bar')
|
9
|
+
@builder.build(@node)
|
10
|
+
xml = @node.target!
|
11
|
+
|
12
|
+
xml.should have_xpath("/PAYMENT")
|
13
|
+
xml.should_not have_xpath("/PAYMENT/foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build hosted cc-specific keys" do
|
17
|
+
fields = %w[
|
18
|
+
EXPIRYDATE
|
19
|
+
CREDITCARDNUMBER
|
20
|
+
ISSUENUMBER
|
21
|
+
CVV
|
22
|
+
CVVINDICATOR
|
23
|
+
AVSINDICATOR
|
24
|
+
AUTHENTICATIONINDICATOR
|
25
|
+
STTINDICATOR
|
26
|
+
FIRSTNAME
|
27
|
+
PREFIXSURNAME
|
28
|
+
SURNAME
|
29
|
+
STREET
|
30
|
+
HOUSENUMBER
|
31
|
+
CUSTOMERIPADDRESS
|
32
|
+
ADDITIONALADDRESSINFO
|
33
|
+
ZIP
|
34
|
+
CITY
|
35
|
+
STATE
|
36
|
+
PHONENUMBER
|
37
|
+
EMAIL
|
38
|
+
BIRTHDATE
|
39
|
+
DCCINDICATOR
|
40
|
+
ISSUERAMOUNT
|
41
|
+
ISSUERCURRENCYCODE
|
42
|
+
MARGINRATEPERCENTAGE
|
43
|
+
EXCHANGERATESOURCENAME
|
44
|
+
EXCHANGERATE
|
45
|
+
EXCHANGERATEVALIDTO
|
46
|
+
MAC
|
47
|
+
]
|
48
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::HostedCreditCardOnlinePayment.new(
|
49
|
+
fields.inject({}) {|m,k| m[k] = k; m }
|
50
|
+
)
|
51
|
+
@builder.build(@node)
|
52
|
+
xml = @node.target!
|
53
|
+
|
54
|
+
xml.should have_xpath("/PAYMENT")
|
55
|
+
fields.each do |field|
|
56
|
+
xml.should match_xpath("/PAYMENT/#{field}", field)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the IOWP order builder" do
|
4
|
+
before(:each) do
|
5
|
+
@node = Builder::XmlMarkup.new
|
6
|
+
end
|
7
|
+
it "should not build unknown keys" do
|
8
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::Order.new('foo' => 'bar')
|
9
|
+
@builder.build(@node)
|
10
|
+
xml = @node.target!
|
11
|
+
|
12
|
+
xml.should have_xpath("/ORDER")
|
13
|
+
xml.should_not have_xpath("/ORDER/foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build known keys" do
|
17
|
+
fields = %w[
|
18
|
+
ORDERID
|
19
|
+
ORDERTYPE
|
20
|
+
AMOUNT
|
21
|
+
AMOUNTSIGN
|
22
|
+
CURRENCYCODE
|
23
|
+
LANGUAGECODE
|
24
|
+
COUNTRYCODE
|
25
|
+
OVERWRITEPAYMENTREFERNCE
|
26
|
+
IPADDRESSCUSTOMER
|
27
|
+
CUSTOMERID
|
28
|
+
MANDATE
|
29
|
+
TITLE
|
30
|
+
FIRSTNAME
|
31
|
+
PREFIXSURNAME
|
32
|
+
SURNAME
|
33
|
+
STREET
|
34
|
+
HOUSENUMBER
|
35
|
+
ADDITIONALADDRESSINFO
|
36
|
+
ZIP
|
37
|
+
CITY
|
38
|
+
STATE
|
39
|
+
SHIPPINGTITLE
|
40
|
+
SHIPPINGFIRSTNAME
|
41
|
+
SHIPPINGPREFIXSURNAME
|
42
|
+
SHIPPINGSURNAME
|
43
|
+
SHIPPINGSTREET
|
44
|
+
SHIPPINGHOUSENUMBER
|
45
|
+
SHIPPINGADDITIONALADDRESSINFO
|
46
|
+
SHIPPINGZIP
|
47
|
+
SHIPPINGCITY
|
48
|
+
SHIPPINGSTATE
|
49
|
+
SHIPPINGCOUNTRYCODE
|
50
|
+
MERCHANTREFERENCE
|
51
|
+
DESCRIPTOR
|
52
|
+
RESELLERID
|
53
|
+
EMAIL
|
54
|
+
EMAILTYPEINDICATOR
|
55
|
+
COMPANYNAME
|
56
|
+
COMPANYDATA
|
57
|
+
SEX
|
58
|
+
VATNUMBER
|
59
|
+
PHONENUMBER
|
60
|
+
FAXNUMBER
|
61
|
+
INVOICENUMBER
|
62
|
+
INVOICETYPE
|
63
|
+
INVOICEDATE
|
64
|
+
INVOICECLASS
|
65
|
+
ORDERDATE
|
66
|
+
BIRTHDATE
|
67
|
+
TEXTQUALIFIER1
|
68
|
+
TEXTQUALIFIER2
|
69
|
+
TEXTQUALIFIER3
|
70
|
+
ADDITIONALDATA
|
71
|
+
STARTDATE
|
72
|
+
ENDDATE
|
73
|
+
NUMBEROFPAYMENTS
|
74
|
+
STEPWEEK
|
75
|
+
STEPMONTH
|
76
|
+
]
|
77
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::Order.new(
|
78
|
+
Hash[*fields.zip(fields)]
|
79
|
+
)
|
80
|
+
@builder.build(@node)
|
81
|
+
xml = @node.target!
|
82
|
+
|
83
|
+
xml.should have_xpath("/ORDER")
|
84
|
+
fields.each do |field|
|
85
|
+
xml.should match_xpath("/ORDER/#{field}", field)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the IOWP payment builder" do
|
4
|
+
before(:each) do
|
5
|
+
@node = Builder::XmlMarkup.new
|
6
|
+
end
|
7
|
+
it "should not build unknown keys" do
|
8
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::Payment.new('foo' => 'bar')
|
9
|
+
@builder.build(@node)
|
10
|
+
xml = @node.target!
|
11
|
+
|
12
|
+
xml.should have_xpath("/PAYMENT")
|
13
|
+
xml.should_not have_xpath("/PAYMENT/foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build known keys" do
|
17
|
+
fields = %w[
|
18
|
+
PAYMENTPRODUCTID
|
19
|
+
AMOUNT
|
20
|
+
AMOUNTSIGN
|
21
|
+
CURRENCYCODE
|
22
|
+
LANGUAGECODE
|
23
|
+
COUNTRYCODE
|
24
|
+
HOSTEDINDICATOR
|
25
|
+
RETURNURL
|
26
|
+
]
|
27
|
+
@builder = GlobalCollect::Builders::InsertOrderWithPayment::Payment.new(
|
28
|
+
fields.inject({}) {|m,k| m[k] = k; m }
|
29
|
+
)
|
30
|
+
@builder.build(@node)
|
31
|
+
xml = @node.target!
|
32
|
+
xml.should have_xpath("/PAYMENT")
|
33
|
+
fields.each do |field|
|
34
|
+
xml.should match_xpath("/PAYMENT/#{field}", field)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the SET_PAYMENT payment builder" do
|
4
|
+
before(:each) do
|
5
|
+
@node = Builder::XmlMarkup.new
|
6
|
+
end
|
7
|
+
it "should not build unknown keys" do
|
8
|
+
@builder = GlobalCollect::Builders::SetPayment::Payment.new('foo' => 'bar')
|
9
|
+
@builder.build(@node)
|
10
|
+
xml = @node.target!
|
11
|
+
|
12
|
+
xml.should have_xpath("/PAYMENT")
|
13
|
+
xml.should_not have_xpath("/PAYMENT/foo")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build known keys" do
|
17
|
+
fields = %w[
|
18
|
+
ORDERID
|
19
|
+
EFFORTID
|
20
|
+
PAYMENTPRODUCTID
|
21
|
+
AMOUNT
|
22
|
+
CURRENCYCODE
|
23
|
+
DATECOLLECT
|
24
|
+
]
|
25
|
+
@builder = GlobalCollect::Builders::SetPayment::Payment.new(
|
26
|
+
fields.inject({}) {|m,k| m[k] = k; m }
|
27
|
+
)
|
28
|
+
@builder.build(@node)
|
29
|
+
xml = @node.target!
|
30
|
+
xml.should have_xpath("/PAYMENT")
|
31
|
+
fields.each do |field|
|
32
|
+
xml.should match_xpath("/PAYMENT/#{field}", field)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "the model validator" do
|
4
|
+
it "should accept nil when the field is not required" do
|
5
|
+
GlobalCollect::FieldValidator.new("D", "O").validate(nil).should be_true
|
6
|
+
GlobalCollect::FieldValidator.new("N1", "O").validate(nil).should be_true
|
7
|
+
GlobalCollect::FieldValidator.new("AN1", "O").validate(nil).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should validate good dates" do
|
11
|
+
validator = GlobalCollect::FieldValidator.new("D", "R")
|
12
|
+
validator.to_sym.should == :datetime
|
13
|
+
# random good dates from the spec
|
14
|
+
validator.validate("20070830120000").should be_true
|
15
|
+
validator.validate("20010101000000").should be_true
|
16
|
+
validator.validate("19990413012344").should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not validate bad dates" do
|
20
|
+
validator = GlobalCollect::FieldValidator.new("D", "R")
|
21
|
+
validator.to_sym.should == :datetime
|
22
|
+
# too short
|
23
|
+
validator.validate("1111").should be_false
|
24
|
+
# invalid second
|
25
|
+
validator.validate("20100101000099").should be_false
|
26
|
+
# invalid minute
|
27
|
+
validator.validate("20100101009900").should be_false
|
28
|
+
# invalid hour
|
29
|
+
validator.validate("20100101990000").should be_false
|
30
|
+
# invalid day
|
31
|
+
validator.validate("20100199000000").should be_false
|
32
|
+
# invalid month
|
33
|
+
validator.validate("20109901000000").should be_false
|
34
|
+
# bad prefix
|
35
|
+
validator.validate("a20100101123456").should be_false
|
36
|
+
# bad suffix
|
37
|
+
validator.validate("20100101123456a").should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should validate good alphanumerics" do
|
41
|
+
validator = GlobalCollect::FieldValidator.new("AN4", "R")
|
42
|
+
validator.to_sym.should == :alphanumeric
|
43
|
+
validator.validate("a1b2").should be_true
|
44
|
+
validator.validate("A1B2").should be_true
|
45
|
+
validator.validate("A1b2").should be_true
|
46
|
+
validator.validate("aaa").should be_true
|
47
|
+
validator.validate("111").should be_true
|
48
|
+
validator.validate("a b2").should be_true
|
49
|
+
validator.validate("A-B2").should be_true
|
50
|
+
validator.validate("A1b2").should be_true
|
51
|
+
validator.validate("").should be_true
|
52
|
+
validator.validate(" ").should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not validate bad alphanumerics" do
|
56
|
+
validator = GlobalCollect::FieldValidator.new("AN4", "R")
|
57
|
+
validator.to_sym.should == :alphanumeric
|
58
|
+
# too long
|
59
|
+
validator.validate("aaa213123123123").should be_false
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should validate good numerics" do
|
63
|
+
validator = GlobalCollect::FieldValidator.new("N4", "R")
|
64
|
+
validator.to_sym.should == :numeric
|
65
|
+
validator.validate("1").should be_true
|
66
|
+
validator.validate("12").should be_true
|
67
|
+
validator.validate("123").should be_true
|
68
|
+
validator.validate("1234").should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not validate bad numerics" do
|
72
|
+
validator = GlobalCollect::FieldValidator.new("N4", "R")
|
73
|
+
validator.to_sym.should == :numeric
|
74
|
+
validator.validate("").should be_false
|
75
|
+
validator.validate("a12").should be_false
|
76
|
+
validator.validate("a").should be_false
|
77
|
+
validator.validate(" ").should be_false
|
78
|
+
end
|
79
|
+
end
|