elfproef 0.1.1 → 0.1.2
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.
- data/README.md +14 -0
- data/lib/elfproef/bank_account_validator.rb +8 -4
- data/lib/elfproef/bsn_validator.rb +17 -1
- data/lib/elfproef/version.rb +1 -1
- data/spec/bank_account_validator_spec.rb +13 -13
- data/spec/bsn_validator_spec.rb +11 -11
- metadata +33 -13
data/README.md
CHANGED
@@ -42,6 +42,20 @@ You can also use these validators without `ActiveRecord` by including `ActiveMod
|
|
42
42
|
validates :bsn, bsn: true
|
43
43
|
end
|
44
44
|
|
45
|
+
## I18n
|
46
|
+
|
47
|
+
Add the following to your locale file:
|
48
|
+
|
49
|
+
en:
|
50
|
+
activemodel:
|
51
|
+
errors:
|
52
|
+
models:
|
53
|
+
YOUR_MODEL:
|
54
|
+
attributes:
|
55
|
+
ATTRIBUTE:
|
56
|
+
invalid_bank_account: "is not a valid bank account number"
|
57
|
+
invalid_bsn: "is not a valid BSN"
|
58
|
+
|
45
59
|
## Bugs / Feature Requests
|
46
60
|
|
47
61
|
Please post them to
|
@@ -1,11 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'active_model/validator'
|
2
|
+
require 'active_support/concern'
|
3
3
|
|
4
4
|
# Validates if the specified value is a valid
|
5
5
|
# bank account number using the 11-test
|
6
|
-
class BankAccountValidator < ActiveModel::EachValidator
|
6
|
+
class BankAccountValidator < ::ActiveModel::EachValidator
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
7
9
|
def validate_each(record, attribute, value)
|
8
|
-
|
10
|
+
unless validate_account_number(value, options)
|
11
|
+
record.errors.add(attribute, :invalid_bank_account, options)
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
private
|
@@ -5,7 +5,9 @@ require "active_model/validations"
|
|
5
5
|
# Burgerservicenummer (Dutch social security number)
|
6
6
|
class BsnValidator < ActiveModel::EachValidator
|
7
7
|
def validate_each(record, attribute, value)
|
8
|
-
|
8
|
+
unless validate_bsn(value, options)
|
9
|
+
record.errors.add(attribute, :invalid_bsn, options)
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
@@ -22,6 +24,20 @@ class BsnValidator < ActiveModel::EachValidator
|
|
22
24
|
validate_with_advanced_eleven_test(bsn)
|
23
25
|
end
|
24
26
|
|
27
|
+
# Performs the advanced 11-test on a
|
28
|
+
# 8 or 9 digit account number
|
29
|
+
#
|
30
|
+
# For 9 digits (prefix with a 0 for 8 digits):
|
31
|
+
#
|
32
|
+
# 123456782
|
33
|
+
# ABCDEFGHI
|
34
|
+
#
|
35
|
+
# sum = 9*A + 8*B + 7*C + 6*D + 5*E + 4*F + 3*G + 2*H + -1*I
|
36
|
+
#
|
37
|
+
# Note the -1*I!
|
38
|
+
#
|
39
|
+
# If sum % 11 is 0, the number is valid, otherwise
|
40
|
+
# a typo has been made or the number is outright invalid.
|
25
41
|
def validate_with_advanced_eleven_test(number)
|
26
42
|
# Make sure we have 9 digits
|
27
43
|
number = "0#{number}" if number.size == 8
|
data/lib/elfproef/version.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
+
class BankAccountTest
|
4
|
+
include ActiveModel::Validations
|
5
|
+
attr_accessor :account
|
6
|
+
validates :account, :bank_account => true
|
7
|
+
end
|
8
|
+
|
3
9
|
describe BankAccountValidator do
|
4
10
|
subject {
|
5
|
-
|
6
|
-
include ActiveModel::Validations
|
7
|
-
attr_accessor :account
|
8
|
-
validates :account, :bank_account => true
|
9
|
-
end.new
|
11
|
+
BankAccountTest.new
|
10
12
|
}
|
11
13
|
|
12
|
-
let(:errors) { ["is not valid"] }
|
13
|
-
|
14
14
|
it "accepts 1 digit ING accounts" do
|
15
15
|
subject.account = "1"
|
16
16
|
subject.should be_valid
|
@@ -56,21 +56,21 @@ describe BankAccountValidator do
|
|
56
56
|
subject.should be_valid
|
57
57
|
end
|
58
58
|
|
59
|
-
it "
|
59
|
+
it "rejects on an 8 digit number" do
|
60
60
|
subject.account = "12345678"
|
61
61
|
subject.should_not be_valid
|
62
|
-
subject.errors[:account].should
|
62
|
+
subject.errors[:account].should be_present
|
63
63
|
end
|
64
64
|
|
65
|
-
it "
|
65
|
+
it "rejects on obviously wrong numbers" do
|
66
66
|
subject.account = "CHUCKNORRIS"
|
67
67
|
subject.should_not be_valid
|
68
|
-
subject.errors[:account].should
|
68
|
+
subject.errors[:account].should be_present
|
69
69
|
end
|
70
70
|
|
71
|
-
it "
|
71
|
+
it "rejects on 1 digit errors" do
|
72
72
|
subject.account = "133456789"
|
73
73
|
subject.should_not be_valid
|
74
|
-
subject.errors[:account].should
|
74
|
+
subject.errors[:account].should be_present
|
75
75
|
end
|
76
76
|
end
|
data/spec/bsn_validator_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
+
class BsnTest
|
4
|
+
include ActiveModel::Validations
|
5
|
+
attr_accessor :number
|
6
|
+
validates :number, :bsn => true
|
7
|
+
end
|
8
|
+
|
3
9
|
describe BsnValidator do
|
4
10
|
subject {
|
5
|
-
|
6
|
-
include ActiveModel::Validations
|
7
|
-
attr_accessor :number
|
8
|
-
validates :number, :bsn => true
|
9
|
-
end.new
|
11
|
+
BsnTest.new
|
10
12
|
}
|
11
13
|
|
12
|
-
let(:errors) { ["is not valid"] }
|
13
|
-
|
14
14
|
it "accepts an 8 digit bsn" do
|
15
15
|
subject.number = "12345672"
|
16
16
|
subject.should be_valid
|
@@ -24,24 +24,24 @@ describe BsnValidator do
|
|
24
24
|
it "rejects too short bsn numbers" do
|
25
25
|
subject.number = "123"
|
26
26
|
subject.should_not be_valid
|
27
|
-
subject.errors[:number].should
|
27
|
+
subject.errors[:number].should be_present
|
28
28
|
end
|
29
29
|
|
30
30
|
it "rejects too long bsn numbers" do
|
31
31
|
subject.number = "123456789012345"
|
32
32
|
subject.should_not be_valid
|
33
|
-
subject.errors[:number].should
|
33
|
+
subject.errors[:number].should be_present
|
34
34
|
end
|
35
35
|
|
36
36
|
it "rejects obvious incorrect bsn numbers" do
|
37
37
|
subject.number = "NOTAXES"
|
38
38
|
subject.should_not be_valid
|
39
|
-
subject.errors[:number].should
|
39
|
+
subject.errors[:number].should be_present
|
40
40
|
end
|
41
41
|
|
42
42
|
it "rejects mistyped bsn numbers" do
|
43
43
|
subject.number = "123456789012345"
|
44
44
|
subject.should_not be_valid
|
45
|
-
subject.errors[:number].should
|
45
|
+
subject.errors[:number].should be_present
|
46
46
|
end
|
47
47
|
end
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-04-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: rspec
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ! '>='
|
@@ -33,10 +38,15 @@ dependencies:
|
|
33
38
|
version: '0'
|
34
39
|
type: :development
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
37
47
|
- !ruby/object:Gem::Dependency
|
38
48
|
name: guard-rspec
|
39
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
none: false
|
41
51
|
requirements:
|
42
52
|
- - ! '>='
|
@@ -44,10 +54,15 @@ dependencies:
|
|
44
54
|
version: '0'
|
45
55
|
type: :development
|
46
56
|
prerelease: false
|
47
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
48
63
|
- !ruby/object:Gem::Dependency
|
49
64
|
name: activemodel
|
50
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
51
66
|
none: false
|
52
67
|
requirements:
|
53
68
|
- - ! '>='
|
@@ -55,7 +70,12 @@ dependencies:
|
|
55
70
|
version: '0'
|
56
71
|
type: :runtime
|
57
72
|
prerelease: false
|
58
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
59
79
|
description: Validation for Dutch bank account numbers and Citizen Service Numbers
|
60
80
|
(BSN)
|
61
81
|
email:
|
@@ -93,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
113
|
version: '0'
|
94
114
|
segments:
|
95
115
|
- 0
|
96
|
-
hash: -
|
116
|
+
hash: -3163671652779921677
|
97
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
118
|
none: false
|
99
119
|
requirements:
|
@@ -102,10 +122,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
122
|
version: '0'
|
103
123
|
segments:
|
104
124
|
- 0
|
105
|
-
hash: -
|
125
|
+
hash: -3163671652779921677
|
106
126
|
requirements: []
|
107
127
|
rubyforge_project: elfproef
|
108
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.19
|
109
129
|
signing_key:
|
110
130
|
specification_version: 3
|
111
131
|
summary: Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)
|