br_documents 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/br_documents.gemspec +1 -0
- data/circle.yml +3 -0
- data/lib/br_documents/ie/to.rb +12 -3
- data/lib/br_documents/version.rb +1 -1
- data/spec/ie/to_spec.rb +70 -13
- data/spec/ie_validator_spec.rb +40 -31
- metadata +37 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2868a841f5b9a2487fa3fa00f9c9beb4ff4920ac
|
4
|
+
data.tar.gz: f0d3e96b7388d21779b704098eec4839943800d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42d5062406d40d444454a9df7ebd2f954d12a2e7681f93148cf261d2de1b3dc7f3e308bd3df648a424e4fbe9d43d79db627ea2fd889f8656a7b633ca0620cae9
|
7
|
+
data.tar.gz: 24711a1be9598e21df60eaa4e0ed27f447d047dffb6b0637c41ebd9734466b587038dd7db215c0e24015765da2e227a6088d3161e3e25830464866981c0148e8
|
data/br_documents.gemspec
CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rspec", ">= 3.0.0"
|
27
27
|
spec.add_development_dependency "codeclimate-test-reporter"
|
28
28
|
spec.add_development_dependency "simplecov", ">= 0.9.0"
|
29
|
+
spec.add_development_dependency "byebug", "4.0.1" if RUBY_VERSION >= "2.0"
|
29
30
|
end
|
data/circle.yml
ADDED
data/lib/br_documents/ie/to.rb
CHANGED
@@ -5,13 +5,22 @@ module BrDocuments
|
|
5
5
|
class TO < Pattern1
|
6
6
|
def initialize(number)
|
7
7
|
super
|
8
|
-
|
9
|
-
|
8
|
+
if number.gsub(/(\.)|(\-)/, "").length == 9
|
9
|
+
@mask = /^(\d{2}\.\d{6}\-\d{1})$|^(\d{9})$/
|
10
|
+
@weight = [9, 8, 7, 6, 5, 4, 3, 2]
|
11
|
+
else
|
12
|
+
@mask = /^(\d{2}\.\d{2}\.\d{6}\-\d{1})$|^(\d{11})$/
|
13
|
+
@weight = [9, 8, 0, 0, 7, 6, 5, 4, 3, 2]
|
14
|
+
end
|
10
15
|
end
|
11
16
|
|
12
17
|
private
|
13
18
|
def format_ie(number)
|
14
|
-
number
|
19
|
+
if number.gsub(/(\.)|(\-)/, "").length == 9
|
20
|
+
number.sub(/(\d{2})(\d{6})(\d{1})/, "\\1.\\2-\\3")
|
21
|
+
else
|
22
|
+
number.sub(/(\d{2})(\d{2})(\d{6})(\d{1})/, "\\1.\\2.\\3-\\4")
|
23
|
+
end
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
data/lib/br_documents/version.rb
CHANGED
data/spec/ie/to_spec.rb
CHANGED
@@ -2,9 +2,20 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe BrDocuments::IE::TO do
|
4
4
|
describe "#formatted" do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
context "when having 9 digits" do
|
6
|
+
subject { BrDocuments::IE::TO.new("123456789") }
|
7
|
+
|
8
|
+
it "returns a formatted ie" do
|
9
|
+
expect(subject.formatted).to eq "12.345678-9"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when having 11 digits" do
|
14
|
+
subject { BrDocuments::IE::TO.new("12345678901") }
|
15
|
+
|
16
|
+
it "returns a formatted ie" do
|
17
|
+
expect(subject.formatted).to eq "12.34.567890-1"
|
18
|
+
end
|
8
19
|
end
|
9
20
|
end
|
10
21
|
|
@@ -16,24 +27,70 @@ describe BrDocuments::IE::TO do
|
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|
19
|
-
it "is invalid with length different
|
20
|
-
["12345678", "123456789012"].each do |number|
|
30
|
+
it "is invalid with length different of 9 or 11" do
|
31
|
+
["12345678", "1234567890", "123456789012"].each do |number|
|
21
32
|
ie = BrDocuments::IE::TO.new(number)
|
22
33
|
expect(ie).to_not be_valid
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
context "when having 9 digits" do
|
38
|
+
it "is invalid with invalid check number" do
|
39
|
+
["290227835", "294083153"].each do |number|
|
40
|
+
ie = BrDocuments::IE::TO.new(number)
|
41
|
+
expect(ie).to_not be_valid
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "is invalid with correct check number but invalid mask" do
|
46
|
+
["29-022783-6", "29.408315.4"].each do |number|
|
47
|
+
ie = BrDocuments::IE::TO.new(number)
|
48
|
+
expect(ie).to_not be_valid
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is valid with valid number" do
|
53
|
+
["290227836", "294083154"].each do |number|
|
54
|
+
ie = BrDocuments::IE::TO.new(number)
|
55
|
+
expect(ie).to be_valid
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "is valid with valid masked number" do
|
60
|
+
["29.022783-6", "29.408315-4"].each do |number|
|
61
|
+
ie = BrDocuments::IE::TO.new(number)
|
62
|
+
expect(ie).to be_valid
|
63
|
+
end
|
30
64
|
end
|
31
65
|
end
|
32
66
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
67
|
+
context "when having 11 digits" do
|
68
|
+
it "is invalid with invalid check number" do
|
69
|
+
["29023864406", "29023864409"].each do |number|
|
70
|
+
ie = BrDocuments::IE::TO.new(number)
|
71
|
+
expect(ie).to_not be_valid
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "is invalid with correct check number but invalid mask" do
|
76
|
+
["29-99.200143-6", "29.99.231741.7"].each do |number|
|
77
|
+
ie = BrDocuments::IE::TO.new(number)
|
78
|
+
expect(ie).to_not be_valid
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "is valid with valid number" do
|
83
|
+
["29992001436", "29992317417"].each do |number|
|
84
|
+
ie = BrDocuments::IE::TO.new(number)
|
85
|
+
expect(ie).to be_valid
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "is valid with valid masked number" do
|
90
|
+
["29.99.200143-6", "29.99.231741-7"].each do |number|
|
91
|
+
ie = BrDocuments::IE::TO.new(number)
|
92
|
+
expect(ie).to be_valid
|
93
|
+
end
|
37
94
|
end
|
38
95
|
end
|
39
96
|
end
|
data/spec/ie_validator_spec.rb
CHANGED
@@ -1,72 +1,81 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe IeValidator do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
allow(
|
8
|
-
allow(
|
9
|
-
allow(
|
10
|
-
allow(
|
11
|
-
|
4
|
+
let(:record) { double("model") }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(record).to receive(:uf) {"SC"}
|
8
|
+
allow(record).to receive(:errors).and_return([])
|
9
|
+
allow(record.errors).to receive(:messages).and_return({})
|
10
|
+
allow(record.errors).to receive(:add) do | attribute, error |
|
11
|
+
record.errors.messages[attribute] = [error]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
subject {
|
15
|
+
subject { IeValidator.new(attributes: "ie", uf: "uf") }
|
16
16
|
|
17
17
|
context "when IE's number is valid" do
|
18
|
+
before { subject.validate_each(record, "ie", "253667852") }
|
19
|
+
|
18
20
|
it "doesn't add errors in model" do
|
19
|
-
|
20
|
-
expect(@mock.errors.messages).to be_empty
|
21
|
+
expect(record.errors.messages).to be_empty
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
context "when IE is 'ISENTO'" do
|
26
|
+
before { subject.validate_each(record, "ie", "ISENTO") }
|
27
|
+
|
25
28
|
it "doesn't add errors in model" do
|
26
|
-
|
27
|
-
expect(@mock.errors.messages).to be_empty
|
29
|
+
expect(record.errors.messages).to be_empty
|
28
30
|
end
|
29
|
-
end
|
31
|
+
end
|
30
32
|
|
31
33
|
context "when IE is blank" do
|
34
|
+
before { subject.validate_each(record, "ie", "") }
|
35
|
+
|
32
36
|
it "doesn't add errors in model" do
|
33
|
-
|
34
|
-
expect(@mock.errors.messages).to be_empty
|
37
|
+
expect(record.errors.messages).to be_empty
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
41
|
context "when IE is invalid" do
|
42
|
+
before { subject.validate_each(record, "ie", "253667853") }
|
43
|
+
|
39
44
|
it "adds errors in model" do
|
40
|
-
|
41
|
-
expect(@mock.errors.messages).to_not be_empty
|
45
|
+
expect(record.errors.messages).to_not be_empty
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
45
49
|
context "when UF is invalid" do
|
50
|
+
before do
|
51
|
+
allow(record).to receive(:uf){""}
|
52
|
+
subject.validate_each(record, "ie", "253667852")
|
53
|
+
end
|
54
|
+
|
46
55
|
it "adds error in model" do
|
47
|
-
|
48
|
-
subject.validate_each(@mock, "ie", "253667852")
|
49
|
-
expect(@mock.errors.messages["ie"]).to eql [t("validator.ie.uf.invalid")]
|
56
|
+
expect(record.errors.messages["ie"]).to eql [t("validator.ie.uf.invalid")]
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
53
60
|
context "when it can't find attribute uf in model" do
|
61
|
+
before do
|
62
|
+
allow(record).to receive(:uf).and_raise(NoMethodError)
|
63
|
+
subject.validate_each(record, "ie", "253667852")
|
64
|
+
end
|
65
|
+
|
54
66
|
it "adds error in model" do
|
55
|
-
|
56
|
-
|
57
|
-
expect(@mock.errors.messages[:base]).to eql [
|
58
|
-
t("validator.ie.uf.no_present", uf: "uf")
|
59
|
-
]
|
67
|
+
expect(record.errors.messages[:base]).to eql [
|
68
|
+
t("validator.ie.uf.no_present", uf: "uf")]
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
63
72
|
context "when attribute uf is not defined" do
|
73
|
+
subject { IeValidator.new(attributes: "ie") }
|
74
|
+
before { subject.validate_each(record, "ie", "253667852") }
|
75
|
+
|
64
76
|
it "adds error in model" do
|
65
|
-
|
66
|
-
|
67
|
-
expect(@mock.errors.messages[:base]).to eql [
|
68
|
-
t("validator.ie.uf.no_configured")
|
69
|
-
]
|
77
|
+
expect(record.errors.messages[:base]).to eql [
|
78
|
+
t("validator.ie.uf.no_configured")]
|
70
79
|
end
|
71
80
|
end
|
72
81
|
end
|
metadata
CHANGED
@@ -1,113 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: br_documents
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ASSEINFO - Sistemas de Informação
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.6.5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.6.5
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 10.1.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 10.1.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 3.0.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.0.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: codeclimate-test-reporter
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 0.9.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.9.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 4.0.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 4.0.1
|
111
125
|
description: Validates brazilian documents like CPF, CNPJ and IE.
|
112
126
|
email:
|
113
127
|
- asseinfo@asseinfo.com.br
|
@@ -115,13 +129,14 @@ executables: []
|
|
115
129
|
extensions: []
|
116
130
|
extra_rdoc_files: []
|
117
131
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .rspec
|
120
|
-
- .travis.yml
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
121
135
|
- Gemfile
|
122
136
|
- README.md
|
123
137
|
- Rakefile
|
124
138
|
- br_documents.gemspec
|
139
|
+
- circle.yml
|
125
140
|
- config/locales/pt-BR.yml
|
126
141
|
- lib/br_documents.rb
|
127
142
|
- lib/br_documents/cnpj_cpf/cnpj.rb
|
@@ -209,17 +224,17 @@ require_paths:
|
|
209
224
|
- lib
|
210
225
|
required_ruby_version: !ruby/object:Gem::Requirement
|
211
226
|
requirements:
|
212
|
-
- -
|
227
|
+
- - ">="
|
213
228
|
- !ruby/object:Gem::Version
|
214
229
|
version: '0'
|
215
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
231
|
requirements:
|
217
|
-
- -
|
232
|
+
- - ">="
|
218
233
|
- !ruby/object:Gem::Version
|
219
234
|
version: '0'
|
220
235
|
requirements: []
|
221
236
|
rubyforge_project:
|
222
|
-
rubygems_version: 2.
|
237
|
+
rubygems_version: 2.4.2
|
223
238
|
signing_key:
|
224
239
|
specification_version: 4
|
225
240
|
summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with
|
@@ -261,4 +276,3 @@ test_files:
|
|
261
276
|
- spec/ie_validator_spec.rb
|
262
277
|
- spec/spec_helper.rb
|
263
278
|
- spec/support/utilities.rb
|
264
|
-
has_rdoc:
|