bank-validator 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bank-validator.gemspec +6 -3
- data/lib/active_model/bic_validator.rb +1 -1
- data/lib/active_model/iban_validator.rb +1 -1
- data/lib/active_model/routing_number_validator.rb +1 -1
- data/test/dummy/Gemfile.lock +1 -1
- data/test/dummy_classes.rb +3 -0
- data/test/dummy_classes/dummy_user.rb +38 -0
- data/test/dummy_classes/dummy_user2.rb +38 -0
- data/test/test_bank-validator.rb +28 -48
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a12a8cb39e85cd7d3095f4531e93280815e1c6ad
|
4
|
+
data.tar.gz: 696ef669eda1a6b45c321d8370ed271f40604ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bf523388656b2848daf70438f5be12aae3255a29f8ac84351545097408af1c03960f71cf83d2b01b7b24252d143b4153737b5ad88136d956f24dfc08b5d2965
|
7
|
+
data.tar.gz: 6ec35e9c6495af57215244c1c00d7924ad1cd5ae2bf7a0e944ac3bb388cc651db54803fbbf2c0df56bc508e233a128f1e15568d6516913de147abdff4d7eb6fc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/bank-validator.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: bank-validator 0.2.
|
5
|
+
# stub: bank-validator 0.2.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "bank-validator"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Adam Bahlke"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-04-01"
|
15
15
|
s.description = "Validates IBAN and BIC account numbers. Still a work in progress"
|
16
16
|
s.email = "adam.bahlke@hitfoxgroup.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -89,6 +89,9 @@ Gem::Specification.new do |s|
|
|
89
89
|
"test/dummy/spec/spec_helper.rb",
|
90
90
|
"test/dummy/vendor/assets/javascripts/.keep",
|
91
91
|
"test/dummy/vendor/assets/stylesheets/.keep",
|
92
|
+
"test/dummy_classes.rb",
|
93
|
+
"test/dummy_classes/dummy_user.rb",
|
94
|
+
"test/dummy_classes/dummy_user2.rb",
|
92
95
|
"test/helper.rb",
|
93
96
|
"test/test_bank-validator.rb"
|
94
97
|
]
|
@@ -9,7 +9,7 @@ class BicValidator < ActiveModel::EachValidator
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def record_error(record, attribute, value)
|
12
|
-
record.errors.add(attribute, (:
|
12
|
+
record.errors.add(attribute, (options[:message] || :invalid_bic))
|
13
13
|
end
|
14
14
|
|
15
15
|
def regexp
|
@@ -9,7 +9,7 @@ class IbanValidator < ActiveModel::EachValidator
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def record_error(record, attribute, value)
|
12
|
-
record.errors.add(attribute, (:invalid_iban || options[:message]))
|
12
|
+
record.errors.add(attribute, (options[:message] || :invalid_iban))# || options[:message]))
|
13
13
|
end
|
14
14
|
|
15
15
|
def regexp
|
@@ -9,7 +9,7 @@ class RoutingNumberValidator < ActiveModel::EachValidator
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def record_error(record, attribute, value)
|
12
|
-
record.errors.add(attribute, (:
|
12
|
+
record.errors.add(attribute, (options[:message] || :invalid_routing_number))
|
13
13
|
end
|
14
14
|
|
15
15
|
def regexp
|
data/test/dummy/Gemfile.lock
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
class DummyUser
|
2
|
+
include ActiveModel::Validations
|
3
|
+
validates :iban, iban: true
|
4
|
+
validates :bic, bic: true
|
5
|
+
validates :routing_number, routing_number: true
|
6
|
+
|
7
|
+
attr_accessor :iban
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@iban = attributes[:iban]
|
11
|
+
@bic = attributes[:bic]
|
12
|
+
@routing_number = attributes[:routing_number]
|
13
|
+
end
|
14
|
+
|
15
|
+
def save
|
16
|
+
if valid?
|
17
|
+
return true
|
18
|
+
else
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create(attributes = {})
|
24
|
+
new(attributes).save
|
25
|
+
end
|
26
|
+
|
27
|
+
def iban
|
28
|
+
@iban
|
29
|
+
end
|
30
|
+
|
31
|
+
def bic
|
32
|
+
@bic
|
33
|
+
end
|
34
|
+
|
35
|
+
def routing_number
|
36
|
+
@routing_number
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class DummyUser2
|
2
|
+
include ActiveModel::Validations
|
3
|
+
validates :iban, iban: {:message => 'custom iban error message'}
|
4
|
+
validates :bic, bic: {:message => 'custom bic error message'}
|
5
|
+
validates :routing_number, routing_number: {:message => 'custom routing number error message'}
|
6
|
+
|
7
|
+
attr_accessor :iban
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@iban = attributes[:iban]
|
11
|
+
@bic = attributes[:bic]
|
12
|
+
@routing_number = attributes[:routing_number]
|
13
|
+
end
|
14
|
+
|
15
|
+
def save
|
16
|
+
if valid?
|
17
|
+
return true
|
18
|
+
else
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create(attributes = {})
|
24
|
+
new(attributes).save
|
25
|
+
end
|
26
|
+
|
27
|
+
def iban
|
28
|
+
@iban
|
29
|
+
end
|
30
|
+
|
31
|
+
def bic
|
32
|
+
@bic
|
33
|
+
end
|
34
|
+
|
35
|
+
def routing_number
|
36
|
+
@routing_number
|
37
|
+
end
|
38
|
+
end
|
data/test/test_bank-validator.rb
CHANGED
@@ -1,95 +1,75 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'dummy_classes'
|
3
2
|
class TestBankValidator < MiniTest::Test
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
attr_accessor :iban
|
12
|
-
|
13
|
-
def initialize(attributes = {})
|
14
|
-
@iban = attributes[:iban]
|
15
|
-
@bic = attributes[:bic]
|
16
|
-
@routing_number = attributes[:routing_number]
|
17
|
-
end
|
18
|
-
|
19
|
-
def save
|
20
|
-
if valid?
|
21
|
-
return true
|
22
|
-
else
|
23
|
-
return false
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.create(attributes = {})
|
28
|
-
new(attributes).save
|
29
|
-
end
|
30
|
-
|
31
|
-
def iban
|
32
|
-
@iban
|
4
|
+
context "test custom messages" do
|
5
|
+
should "display custom iban error message" do
|
6
|
+
user = DummyUser2.new(iban: "GB82WEST", bic: "DEUTDEBR", routing_number: "026009593")
|
7
|
+
user.valid?
|
8
|
+
assert_equal ['custom iban error message'], user.errors[:iban]
|
33
9
|
end
|
34
10
|
|
35
|
-
|
36
|
-
|
11
|
+
should "display custom bic error message" do
|
12
|
+
user = DummyUser2.new(iban: "GB82WEST12345698765432", bic: "DEUTDE", routing_number: "026009593")
|
13
|
+
user.valid?
|
14
|
+
assert_equal ['custom bic error message'], user.errors[:bic]
|
37
15
|
end
|
38
16
|
|
39
|
-
|
40
|
-
|
17
|
+
should "display custom routing number error message" do
|
18
|
+
user = DummyUser2.new(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "02600959")
|
19
|
+
user.valid?
|
20
|
+
assert_equal ['custom routing number error message'], user.errors[:routing_number]
|
41
21
|
end
|
42
22
|
end
|
43
23
|
|
44
24
|
context "iban validator" do
|
45
25
|
should "not save if the iban is too short" do
|
46
|
-
assert_equal false,
|
26
|
+
assert_equal false, DummyUser.create(iban: "GB82WEST", bic: "DEUTDEBR", routing_number: "026009593")
|
47
27
|
end
|
48
28
|
|
49
29
|
should "save if the iban is at least 16 characters" do
|
50
|
-
assert_equal true,
|
30
|
+
assert_equal true, DummyUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
|
51
31
|
end
|
52
32
|
|
53
33
|
should "returns false if the iban does not leave a remainder of 1 when divided by 97" do
|
54
|
-
assert_equal false,
|
34
|
+
assert_equal false, DummyUser.create(iban: "GB82WEST123456987654Df", bic: "DEUTDEBR", routing_number: "026009593")
|
55
35
|
end
|
56
36
|
|
57
37
|
should "returns true if the iban returns a remainder of 1 when divided by 97" do
|
58
|
-
assert_equal true,
|
38
|
+
assert_equal true, DummyUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
|
59
39
|
end
|
60
40
|
|
61
41
|
should "work for different IBAN formats" do
|
62
42
|
#Belgium
|
63
|
-
assert_equal true,
|
43
|
+
assert_equal true, DummyUser.create(iban: "BE62510007547061", bic: "DEUTDEBR", routing_number: "026009593")
|
64
44
|
|
65
45
|
#Bulgaria
|
66
|
-
assert_equal true,
|
46
|
+
assert_equal true, DummyUser.create(iban: "BG80BNBG96611020345678", bic: "DEUTDEBR", routing_number: "026009593")
|
67
47
|
|
68
48
|
#Germany
|
69
|
-
assert_equal true,
|
49
|
+
assert_equal true, DummyUser.create(iban: "DE89370400440532013000", bic: "DEUTDEBR", routing_number: "026009593")
|
70
50
|
end
|
71
51
|
end
|
72
52
|
|
73
53
|
context "bic validator" do
|
74
54
|
should "be between 8 and 11 characters" do
|
75
|
-
assert_equal true,
|
76
|
-
assert_equal true,
|
55
|
+
assert_equal true, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
|
56
|
+
assert_equal true, DummyUser.create(bic: "DEUTDEBR123", iban: "BE62510007547061", routing_number: "026009593")
|
77
57
|
end
|
78
58
|
|
79
59
|
should "start with 6 letters" do
|
80
|
-
assert_equal true,
|
81
|
-
assert_equal false,
|
60
|
+
assert_equal true, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
|
61
|
+
assert_equal false, DummyUser.create(bic: "DEUT22BR", iban: "BE62510007547061", routing_number: "026009593")
|
82
62
|
end
|
83
63
|
end
|
84
64
|
|
85
65
|
context "routing number" do
|
86
66
|
should "be 9 digits long" do
|
87
|
-
assert_equal true,
|
67
|
+
assert_equal true, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
|
88
68
|
end
|
89
69
|
|
90
70
|
should "return false if not 9 digits long" do
|
91
|
-
assert_equal false,
|
92
|
-
assert_equal false,
|
71
|
+
assert_equal false, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "02600959")
|
72
|
+
assert_equal false, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "0260095933")
|
93
73
|
end
|
94
74
|
end
|
95
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Bahlke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -214,6 +214,9 @@ files:
|
|
214
214
|
- test/dummy/spec/spec_helper.rb
|
215
215
|
- test/dummy/vendor/assets/javascripts/.keep
|
216
216
|
- test/dummy/vendor/assets/stylesheets/.keep
|
217
|
+
- test/dummy_classes.rb
|
218
|
+
- test/dummy_classes/dummy_user.rb
|
219
|
+
- test/dummy_classes/dummy_user2.rb
|
217
220
|
- test/helper.rb
|
218
221
|
- test/test_bank-validator.rb
|
219
222
|
homepage: http://github.com/declarus/bank-validator
|