elfproef 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/README.md +2 -2
- data/lib/elfproef.rb +4 -4
- data/lib/version.rb +1 -1
- data/spec/elfproef_spec.rb +49 -5
- metadata +10 -16
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -28,10 +28,10 @@ and run
|
|
28
28
|
Simply add "validates_elfproef_of" to your model class.
|
29
29
|
|
30
30
|
class User < ActiveRecord::Base
|
31
|
-
|
31
|
+
# Validate with 11-test, do not allow 7 digit ING account numbers
|
32
32
|
validates :bsn, elfproef: true
|
33
33
|
|
34
|
-
|
34
|
+
# Validate bank account numbers with 11-test, allow 7 digit ING account numbers
|
35
35
|
validates :bank_account, elfproef: { allow_ing: true }
|
36
36
|
end
|
37
37
|
|
data/lib/elfproef.rb
CHANGED
@@ -19,10 +19,10 @@ module Elfproef
|
|
19
19
|
# http://nl.wikipedia.org/wiki/Elfproef
|
20
20
|
def self.elfproef(number, options = {})
|
21
21
|
number, sum = number.to_s, 0
|
22
|
-
number.gsub!(/\D/, '')
|
23
|
-
return true if options[:allow_ing] && number.length
|
24
|
-
return false unless number
|
25
|
-
(1..
|
22
|
+
number.gsub!(/\D/, '') # strip out any non-digit character.
|
23
|
+
return true if options[:allow_ing] && (1..7).include?(number.length) # always pass ING accounts (between 1 and 7 digits)
|
24
|
+
return false unless (9..10).include?(number.length) # account should be exactly 9 or 10 digits
|
25
|
+
(1..number.length).each do |c|
|
26
26
|
sum += number[-c].chr.to_i * c
|
27
27
|
end
|
28
28
|
sum % 11 == 0
|
data/lib/version.rb
CHANGED
data/spec/elfproef_spec.rb
CHANGED
@@ -40,7 +40,6 @@ describe Elfproef do
|
|
40
40
|
Elfproef.elfproef('1234567', opts).should == true
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
43
|
shared_examples_for "elfproef validations" do
|
45
44
|
subject { account_class.new }
|
46
45
|
|
@@ -50,21 +49,61 @@ describe Elfproef do
|
|
50
49
|
end
|
51
50
|
|
52
51
|
it "fails with an obviously wrong number" do
|
53
|
-
subject.account = "
|
52
|
+
subject.account = "12345678901"
|
54
53
|
subject.should_not be_valid
|
55
54
|
subject.errors[:account].should == errors
|
56
55
|
end
|
57
56
|
|
58
|
-
it "passes with a ING number" do
|
57
|
+
it "passes with a 7-diget ING number" do
|
59
58
|
subject.account = "1234567"
|
60
59
|
subject.should be_valid
|
61
60
|
end
|
62
61
|
|
63
|
-
it "passes with a
|
62
|
+
it "passes with a 6-digit ING number" do
|
63
|
+
subject.account = "123456"
|
64
|
+
subject.should be_valid
|
65
|
+
end
|
66
|
+
|
67
|
+
it "passes with a 5-digit ING number" do
|
68
|
+
subject.account = "12345"
|
69
|
+
subject.should be_valid
|
70
|
+
end
|
71
|
+
|
72
|
+
it "passes with a 4-digit ING number" do
|
73
|
+
subject.account = "1234"
|
74
|
+
subject.should be_valid
|
75
|
+
end
|
76
|
+
|
77
|
+
it "passes with a 3-digit ING number" do
|
78
|
+
subject.account = "123"
|
79
|
+
subject.should be_valid
|
80
|
+
end
|
81
|
+
|
82
|
+
it "passes with a 2-digit ING number" do
|
83
|
+
subject.account = "12"
|
84
|
+
subject.should be_valid
|
85
|
+
end
|
86
|
+
|
87
|
+
it "passes with a 1-digit ING number" do
|
88
|
+
subject.account = "1"
|
89
|
+
subject.should be_valid
|
90
|
+
end
|
91
|
+
|
92
|
+
it "passes with a ING number starting with a P (from Postbank)" do
|
93
|
+
subject.account = "P1234567"
|
94
|
+
subject.should be_valid
|
95
|
+
end
|
96
|
+
|
97
|
+
it "passes with a valid 9-digit bank number" do
|
64
98
|
subject.account = "123456789"
|
65
99
|
subject.should be_valid
|
66
100
|
end
|
67
101
|
|
102
|
+
it "passes with a valid 10-digit bank number" do
|
103
|
+
subject.account = "0123456789"
|
104
|
+
subject.should be_valid
|
105
|
+
end
|
106
|
+
|
68
107
|
it "fails with an wrong bank number" do
|
69
108
|
subject.account = "999999999"
|
70
109
|
subject.should_not be_valid
|
@@ -92,11 +131,16 @@ describe Elfproef do
|
|
92
131
|
subject.errors[:account].should == errors
|
93
132
|
end
|
94
133
|
|
95
|
-
it "passes with a valid bank number" do
|
134
|
+
it "passes with a valid 9-digit bank number" do
|
96
135
|
subject.account = "123456789"
|
97
136
|
subject.should be_valid
|
98
137
|
end
|
99
138
|
|
139
|
+
it "passes with a valid 10-digit bank number" do
|
140
|
+
subject.account = "0123456789"
|
141
|
+
subject.should be_valid
|
142
|
+
end
|
143
|
+
|
100
144
|
it "fails with an wrong bank number" do
|
101
145
|
subject.account = "999999999"
|
102
146
|
subject.should_not be_valid
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elfproef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-03-13 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement: &
|
17
|
+
requirement: &70105363295440 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70105363295440
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &70105363294960 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70105363294960
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: guard-rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70105363294520 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70105363294520
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: activemodel
|
50
|
-
requirement: &
|
50
|
+
requirement: &70105363293980 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70105363293980
|
59
59
|
description: Validation for Dutch bank account numbers and Citizen Service Numbers
|
60
60
|
(BSN)
|
61
61
|
email:
|
@@ -87,21 +87,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- - ! '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
hash: -1245454335303518199
|
93
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
91
|
none: false
|
95
92
|
requirements:
|
96
93
|
- - ! '>='
|
97
94
|
- !ruby/object:Gem::Version
|
98
95
|
version: '0'
|
99
|
-
segments:
|
100
|
-
- 0
|
101
|
-
hash: -1245454335303518199
|
102
96
|
requirements: []
|
103
97
|
rubyforge_project: elfproef
|
104
|
-
rubygems_version: 1.8.
|
98
|
+
rubygems_version: 1.8.17
|
105
99
|
signing_key:
|
106
100
|
specification_version: 3
|
107
101
|
summary: Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)
|