br_documents 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +146 -0
- data/Rakefile +1 -0
- data/br_documents.gemspec +30 -0
- data/config/locales/pt-BR.yml +8 -0
- data/lib/br_documents.rb +4 -0
- data/lib/br_documents/cnpj_cpf/cnpj.rb +21 -0
- data/lib/br_documents/cnpj_cpf/cpf.rb +21 -0
- data/lib/br_documents/cnpj_cpf/document.rb +35 -0
- data/lib/br_documents/cnpj_validator.rb +8 -0
- data/lib/br_documents/commons/mod11.rb +20 -0
- data/lib/br_documents/cpf_validator.rb +8 -0
- data/lib/br_documents/ie/ac.rb +17 -0
- data/lib/br_documents/ie/al.rb +17 -0
- data/lib/br_documents/ie/am.rb +17 -0
- data/lib/br_documents/ie/ap.rb +52 -0
- data/lib/br_documents/ie/ba.rb +75 -0
- data/lib/br_documents/ie/base.rb +17 -0
- data/lib/br_documents/ie/ce.rb +12 -0
- data/lib/br_documents/ie/df.rb +17 -0
- data/lib/br_documents/ie/es.rb +12 -0
- data/lib/br_documents/ie/factory.rb +12 -0
- data/lib/br_documents/ie/go.rb +17 -0
- data/lib/br_documents/ie/ma.rb +12 -0
- data/lib/br_documents/ie/mg.rb +53 -0
- data/lib/br_documents/ie/ms.rb +12 -0
- data/lib/br_documents/ie/mt.rb +18 -0
- data/lib/br_documents/ie/pa.rb +17 -0
- data/lib/br_documents/ie/pattern1.rb +26 -0
- data/lib/br_documents/ie/pattern2.rb +30 -0
- data/lib/br_documents/ie/pb.rb +12 -0
- data/lib/br_documents/ie/pe.rb +51 -0
- data/lib/br_documents/ie/pi.rb +12 -0
- data/lib/br_documents/ie/pr.rb +19 -0
- data/lib/br_documents/ie/rj.rb +18 -0
- data/lib/br_documents/ie/rn.rb +47 -0
- data/lib/br_documents/ie/ro.rb +49 -0
- data/lib/br_documents/ie/rr.rb +23 -0
- data/lib/br_documents/ie/rs.rb +18 -0
- data/lib/br_documents/ie/sc.rb +17 -0
- data/lib/br_documents/ie/se.rb +12 -0
- data/lib/br_documents/ie/sp.rb +55 -0
- data/lib/br_documents/ie/to.rb +18 -0
- data/lib/br_documents/ie_validator.rb +50 -0
- data/lib/br_documents/version.rb +3 -0
- data/spec/cnpj_cpf/cnpj_spec.rb +45 -0
- data/spec/cnpj_cpf/cpf_spec.rb +45 -0
- data/spec/cnpj_validator_spec.rb +36 -0
- data/spec/cpf_validator_spec.rb +36 -0
- data/spec/ie/ac_spec.rb +40 -0
- data/spec/ie/al_spec.rb +33 -0
- data/spec/ie/am_spec.rb +40 -0
- data/spec/ie/ap_spec.rb +33 -0
- data/spec/ie/ba_spec.rb +63 -0
- data/spec/ie/ce_spec.rb +13 -0
- data/spec/ie/df_spec.rb +40 -0
- data/spec/ie/es_spec.rb +13 -0
- data/spec/ie/factory_spec.rb +203 -0
- data/spec/ie/go_spec.rb +40 -0
- data/spec/ie/ma_spec.rb +13 -0
- data/spec/ie/mg_spec.rb +40 -0
- data/spec/ie/ms_spec.rb +13 -0
- data/spec/ie/mt_spec.rb +40 -0
- data/spec/ie/pa_spec.rb +40 -0
- data/spec/ie/pb_spec.rb +13 -0
- data/spec/ie/pe_spec.rb +59 -0
- data/spec/ie/pi_spec.rb +13 -0
- data/spec/ie/pr_spec.rb +33 -0
- data/spec/ie/rj_spec.rb +40 -0
- data/spec/ie/rn_spec.rb +59 -0
- data/spec/ie/ro_spec.rb +59 -0
- data/spec/ie/rr_spec.rb +40 -0
- data/spec/ie/rs_spec.rb +38 -0
- data/spec/ie/sc_spec.rb +40 -0
- data/spec/ie/se_spec.rb +13 -0
- data/spec/ie/shared_examples_for_pattern1.rb +33 -0
- data/spec/ie/sp_spec.rb +42 -0
- data/spec/ie/to_spec.rb +40 -0
- data/spec/ie_validator_spec.rb +65 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/utilities.rb +3 -0
- metadata +248 -0
data/spec/ie/go_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::GO do
|
4
|
+
describe "#formatted" do
|
5
|
+
it "returns a formatted ie" do
|
6
|
+
ie = BrDocuments::IE::GO.new("123456789")
|
7
|
+
expect(ie.formatted).to eq "12.345.678-9"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#valid?" do
|
12
|
+
it "is invalid with malformed number" do
|
13
|
+
["01.390415.9", "280541-600", "1C78150A5"].each do |number|
|
14
|
+
ie = BrDocuments::IE::GO.new(number)
|
15
|
+
expect(ie).to_not be_valid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is invalid with length different to 9" do
|
20
|
+
["1234567", "122345678901"].each do |number|
|
21
|
+
ie = BrDocuments::IE::GO.new(number)
|
22
|
+
expect(ie).to_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is invalid with invalid check number" do
|
27
|
+
["903473566", "493184742"].each do |number|
|
28
|
+
ie = BrDocuments::IE::GO.new(number)
|
29
|
+
expect(ie).to_not be_valid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "is valid with valid number" do
|
34
|
+
["155432214", "916876470"].each do |number|
|
35
|
+
ie = BrDocuments::IE::GO.new(number)
|
36
|
+
expect(ie).to be_valid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/ie/ma_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "shared_examples_for_pattern1"
|
3
|
+
|
4
|
+
describe BrDocuments::IE::MA do
|
5
|
+
describe "#formatted" do
|
6
|
+
it "returns a formatted ie" do
|
7
|
+
ie = BrDocuments::IE::MA.new("123456789")
|
8
|
+
expect(ie.formatted).to eq "123456789"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it_behaves_like "a pattern1", "MA"
|
13
|
+
end
|
data/spec/ie/mg_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::MG do
|
4
|
+
describe "#formatted" do
|
5
|
+
it "returns a formatted ie" do
|
6
|
+
ie = BrDocuments::IE::MG.new("1234567890123")
|
7
|
+
expect(ie.formatted).to eq "123.456.789/0123"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#valid?" do
|
12
|
+
it "is invalid with malformed number" do
|
13
|
+
["36.311.266.571-75", "4.168.836.973-423", "560.139.778.87-BA"].each do |number|
|
14
|
+
ie = BrDocuments::IE::MG.new(number)
|
15
|
+
expect(ie).to_not be_valid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is invalid with length different to 13" do
|
20
|
+
["123456789", "1234567890123"].each do |number|
|
21
|
+
ie = BrDocuments::IE::MG.new(number)
|
22
|
+
expect(ie).to_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is invalid with invalid check number" do
|
27
|
+
["4193434759812", "9427301981832"].each do |number|
|
28
|
+
ie = BrDocuments::IE::MG.new(number)
|
29
|
+
expect(ie).to_not be_valid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "is valid with valid number" do
|
34
|
+
["4193434759899", "9427301981820"].each do |number|
|
35
|
+
ie = BrDocuments::IE::MG.new(number)
|
36
|
+
expect(ie).to be_valid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/ie/ms_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "shared_examples_for_pattern1"
|
3
|
+
|
4
|
+
describe BrDocuments::IE::MS do
|
5
|
+
describe "#formatted" do
|
6
|
+
it "returns a formatted ie" do
|
7
|
+
ie = BrDocuments::IE::MS.new("123456789")
|
8
|
+
expect(ie.formatted).to eq "123456789"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it_behaves_like "a pattern1", "MS"
|
13
|
+
end
|
data/spec/ie/mt_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::MT do
|
4
|
+
describe "#formatted" do
|
5
|
+
it "returns a formatted ie" do
|
6
|
+
ie = BrDocuments::IE::MT.new("12345678901")
|
7
|
+
expect(ie.formatted).to eq "1234567890-1"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#valid?" do
|
12
|
+
it "is invalid with malformed number" do
|
13
|
+
["82.060.187.373", "528843171-72", "AD402552219"].each do |number|
|
14
|
+
ie = BrDocuments::IE::MT.new(number)
|
15
|
+
expect(ie).to_not be_valid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is invalid with length different to 11" do
|
20
|
+
["123456789012", "123456789"].each do |number|
|
21
|
+
ie = BrDocuments::IE::MT.new(number)
|
22
|
+
expect(ie).to_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is invalid with invalid check number" do
|
27
|
+
["00404609123", "83646580222"].each do |number|
|
28
|
+
ie = BrDocuments::IE::MT.new(number)
|
29
|
+
expect(ie).to_not be_valid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "is valid with valid number" do
|
34
|
+
["00130000019", "82060187373"].each do |number|
|
35
|
+
ie = BrDocuments::IE::MT.new(number)
|
36
|
+
expect(ie).to be_valid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/ie/pa_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::PA do
|
4
|
+
describe "#formatted" do
|
5
|
+
it "returns a formatted ie" do
|
6
|
+
ie = BrDocuments::IE::PA.new("123456789")
|
7
|
+
expect(ie.formatted).to eq "12-345678-9"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#valid?" do
|
12
|
+
it "is invalid with malformed number" do
|
13
|
+
["15.361.802-7", "15-48556-93", "15-4AB752-7"].each do |number|
|
14
|
+
ie = BrDocuments::IE::PA.new(number)
|
15
|
+
expect(ie).to_not be_valid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is invalid with length different to 9" do
|
20
|
+
["1234567", "12345678901"].each do |number|
|
21
|
+
ie = BrDocuments::IE::PA.new(number)
|
22
|
+
expect(ie).to_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is invalid with invalid check number" do
|
27
|
+
["152653852", "157252799"].each do |number|
|
28
|
+
ie = BrDocuments::IE::PA.new(number)
|
29
|
+
expect(ie).to_not be_valid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "is valid with valid number" do
|
34
|
+
["159636841", "158667794"].each do |number|
|
35
|
+
ie = BrDocuments::IE::PA.new(number)
|
36
|
+
expect(ie).to be_valid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/ie/pb_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "shared_examples_for_pattern1"
|
3
|
+
|
4
|
+
describe BrDocuments::IE::PB do
|
5
|
+
describe "#formatted" do
|
6
|
+
it "returns a formatted ie" do
|
7
|
+
ie = BrDocuments::IE::PB.new("123456789")
|
8
|
+
expect(ie.formatted).to eq "12345678-9"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it_behaves_like "a pattern1", "PB"
|
13
|
+
end
|
data/spec/ie/pe_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::PE do
|
4
|
+
describe "#formatted" do
|
5
|
+
context "when having 9 digits" do
|
6
|
+
it "returns a formatted ie" do
|
7
|
+
ie = BrDocuments::IE::PE.new("123456789")
|
8
|
+
expect(ie.formatted).to eq "1234567-89"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when having 14 digits" do
|
13
|
+
it "returns a formatted ie" do
|
14
|
+
ie = BrDocuments::IE::PE.new("18100100000049")
|
15
|
+
expect(ie.formatted).to eq "18.1.001.0000004-9"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#valid?" do
|
21
|
+
it "is invalid with malformed number" do
|
22
|
+
["15711188-1", "3.661.165-41", "3AB8287-00", "18.1.001.000000-49"].each do |number|
|
23
|
+
ie = BrDocuments::IE::PE.new(number)
|
24
|
+
expect(ie).to_not be_valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is invalid with length different to 9 or 14" do
|
29
|
+
["1234567", "12345678901", "0123456789012345"].each do |number|
|
30
|
+
ie = BrDocuments::IE::PE.new(number)
|
31
|
+
expect(ie).to_not be_valid
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when having 9 digits" do
|
36
|
+
it "is invalid with invalid check number" do
|
37
|
+
ie = BrDocuments::IE::PE.new("838872602")
|
38
|
+
expect(ie).to_not be_valid
|
39
|
+
end
|
40
|
+
|
41
|
+
it "is valid with valid number" do
|
42
|
+
ie = BrDocuments::IE::PE.new("418873607")
|
43
|
+
expect(ie).to be_valid
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when having 14 digits" do
|
48
|
+
it "is invalid with invalid check number" do
|
49
|
+
ie = BrDocuments::IE::PE.new("18100100000048")
|
50
|
+
expect(ie).to_not be_valid
|
51
|
+
end
|
52
|
+
|
53
|
+
it "is valid with valid number" do
|
54
|
+
ie = BrDocuments::IE::PE.new("18100100000049")
|
55
|
+
expect(ie).to be_valid
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/ie/pi_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "shared_examples_for_pattern1"
|
3
|
+
|
4
|
+
describe BrDocuments::IE::PI do
|
5
|
+
describe "#formatted" do
|
6
|
+
it "returns a formatted ie" do
|
7
|
+
ie = BrDocuments::IE::PI.new("123456789")
|
8
|
+
expect(ie.formatted).to eq "123456789"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it_behaves_like "a pattern1", "PI"
|
13
|
+
end
|
data/spec/ie/pr_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::PR do
|
4
|
+
describe "#formatted" do
|
5
|
+
it "returns a formatted ie" do
|
6
|
+
ie = BrDocuments::IE::PR.new("1234567890")
|
7
|
+
expect(ie.formatted).to eq "12345678-90"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#valid?" do
|
12
|
+
it "is invalid with malformed number" do
|
13
|
+
["1016323-850", "10163238.50"].each do |number|
|
14
|
+
ie = BrDocuments::IE::PR.new(number)
|
15
|
+
expect(ie).to_not be_valid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is invalid with invalid check number" do
|
20
|
+
["10163238-51", "10163238-40"].each do |number|
|
21
|
+
ie = BrDocuments::IE::PR.new(number)
|
22
|
+
expect(ie).to_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is valid with valid number" do
|
27
|
+
["1016323850", "10163238-50"].each do |number|
|
28
|
+
ie = BrDocuments::IE::PR.new(number)
|
29
|
+
expect(ie).to be_valid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/ie/rj_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::RJ do
|
4
|
+
describe "#formatted" do
|
5
|
+
it "returns a formatted ie" do
|
6
|
+
ie = BrDocuments::IE::RJ.new("12345678")
|
7
|
+
expect(ie.formatted).to eq "12.345.67-8"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#valid?" do
|
12
|
+
it "is invalid with malformed number" do
|
13
|
+
["00.55.55.25", "34.09.25-08", "0A220C18"].each do |number|
|
14
|
+
ie = BrDocuments::IE::RJ.new(number)
|
15
|
+
expect(ie).to_not be_valid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is invalid with length different to 8" do
|
20
|
+
["1234567890", "12345"].each do |number|
|
21
|
+
ie = BrDocuments::IE::RJ.new(number)
|
22
|
+
expect(ie).to_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is invalid with invalid check number" do
|
27
|
+
["99228676", "48388923"].each do |number|
|
28
|
+
ie = BrDocuments::IE::RJ.new(number)
|
29
|
+
expect(ie).to_not be_valid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "is valid with valid number" do
|
34
|
+
["80172010", "31864950"].each do |number|
|
35
|
+
ie = BrDocuments::IE::RJ.new(number)
|
36
|
+
expect(ie).to be_valid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/ie/rn_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::RN do
|
4
|
+
describe "#formatted" do
|
5
|
+
context "when having 9 digits" do
|
6
|
+
it "returns a formatted ie" do
|
7
|
+
ie = BrDocuments::IE::RN.new("123456789")
|
8
|
+
expect(ie.formatted).to eq "12.345.678-9"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when having 10 digits" do
|
13
|
+
it "returns a formatted ie" do
|
14
|
+
ie = BrDocuments::IE::RN.new("1234567890")
|
15
|
+
expect(ie.formatted).to eq "12.3.456.789-0"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#valid?" do
|
21
|
+
it "is invalid with malformed number" do
|
22
|
+
["9.012.207-95", "617.964.80-7", "25.9AB.924-6"].each do |number|
|
23
|
+
ie = BrDocuments::IE::RN.new(number)
|
24
|
+
expect(ie).to_not be_valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is invalid with length different to 9 or 10" do
|
29
|
+
["12345678", "12345678901"].each do |number|
|
30
|
+
ie = BrDocuments::IE::RN.new(number)
|
31
|
+
expect(ie).to_not be_valid
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when having 9 digits" do
|
36
|
+
it "is invalid with invalid check number" do
|
37
|
+
ie = BrDocuments::IE::RN.new("794050643")
|
38
|
+
expect(ie).to_not be_valid
|
39
|
+
end
|
40
|
+
|
41
|
+
it "is valid with valid number" do
|
42
|
+
ie = BrDocuments::IE::RN.new("200400401")
|
43
|
+
expect(ie).to be_valid
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when having 10 digits" do
|
48
|
+
it "is invalid with invalid check number" do
|
49
|
+
ie = BrDocuments::IE::RN.new("1153296142")
|
50
|
+
expect(ie).to_not be_valid
|
51
|
+
end
|
52
|
+
|
53
|
+
it "is valid with valid number" do
|
54
|
+
ie = BrDocuments::IE::RN.new("2000400400")
|
55
|
+
expect(ie).to be_valid
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/ie/ro_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BrDocuments::IE::RO do
|
4
|
+
describe "#formatted" do
|
5
|
+
context "when having 9 digits" do
|
6
|
+
it "returns a formatted ie" do
|
7
|
+
ie = BrDocuments::IE::RO.new("123456789")
|
8
|
+
expect(ie.formatted).to eq "123.45678-9"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when having 14 digits" do
|
13
|
+
it "returns a formatted ie" do
|
14
|
+
ie = BrDocuments::IE::RO.new("12345678901234")
|
15
|
+
expect(ie.formatted).to eq "1234567890123-4"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#valid?" do
|
21
|
+
it "is invalid with malformed number" do
|
22
|
+
["20.049.788-6", "2.004.978-86", "937.03AB1-6"].each do |number|
|
23
|
+
ie = BrDocuments::IE::RO.new(number)
|
24
|
+
expect(ie).to_not be_valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is invalid with length different to 9 or 14" do
|
29
|
+
["1234567", "123456789012", "12345678901234567"].each do |number|
|
30
|
+
ie = BrDocuments::IE::RO.new(number)
|
31
|
+
expect(ie).to_not be_valid
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when having 9 digits" do
|
36
|
+
it "is invalid with invalid check number" do
|
37
|
+
ie = BrDocuments::IE::RO.new("134725252")
|
38
|
+
expect(ie).to_not be_valid
|
39
|
+
end
|
40
|
+
|
41
|
+
it "is valid with valid number" do
|
42
|
+
ie = BrDocuments::IE::RO.new("101625213")
|
43
|
+
expect(ie).to be_valid
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when having 14 digits" do
|
48
|
+
it "is invalid with invalid check number" do
|
49
|
+
ie = BrDocuments::IE::RO.new("02539835229263")
|
50
|
+
expect(ie).to_not be_valid
|
51
|
+
end
|
52
|
+
|
53
|
+
it "is valid with valid number" do
|
54
|
+
ie = BrDocuments::IE::RO.new("00000000625213")
|
55
|
+
expect(ie).to be_valid
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|