elfproef 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +7 -2
- data/elfproef.gemspec +4 -4
- data/lib/elfproef.rb +4 -4
- data/lib/version.rb +2 -2
- data/spec/elfproef_spec.rb +50 -5
- metadata +20 -11
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Elfproef
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/sytzeloor/elfproef.png?branch=master)](http://travis-ci.org/sytzeloor/elfproef)
|
4
|
+
|
3
5
|
This gem adds a validation method for Dutch bank account numbers and
|
4
6
|
Citizen Service Numbers (BSN). These can be validated using the
|
5
7
|
so-called Elfproef.
|
@@ -26,8 +28,11 @@ and run
|
|
26
28
|
Simply add "validates_elfproef_of" to your model class.
|
27
29
|
|
28
30
|
class User < ActiveRecord::Base
|
29
|
-
|
31
|
+
# Validate with 11-test, do not allow 7 digit ING account numbers
|
30
32
|
validates :bsn, elfproef: true
|
33
|
+
|
34
|
+
# Validate bank account numbers with 11-test, allow 7 digit ING account numbers
|
35
|
+
validates :bank_account, elfproef: { allow_ing: true }
|
31
36
|
end
|
32
37
|
|
33
38
|
## Bugs / Feature Requests
|
@@ -66,4 +71,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
66
71
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
67
72
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
68
73
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
69
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
74
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/elfproef.gemspec
CHANGED
@@ -5,9 +5,9 @@ require "version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "elfproef"
|
7
7
|
s.version = Elfproef::VERSION
|
8
|
-
s.authors = ["Sytze Loor"]
|
9
|
-
s.email = ["sytze@tweedledum.nl"]
|
10
|
-
s.homepage = ""
|
8
|
+
s.authors = ["Sytze Loor", "Ariejan de Vroom"]
|
9
|
+
s.email = ["sytze@tweedledum.nl", "ariejan@ariejan.net"]
|
10
|
+
s.homepage = "https://github.com/sytzeloor/elfproef"
|
11
11
|
s.summary = %q{Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)}
|
12
12
|
s.description = %q{Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)}
|
13
13
|
|
@@ -25,4 +25,4 @@ Gem::Specification.new do |s|
|
|
25
25
|
|
26
26
|
s.add_dependency "activemodel"
|
27
27
|
|
28
|
-
end
|
28
|
+
end
|
data/lib/elfproef.rb
CHANGED
@@ -5,7 +5,7 @@ require "active_model/validations"
|
|
5
5
|
class ElfproefValidator < ActiveModel::EachValidator
|
6
6
|
# implement the method where the validation logic must reside
|
7
7
|
def validate_each(record, attribute, value)
|
8
|
-
record.errors.add(attribute, options[:message] || "is not valid") unless Elfproef.elfproef(value)
|
8
|
+
record.errors.add(attribute, options[:message] || "is not valid") unless Elfproef.elfproef(value, options)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -17,14 +17,14 @@ module Elfproef
|
|
17
17
|
# Postbank bank accounts (7 digits) cannot be validated using the elfproef and
|
18
18
|
# will always return 0 (success).
|
19
19
|
# http://nl.wikipedia.org/wiki/Elfproef
|
20
|
-
def self.elfproef(number)
|
20
|
+
def self.elfproef(number, options = {})
|
21
21
|
number, sum = number.to_s, 0
|
22
22
|
number.gsub!(/\D/, '') # strip out any non-digit character.
|
23
|
-
return true if number.length == 7 # always pass postbank accounts (7 digits)
|
23
|
+
return true if options[:allow_ing] && number.length == 7 # always pass postbank accounts (7 digits)
|
24
24
|
return false unless number =~ /^\d{9}$/ # account should be exactly 9 digits
|
25
25
|
(1..9).each do |c|
|
26
26
|
sum += number[-c].chr.to_i * c
|
27
27
|
end
|
28
28
|
sum % 11 == 0
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
data/lib/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Elfproef
|
2
|
-
VERSION= "0.0.
|
3
|
-
end
|
2
|
+
VERSION= "0.0.2"
|
3
|
+
end
|
data/spec/elfproef_spec.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe Elfproef do
|
4
|
-
|
5
4
|
account_class = Class.new do
|
5
|
+
include ActiveModel::Validations
|
6
|
+
attr_accessor :account
|
7
|
+
validates :account, :elfproef => { :allow_ing => true }
|
8
|
+
end
|
9
|
+
|
10
|
+
bank_only_class = Class.new do
|
6
11
|
include ActiveModel::Validations
|
7
12
|
attr_accessor :account
|
8
13
|
validates :account, :elfproef => true
|
@@ -27,8 +32,12 @@ describe Elfproef do
|
|
27
32
|
Elfproef.elfproef(123456789).should == true
|
28
33
|
Elfproef.elfproef('12.34.56.789').should == true
|
29
34
|
Elfproef.elfproef('12 34 56 789').should == true
|
30
|
-
|
31
|
-
|
35
|
+
end
|
36
|
+
|
37
|
+
it "tests valid ING accounts" do
|
38
|
+
opts = { :allow_ing => true }
|
39
|
+
Elfproef.elfproef(1234567, opts).should == true
|
40
|
+
Elfproef.elfproef('1234567', opts).should == true
|
32
41
|
end
|
33
42
|
|
34
43
|
|
@@ -61,11 +70,47 @@ describe Elfproef do
|
|
61
70
|
subject.should_not be_valid
|
62
71
|
subject.errors[:account].should == errors
|
63
72
|
end
|
73
|
+
end
|
74
|
+
|
75
|
+
shared_examples_for "elfproef, bank accounts only validations" do
|
76
|
+
subject { bank_only_class.new }
|
77
|
+
|
78
|
+
it "fails when empty" do
|
79
|
+
subject.should_not be_valid
|
80
|
+
subject.errors[:account].should == errors
|
81
|
+
end
|
82
|
+
|
83
|
+
it "fails with an obviously wrong number" do
|
84
|
+
subject.account = "666"
|
85
|
+
subject.should_not be_valid
|
86
|
+
subject.errors[:account].should == errors
|
87
|
+
end
|
88
|
+
|
89
|
+
it "fails with a ING number" do
|
90
|
+
subject.account = "1234567"
|
91
|
+
subject.should_not be_valid
|
92
|
+
subject.errors[:account].should == errors
|
93
|
+
end
|
64
94
|
|
95
|
+
it "passes with a valid bank number" do
|
96
|
+
subject.account = "123456789"
|
97
|
+
subject.should be_valid
|
98
|
+
end
|
99
|
+
|
100
|
+
it "fails with an wrong bank number" do
|
101
|
+
subject.account = "999999999"
|
102
|
+
subject.should_not be_valid
|
103
|
+
subject.errors[:account].should == errors
|
104
|
+
end
|
65
105
|
end
|
66
106
|
|
67
|
-
describe "
|
107
|
+
describe "bank + ing validations" do
|
68
108
|
let!(:errors) { [ "is not valid"] }
|
69
109
|
it_should_behave_like "elfproef validations"
|
70
110
|
end
|
71
|
-
|
111
|
+
|
112
|
+
describe "bank only validations" do
|
113
|
+
let!(:errors) { [ "is not valid"] }
|
114
|
+
it_should_behave_like "elfproef, bank accounts only validations"
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,11 +1,12 @@
|
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sytze Loor
|
9
|
+
- Ariejan de Vroom
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
@@ -13,7 +14,7 @@ date: 2012-03-13 00:00:00.000000000 Z
|
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rake
|
16
|
-
requirement: &
|
17
|
+
requirement: &70335074770740 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ! '>='
|
@@ -21,10 +22,10 @@ dependencies:
|
|
21
22
|
version: '0'
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
+
version_requirements: *70335074770740
|
25
26
|
- !ruby/object:Gem::Dependency
|
26
27
|
name: rspec
|
27
|
-
requirement: &
|
28
|
+
requirement: &70335074769940 !ruby/object:Gem::Requirement
|
28
29
|
none: false
|
29
30
|
requirements:
|
30
31
|
- - ! '>='
|
@@ -32,10 +33,10 @@ dependencies:
|
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
+
version_requirements: *70335074769940
|
36
37
|
- !ruby/object:Gem::Dependency
|
37
38
|
name: guard-rspec
|
38
|
-
requirement: &
|
39
|
+
requirement: &70335074769340 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
42
|
- - ! '>='
|
@@ -43,10 +44,10 @@ dependencies:
|
|
43
44
|
version: '0'
|
44
45
|
type: :development
|
45
46
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
+
version_requirements: *70335074769340
|
47
48
|
- !ruby/object:Gem::Dependency
|
48
49
|
name: activemodel
|
49
|
-
requirement: &
|
50
|
+
requirement: &70335074768620 !ruby/object:Gem::Requirement
|
50
51
|
none: false
|
51
52
|
requirements:
|
52
53
|
- - ! '>='
|
@@ -54,16 +55,18 @@ dependencies:
|
|
54
55
|
version: '0'
|
55
56
|
type: :runtime
|
56
57
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
+
version_requirements: *70335074768620
|
58
59
|
description: Validation for Dutch bank account numbers and Citizen Service Numbers
|
59
60
|
(BSN)
|
60
61
|
email:
|
61
62
|
- sytze@tweedledum.nl
|
63
|
+
- ariejan@ariejan.net
|
62
64
|
executables: []
|
63
65
|
extensions: []
|
64
66
|
extra_rdoc_files: []
|
65
67
|
files:
|
66
68
|
- .gitignore
|
69
|
+
- .travis.yml
|
67
70
|
- Gemfile
|
68
71
|
- README.md
|
69
72
|
- Rakefile
|
@@ -72,7 +75,7 @@ files:
|
|
72
75
|
- lib/version.rb
|
73
76
|
- spec/elfproef_spec.rb
|
74
77
|
- spec/spec_helper.rb
|
75
|
-
homepage:
|
78
|
+
homepage: https://github.com/sytzeloor/elfproef
|
76
79
|
licenses: []
|
77
80
|
post_install_message:
|
78
81
|
rdoc_options: []
|
@@ -84,15 +87,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
87
|
- - ! '>='
|
85
88
|
- !ruby/object:Gem::Version
|
86
89
|
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: -1245454335303518199
|
87
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
94
|
none: false
|
89
95
|
requirements:
|
90
96
|
- - ! '>='
|
91
97
|
- !ruby/object:Gem::Version
|
92
98
|
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: -1245454335303518199
|
93
102
|
requirements: []
|
94
103
|
rubyforge_project: elfproef
|
95
|
-
rubygems_version: 1.8.
|
104
|
+
rubygems_version: 1.8.11
|
96
105
|
signing_key:
|
97
106
|
specification_version: 3
|
98
107
|
summary: Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)
|