romanianvalidators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +11 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +18 -0
- data/Rakefile +49 -0
- data/lib/active_model/validations/bic_validator.rb +27 -0
- data/lib/active_model/validations/cif_validator.rb +32 -0
- data/lib/active_model/validations/cnp_validator.rb +54 -0
- data/lib/active_model/validations/iban_validator.rb +29 -0
- data/lib/romanianvalidators.rb +23 -0
- data/romanianvalidators.gemspec +19 -0
- data/test/data/valid_bics.txt +42 -0
- data/test/data/valid_cifs.txt +5 -0
- data/test/data/valid_cnps.txt +6 -0
- data/test/data/valid_ro_ibans.txt +64 -0
- data/test/test_helper.rb +22 -0
- data/test/validations/bic_test.rb +31 -0
- data/test/validations/cif_test.rb +31 -0
- data/test/validations/cnp_test.rb +31 -0
- data/test/validations/iban_test.rb +31 -0
- metadata +143 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007, 2012 Mihai Târnovan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Romanian Validators
|
2
|
+
|
3
|
+
Rails validators for:
|
4
|
+
|
5
|
+
* Cod Numeric Personal (CNP)
|
6
|
+
* Cod de identificare fiscală (CIF) and
|
7
|
+
* IBAN (only Romanian format as published by Romanian National Bank).
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
|
12
|
+
# TODO
|
13
|
+
|
14
|
+
* test more edge cases; test nil, blank; test messages
|
15
|
+
|
16
|
+
## Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2007-2012 Mihai Târnovan. MIT LICENSE. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/specification'
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
require 'rake/testtask'
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.pattern = "test/**/*_test.rb"
|
11
|
+
t.verbose = true
|
12
|
+
t.warning = true
|
13
|
+
end
|
14
|
+
|
15
|
+
# -*- encoding: utf-8 -*-
|
16
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
17
|
+
require 'romanianvalidators'
|
18
|
+
|
19
|
+
def gemspec
|
20
|
+
@gemspec ||= begin
|
21
|
+
file = File.expand_path('../romanianvalidators.gemspec', __FILE__)
|
22
|
+
eval(File.read(file), binding, file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Run the full spec suite"
|
27
|
+
task :full => ["test"]
|
28
|
+
|
29
|
+
desc "install the gem locally"
|
30
|
+
task :install => :package do
|
31
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "validate the gemspec"
|
35
|
+
task :gemspec do
|
36
|
+
gemspec.validate
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Build the gem"
|
40
|
+
task :gem => [:gemspec, :build] do
|
41
|
+
sh "gem build *.gemspec"
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Install RomanianValidators"
|
45
|
+
task :install => :gem do
|
46
|
+
sh "gem install pkg/#{gemspec.full_name}.gem"
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => :full
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
|
4
|
+
class BicValidator < EachValidator
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
allow_blank = options.fetch(:allow_blank, false)
|
7
|
+
allow_nil = options.fetch(:allow_nil, false)
|
8
|
+
record.errors.add_on_empty(attribute) if value.nil? && !allow_nil
|
9
|
+
record.errors.add_on_blank(attribute) if value.blank? && !allow_blank
|
10
|
+
record.errors.add(attribute) unless Bic.valid?(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
# This is only a basic validation of a BIC
|
14
|
+
# http://www.swift.com/biconline/index.cfm?fuseaction=display_aboutbic
|
15
|
+
class Bic
|
16
|
+
def self.valid?(bic)
|
17
|
+
country_codes = %w[AF AL DZ AS AD AO AI AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM BT BO BA BW BR BN BG BF BI KH CM CA CV KY CF TD CL CN CO KM CG CD CK CR CI HR CU CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK FO FJ FI FR GF PF GA GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT VA HN HK HU IS IN ID IR IQ IE IL IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV ML MT MH MQ MR MU MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW SH KN LC PM VC WS SM ST SA SN SC SL SG SK SI SB SO ZA ES LK SD SR SJ SZ SE CH SY TW TJ TZ TH TG TK TO TT TN TR TM TC TV UG UA AE GB US UY UZ VU VE VN VG VI WF EH YE ZM ZW]
|
18
|
+
return false unless bic.size == 8 || bic.size == 11 # length 8 or 11
|
19
|
+
return false unless (bic[0..3]=~(/[^A-Z]/)).nil? # first 4 must be letters only
|
20
|
+
return true if country_codes.include?(bic[4..5])
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
|
4
|
+
class CifValidator < EachValidator
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
allow_blank = options.fetch(:allow_blank, false)
|
7
|
+
allow_nil = options.fetch(:allow_nil, false)
|
8
|
+
record.errors.add_on_empty(attribute) if value.nil? && !allow_nil
|
9
|
+
record.errors.add_on_blank(attribute) if value.blank? && !allow_blank
|
10
|
+
record.errors.add(attribute) unless Cif.valid?(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Algoritmul de validare al unui cod CUI
|
14
|
+
# Pas preliminar: Se testeaza daca codul respecta formatul unui cod CUI. Adica lungimea maxima sa fie de 10 cifre si sa contina doar caractere numerice.
|
15
|
+
# Pas 1: Se foloseste cheia de testare "753217532". Se inverseaza ordinea cifrelor codului CUI precum si a cheii de testare.
|
16
|
+
# Pas 2: Se ignora prima cifra din codul CUI inversat (aceasta este cifra de control) si se inmulteste fiecare cifra cu cifra corespunzatoare din cheia de testare inversata.
|
17
|
+
# Pas 3: Se aduna toate produsele obtinute. Suma rezultata se inmulteste cu 10 si apoi se afla restul impartirii la 11.
|
18
|
+
# Pas 4: Pentru un CUI valid cifra obtinuta, in urma operatiei MODULO 11, va trebui sa corespunda cu cifra de control a codului CUI initial .
|
19
|
+
class Cif
|
20
|
+
def self.valid?(cif)
|
21
|
+
return false if cif.nil?
|
22
|
+
return false if cif.size > 10 || cif.size < 2
|
23
|
+
return false unless (cif=~(/[^0-9]/)).nil?
|
24
|
+
rk = "235712357".freeze # reversed test key (753217532)
|
25
|
+
rc = cif.reverse.freeze
|
26
|
+
(1..(cif.size - 1)).inject(0) {|sum, n| sum += rk[n-1].chr.to_i * rc[n].chr.to_i} * 10 % 11 % 10 == rc[0].chr.to_i
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
|
4
|
+
class CnpValidator < EachValidator
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
allow_blank = options.fetch(:allow_blank, false)
|
7
|
+
allow_nil = options.fetch(:allow_nil, false)
|
8
|
+
record.errors.add_on_empty(attribute) if value.nil? && !allow_nil
|
9
|
+
record.errors.add_on_blank(attribute) if value.blank? && !allow_blank
|
10
|
+
record.errors.add(attribute) unless Cnp.valid?(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Algoritm de validare CNP
|
14
|
+
# Pas preliminar: Se testeaza daca codul respecta formatul unui cod CNP.
|
15
|
+
# Adica prima cifra sa fie cuprinsa in intervalul 1 - 6 sau sa fie 9 pentru straini.
|
16
|
+
# Urmatoarele sase cifre trebuie sa constituie o data calendaristica valida in formatul AALLZZ.
|
17
|
+
#
|
18
|
+
# Pas 1:
|
19
|
+
# Se foloseste cheia de testare "279146358279". Primele douasprezece cifre se inmultesc pe rand de la
|
20
|
+
# stanga spre dreapta cu cifra corespunzatoare din cheia de testare.
|
21
|
+
#
|
22
|
+
# Pas 2: Cele douasprezece produse obtinute se aduna si suma obtinuta se imparte la 11. Restul impartirii
|
23
|
+
# reprezinta cifra de control. Pentru un CNP valid acest rest va trebui sa coincida cu cifra de pe
|
24
|
+
# pozitia treisprezece din CNP-ul initial.
|
25
|
+
class Cnp
|
26
|
+
def self.valid?(cnp)
|
27
|
+
return false unless (cnp=~(/[^0-9]/)).nil? && cnp.size == 13
|
28
|
+
require 'date'
|
29
|
+
begin
|
30
|
+
year = case
|
31
|
+
when
|
32
|
+
cnp[0].chr == "1" || cnp[0].chr == "2" then "19"
|
33
|
+
when
|
34
|
+
cnp[0].chr == "3" || cnp[0].chr == "4" then "18"
|
35
|
+
when
|
36
|
+
cnp[0].chr == "5" || cnp[0].chr == "6" then "20"
|
37
|
+
when
|
38
|
+
cnp[0].chr == "9" then "19" # oare se sare peste un an bisect intre 1800-2099 ?
|
39
|
+
else return false;
|
40
|
+
end
|
41
|
+
|
42
|
+
year = (year + cnp[1..2]).to_i
|
43
|
+
return false unless Date.valid_civil?(year,cnp[3..4].to_i,cnp[5..6].to_i)
|
44
|
+
rescue ArgumentError
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
test_key = "279146358279"
|
48
|
+
(0..11).inject(0){|sum, n| sum += test_key[n].chr.to_i * cnp[n].chr.to_i} % 11 == cnp[12].chr.to_i
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
|
4
|
+
class IbanValidator < EachValidator
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
allow_blank = options.fetch(:allow_blank, false)
|
7
|
+
allow_nil = options.fetch(:allow_nil, false)
|
8
|
+
record.errors.add_on_empty(attribute) if value.nil? && !allow_nil
|
9
|
+
record.errors.add_on_blank(attribute) if value.blank? && !allow_blank
|
10
|
+
record.errors.add(attribute) unless Iban.valid?(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Descrierea algoritmului:
|
14
|
+
# http://www.bnr.ro/files/d/Legislatie/EN/Reg_IBAN.pdf
|
15
|
+
class Iban
|
16
|
+
def self.valid?(iban)
|
17
|
+
return false if iban.size < 3
|
18
|
+
use_ord = "".respond_to?(:ord) # Ruby 1.9
|
19
|
+
(iban.slice(4,iban.size) + iban[0..3]).upcase.gsub(/[A-Z]/) do |s|
|
20
|
+
use_ord ? (s[0].ord - 55).to_s : (s[0].to_i - 55).to_s
|
21
|
+
end.to_i % 97 == 1
|
22
|
+
rescue
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
module Validations
|
5
|
+
def self.romanianvalidators
|
6
|
+
%w(cif cnp iban bic)
|
7
|
+
end
|
8
|
+
|
9
|
+
romanianvalidators.each do |validator_name|
|
10
|
+
require "active_model/validations/#{validator_name}_validator"
|
11
|
+
end
|
12
|
+
|
13
|
+
module HelperMethods
|
14
|
+
ActiveModel::Validations.romanianvalidators.each do |validator|
|
15
|
+
define_method('validates_' + validator) do |*fields|
|
16
|
+
options ||= (fields.delete fields.find { |f| f.kind_of? Hash}) || true
|
17
|
+
args = fields.push({ validator => options })
|
18
|
+
validates(*args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'romanianvalidators'
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.authors = ['Mihai Târnovan']
|
6
|
+
s.email = ['mihai.tarnovan@cubus.ro']
|
7
|
+
s.homepage = 'http://github.com/mtarnovan/romanianvalidators'
|
8
|
+
s.summary = %q{Collection of validations for Cod Numeric Personal (CNP), Cod de identificare fiscală (CIF) and IBAN (only Romanian format, as published by Romanian National Bank)}
|
9
|
+
s.description = %q{Collection of validations for Cod Numeric Personal (CNP), Cod de identificare fiscală (CIF) and IBAN (only Romanian format, as published by Romanian National Bank).}
|
10
|
+
|
11
|
+
s.add_development_dependency 'bundler'
|
12
|
+
s.add_development_dependency 'minitest'
|
13
|
+
s.add_dependency 'rake' , '>= 0.8.7'
|
14
|
+
s.add_dependency 'activemodel' , '>= 3.0.0'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.rubyforge_project = "romanianvalidators"
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
ABNAROBU
|
2
|
+
BUCUROBU
|
3
|
+
BFROROBU
|
4
|
+
BPOSROBU
|
5
|
+
CARPRO22
|
6
|
+
BROMROBU
|
7
|
+
BITRROBU
|
8
|
+
BRMAROBU
|
9
|
+
BTRLRO22
|
10
|
+
CITIROBU
|
11
|
+
CBITROBU
|
12
|
+
CRCOROBU
|
13
|
+
DAROROBU
|
14
|
+
EGNAROBX
|
15
|
+
BSEAROBU
|
16
|
+
DAFBRO22
|
17
|
+
EXIMROBU
|
18
|
+
FNNBROBU
|
19
|
+
BACXROBU
|
20
|
+
INGBROBU
|
21
|
+
BRELROBU
|
22
|
+
MINDROBU
|
23
|
+
MIRBROBU
|
24
|
+
ETHNROBU
|
25
|
+
NBORROBP
|
26
|
+
BCUNROBU
|
27
|
+
PIRBROBU
|
28
|
+
MIROROBU
|
29
|
+
RZBRROBU
|
30
|
+
RNBRROBU
|
31
|
+
BRDEROBU
|
32
|
+
RNCBROBU
|
33
|
+
ROINROBU
|
34
|
+
TREZROBU
|
35
|
+
CRDZROBU
|
36
|
+
WBANRO22
|
37
|
+
CECEROBU
|
38
|
+
UGBIROBU
|
39
|
+
UNCRROBU
|
40
|
+
VBBUROBU
|
41
|
+
PORLROBU
|
42
|
+
RZBLROBU
|
@@ -0,0 +1,64 @@
|
|
1
|
+
RO56TREZ0462107020101XXX
|
2
|
+
RO75TREZ0462116020201XXX
|
3
|
+
RO42TREZ04621030209XXXXX
|
4
|
+
RO57TREZ04621080206XXXXX
|
5
|
+
RO03TREZ0462107020201XXX
|
6
|
+
RO98TREZ04621030230XXXXX
|
7
|
+
RO24TREZ04621080230XXXXX
|
8
|
+
RO46TREZ04621170230XXXXX
|
9
|
+
RO43TREZ04621160250XXXXX
|
10
|
+
RO30TREZ046210402XXXXXXX
|
11
|
+
RO21TREZ04621070250XXXXX
|
12
|
+
RO04TREZ04621050201XXXXX
|
13
|
+
RO06TREZ0462107020102XXX
|
14
|
+
RO39TREZ04621050202XXXXX
|
15
|
+
RO50TREZ0462107020202XXX
|
16
|
+
RO22TREZ04621080205XXXXX
|
17
|
+
RO25TREZ0462116020202XXX
|
18
|
+
RO97TREZ0462107020203XXX
|
19
|
+
RO46TREZ046211502XXXXXXX
|
20
|
+
RO50TREZ04621150201XXXXX
|
21
|
+
RO71TREZ04621170203XXXXX
|
22
|
+
RO47TREZ04621160203XXXXX
|
23
|
+
RO98TREZ04621030230XXXXX
|
24
|
+
RO24TREZ04621080230XXXXX
|
25
|
+
RO45TREZ04621210230XXXXX
|
26
|
+
RO25TREZ04621170210XXXXX
|
27
|
+
RO25TREZ04621070203XXXXX
|
28
|
+
RO95TREZ04621170212XXXXX
|
29
|
+
RO25TREZ04621070203XXXXX
|
30
|
+
RO33TREZ04621170213XXXXX
|
31
|
+
RO56TREZ04621340202XXXXX
|
32
|
+
RO46TREZ04621170230XXXXX
|
33
|
+
RO91TREZ04621120207XXXXX
|
34
|
+
RO94TREZ04621220203XXXXX
|
35
|
+
RO78TREZ04621210206XXXXX
|
36
|
+
RO45TREZ04621350201XXXXX
|
37
|
+
RO59TREZ04621210211XXXXX
|
38
|
+
RO21TREZ04621330210XXXXX
|
39
|
+
RO59TREZ04621220202XXXXX
|
40
|
+
RO69TREZ04621330228XXXXX
|
41
|
+
RO40TREZ04621220207XXXXX
|
42
|
+
RO65TREZ04621300205XXXXX
|
43
|
+
RO75TREZ04621220208XXXXX
|
44
|
+
RO80TREZ04621350202XXXXX
|
45
|
+
RO45TREZ04621210230XXXXX
|
46
|
+
RO15TREZ04621360205XXXXX
|
47
|
+
RO69TREZ04621220230XXXXX
|
48
|
+
RO38TREZ04621360250XXXXX
|
49
|
+
RO22TREZ04621300201XXXXX
|
50
|
+
RO44TREZ04621390201XXXXX
|
51
|
+
RO92TREZ04621300203XXXXX
|
52
|
+
RO17TREZ04621390203XXXXX
|
53
|
+
RO46TREZ04621300210XXXXX
|
54
|
+
RO60TREZ04621390207XXXXX
|
55
|
+
RO68TREZ04621400201XXXXX
|
56
|
+
RO93TREZ04621370201XXXXX
|
57
|
+
RO90TREZ046500206X000079
|
58
|
+
RO90TREZ046500206X000079
|
59
|
+
RO28TREZ0465033XXX000299
|
60
|
+
RO28TREZ0465033XXX000299
|
61
|
+
RO93TREZ0465040XXX000331
|
62
|
+
RO93TREZ0465040XXX000331
|
63
|
+
RO50TREZ0465006XXX000186
|
64
|
+
RO50TREZ0465006XXX000186
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# silence warnings
|
4
|
+
old_w, $-w = $-w, false
|
5
|
+
|
6
|
+
require 'minitest/spec'
|
7
|
+
require 'minitest/mock'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
|
10
|
+
# unsilence warnings
|
11
|
+
$-w = old_w
|
12
|
+
|
13
|
+
require 'romanianvalidators'
|
14
|
+
|
15
|
+
class TestRecord
|
16
|
+
include ActiveModel::Validations
|
17
|
+
attr_accessor :cnp, :bic, :cif, :iban
|
18
|
+
|
19
|
+
def initialize(attrs = {})
|
20
|
+
attrs.each_pair { |k,v| send("#{k}=", v) }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test_helper.rb'
|
3
|
+
valid_bics = File.read('test/data/valid_bics.txt').split
|
4
|
+
|
5
|
+
describe "BICs" do
|
6
|
+
|
7
|
+
describe "for valid BICs" do
|
8
|
+
valid_bics.each do |bic|
|
9
|
+
it "accepts valid BIC" do
|
10
|
+
subject = build_bic_record({:bic => bic})
|
11
|
+
subject.valid?.must_equal true
|
12
|
+
subject.errors.size.must_equal 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "for invalid BICs" do
|
18
|
+
it "rejects invalid BICs and generates an error message" do
|
19
|
+
subject = build_bic_record :bic => '1'
|
20
|
+
subject.valid?.must_equal false
|
21
|
+
subject.errors.size.must_equal 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_bic_record(attrs = {}, opts = {})
|
26
|
+
TestRecord.reset_callbacks(:validate)
|
27
|
+
TestRecord.validates :bic, :bic => true
|
28
|
+
TestRecord.new attrs
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test_helper.rb'
|
3
|
+
valid_cifs = File.read('test/data/valid_cifs.txt').split
|
4
|
+
|
5
|
+
describe "Cod de identificare fiscală" do
|
6
|
+
|
7
|
+
describe "for valid CIFs" do
|
8
|
+
valid_cifs.each do |cif|
|
9
|
+
it "accepts valid CIF" do
|
10
|
+
subject = build_cif_record({:cif => cif})
|
11
|
+
subject.valid?.must_equal true
|
12
|
+
subject.errors.size.must_equal 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "for invalid CIFs" do
|
18
|
+
it "rejects invalid CIFs and generates an error message" do
|
19
|
+
subject = build_cif_record :cif => '1'
|
20
|
+
subject.valid?.must_equal false
|
21
|
+
subject.errors.size.must_equal 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_cif_record(attrs = {}, opts = {})
|
26
|
+
TestRecord.reset_callbacks(:validate)
|
27
|
+
TestRecord.validates :cif, :cif => true
|
28
|
+
TestRecord.new attrs
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test_helper.rb'
|
3
|
+
valid_cnps = File.read('test/data/valid_cnps.txt').split
|
4
|
+
|
5
|
+
describe "Cod numeric personal" do
|
6
|
+
|
7
|
+
describe "for valid CNPs" do
|
8
|
+
valid_cnps.each do |cnp|
|
9
|
+
it "accepts valid CNP" do
|
10
|
+
subject = build_cnp_record({:cnp => cnp})
|
11
|
+
subject.valid?.must_equal true
|
12
|
+
subject.errors.size.must_equal 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "for invalid CNPs" do
|
18
|
+
it "rejects invalid CNPs and generates an error message" do
|
19
|
+
subject = build_cnp_record :cnp => '1'
|
20
|
+
subject.valid?.must_equal false
|
21
|
+
subject.errors.size.must_equal 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_cnp_record(attrs = {}, opts = {})
|
26
|
+
TestRecord.reset_callbacks(:validate)
|
27
|
+
TestRecord.validates :cnp, :cnp => true
|
28
|
+
TestRecord.new attrs
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test_helper.rb'
|
3
|
+
valid_ro_ibans = File.read('test/data/valid_ro_ibans.txt').split
|
4
|
+
|
5
|
+
describe "Iban (BNR only)" do
|
6
|
+
|
7
|
+
describe "for valid romanian IBANs" do
|
8
|
+
valid_ro_ibans.each do |iban|
|
9
|
+
it "accepts valid IBAN" do
|
10
|
+
subject = build_iban_record({:iban => iban})
|
11
|
+
subject.valid?.must_equal true
|
12
|
+
subject.errors.size.must_equal 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "for invalid IBANs" do
|
18
|
+
it "rejects invalid IBANs and generates an error message" do
|
19
|
+
subject = build_iban_record :iban => '1'
|
20
|
+
subject.valid?.must_equal false
|
21
|
+
subject.errors.size.must_equal 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_iban_record(attrs = {}, opts = {})
|
26
|
+
TestRecord.reset_callbacks(:validate)
|
27
|
+
TestRecord.validates :iban, :iban => true
|
28
|
+
TestRecord.new attrs
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: romanianvalidators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mihai Târnovan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: minitest
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.8.7
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.7
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activemodel
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
78
|
+
description: Collection of validations for Cod Numeric Personal (CNP), Cod de identificare
|
79
|
+
fiscală (CIF) and IBAN (only Romanian format, as published by Romanian National
|
80
|
+
Bank).
|
81
|
+
email:
|
82
|
+
- mihai.tarnovan@cubus.ro
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .travis.yml
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/active_model/validations/bic_validator.rb
|
94
|
+
- lib/active_model/validations/cif_validator.rb
|
95
|
+
- lib/active_model/validations/cnp_validator.rb
|
96
|
+
- lib/active_model/validations/iban_validator.rb
|
97
|
+
- lib/romanianvalidators.rb
|
98
|
+
- romanianvalidators.gemspec
|
99
|
+
- test/data/valid_bics.txt
|
100
|
+
- test/data/valid_cifs.txt
|
101
|
+
- test/data/valid_cnps.txt
|
102
|
+
- test/data/valid_ro_ibans.txt
|
103
|
+
- test/test_helper.rb
|
104
|
+
- test/validations/bic_test.rb
|
105
|
+
- test/validations/cif_test.rb
|
106
|
+
- test/validations/cnp_test.rb
|
107
|
+
- test/validations/iban_test.rb
|
108
|
+
homepage: http://github.com/mtarnovan/romanianvalidators
|
109
|
+
licenses: []
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project: romanianvalidators
|
128
|
+
rubygems_version: 1.8.24
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: Collection of validations for Cod Numeric Personal (CNP), Cod de identificare
|
132
|
+
fiscală (CIF) and IBAN (only Romanian format, as published by Romanian National
|
133
|
+
Bank)
|
134
|
+
test_files:
|
135
|
+
- test/data/valid_bics.txt
|
136
|
+
- test/data/valid_cifs.txt
|
137
|
+
- test/data/valid_cnps.txt
|
138
|
+
- test/data/valid_ro_ibans.txt
|
139
|
+
- test/test_helper.rb
|
140
|
+
- test/validations/bic_test.rb
|
141
|
+
- test/validations/cif_test.rb
|
142
|
+
- test/validations/cnp_test.rb
|
143
|
+
- test/validations/iban_test.rb
|