br_documents 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/br_documents/ie_validator.rb +13 -3
- data/lib/br_documents/version.rb +1 -1
- data/spec/ie_validator_spec.rb +8 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbf43d2ef6c29844d3513e8c69588f27562b962f
|
4
|
+
data.tar.gz: 2f22722e1d6a0952cf321e84c15cb0ad860fbede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 703625b35d4663fa6ea603545c52ec0ebd15181b28aae06061549d61231c19ba55f5b9563f62858aafac6505d34a786f26595cef54c5a324fcbe23e1b15692f8
|
7
|
+
data.tar.gz: b1eeb6ffcfbb99d937276189c652de6a19573dee2eccd59de247762411797b251918dbcef87440c76ca525fdc37dcbf54c861abe692572764cbfba2a02a875a7
|
data/.travis.yml
CHANGED
@@ -31,15 +31,25 @@ class IeValidator < ActiveModel::EachValidator
|
|
31
31
|
|
32
32
|
def ie_valid?(record, attribute, value)
|
33
33
|
begin
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
if (not number_valid?(record, value)) && (not exempted?(value))
|
35
|
+
record.errors.add(attribute, :invalid)
|
36
|
+
end
|
37
37
|
rescue ArgumentError => ex
|
38
38
|
record.errors.add(attribute, ex.message)
|
39
39
|
end
|
40
40
|
record.errors.messages.empty?
|
41
41
|
end
|
42
42
|
|
43
|
+
def number_valid?(record, value)
|
44
|
+
uf = read_uf(record)
|
45
|
+
ie_number = BrDocuments::IE::Factory.create(uf, value)
|
46
|
+
ie_number.valid?
|
47
|
+
end
|
48
|
+
|
49
|
+
def exempted?(value)
|
50
|
+
"isento".casecmp(value) == 0
|
51
|
+
end
|
52
|
+
|
43
53
|
def read_uf(record)
|
44
54
|
attribute = record
|
45
55
|
options[:uf].split("#").each do | field |
|
data/lib/br_documents/version.rb
CHANGED
data/spec/ie_validator_spec.rb
CHANGED
@@ -14,13 +14,20 @@ describe IeValidator do
|
|
14
14
|
|
15
15
|
subject { @validator }
|
16
16
|
|
17
|
-
context "when IE is valid" do
|
17
|
+
context "when IE's number is valid" do
|
18
18
|
it "doesn't add errors in model" do
|
19
19
|
subject.validate_each(@mock, "ie", "253667852")
|
20
20
|
expect(@mock.errors.messages).to be_empty
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
context "when IE is 'ISENTO'" do
|
25
|
+
it "doesn't add errors in model" do
|
26
|
+
subject.validate_each(@mock, "ie", "ISENTO")
|
27
|
+
expect(@mock.errors.messages).to be_empty
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
24
31
|
context "when IE is blank" do
|
25
32
|
it "doesn't add errors in model" do
|
26
33
|
subject.validate_each(@mock, "ie", "")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
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: 2014-
|
11
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.2.2
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with
|