cpf_validation 0.2.0 → 0.3.0
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/.gitignore +1 -0
- data/{cpf_validaton.gemspec → cpf_validation.gemspec} +1 -0
- data/lib/validates_cpf.rb +2 -2
- data/lib/validates_cpf/version.rb +1 -1
- data/spec/lib/validates_cpf_spec.rb +17 -17
- data/spec/spec_helper.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27f7b7ce36364aca809822738025fe05bbff8a45
|
4
|
+
data.tar.gz: e24ee2736c1d567811905dc0069853f39e089883
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0b80902322a659635171c357bd87d31de5f1e7fa923927aaf77dc805a2e51575a47d92b00b5da560d677bac1f8f850e81d977cfabc3d6b2c3eb1ca0604cb2fe
|
7
|
+
data.tar.gz: 943a0d10e3f8645543a506ea81680c86278aab027c1b0d91c193bfd64a02d510ac7388e0013d1f96304b7067eede2c668b01f1d81bbc8f0a308867ef745a3ad1
|
data/.gitignore
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/GabrielLidenor/cpf_validation"
|
11
11
|
s.summary = %q{CPF ActiveModel validation}
|
12
12
|
s.description = %q{CPF validation for ActiveModel and Rails}
|
13
|
+
s.license = 'MIT'
|
13
14
|
|
14
15
|
s.rubyforge_project = "validates_cpf"
|
15
16
|
|
data/lib/validates_cpf.rb
CHANGED
@@ -6,14 +6,14 @@ module ActiveModel
|
|
6
6
|
class CpfValidator < ActiveModel::EachValidator
|
7
7
|
include ValidatesCpf
|
8
8
|
|
9
|
-
def validate_each(record,
|
9
|
+
def validate_each(record, attribute, value)
|
10
10
|
return if (options[:allow_nil] and value.nil?) or (options[:allow_blank] and value.blank?)
|
11
11
|
return if (options[:if] == false) or (options[:unless] == true)
|
12
12
|
return if (options[:on].to_s == 'create' and not record.new_record?) or (options[:on].to_s == 'update' and record.new_record?)
|
13
13
|
|
14
14
|
if value.to_s.gsub(/[^0-9]/, '').length <= 11
|
15
15
|
if (not value.to_s.match(/\A\d{11}\z/) and not value.to_s.match(/\A\d{3}\.\d{3}\.\d{3}\-\d{2}\z/)) or not Cpf.valid?(value)
|
16
|
-
record.errors.add(
|
16
|
+
record.errors.add(attribute, 'The CPF is invalid')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -12,20 +12,20 @@ describe ValidatesCpf do
|
|
12
12
|
|
13
13
|
invalid_cpfs.each do |cpf|
|
14
14
|
it "value is #{cpf}" do
|
15
|
-
person = Person.new(:
|
15
|
+
person = Person.new(code: cpf)
|
16
16
|
person.validates_cpf(:code)
|
17
17
|
expect(person.errors).to_not be_empty
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'value is nil' do
|
22
|
-
person = Person.new(:
|
22
|
+
person = Person.new(code: nil)
|
23
23
|
person.validates_cpf(:code)
|
24
24
|
expect(person.errors).to_not be_empty
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'value is empty' do
|
28
|
-
person = Person.new(:
|
28
|
+
person = Person.new(code: '')
|
29
29
|
person.validates_cpf(:code)
|
30
30
|
expect(person.errors).to_not be_empty
|
31
31
|
end
|
@@ -35,7 +35,7 @@ describe ValidatesCpf do
|
|
35
35
|
|
36
36
|
blocked_cpfs.each do |cpf|
|
37
37
|
it "is a well know invalid number: #{cpf}" do
|
38
|
-
person = Person.new(:
|
38
|
+
person = Person.new(code: cpf)
|
39
39
|
person.validates_cpf(:code)
|
40
40
|
expect(person.errors).to_not be_empty
|
41
41
|
end
|
@@ -44,48 +44,48 @@ describe ValidatesCpf do
|
|
44
44
|
|
45
45
|
context 'should be valid when' do
|
46
46
|
it 'value is 80033787883' do
|
47
|
-
person = Person.new(:
|
47
|
+
person = Person.new(code: '80033787883')
|
48
48
|
person.validates_cpf(:code)
|
49
49
|
expect(person.errors).to be_empty
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'value is 800.337.878-83' do
|
53
|
-
person = Person.new(:
|
53
|
+
person = Person.new(code: '800.337.878-83')
|
54
54
|
person.validates_cpf(:code)
|
55
55
|
expect(person.errors).to be_empty
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'value is nil and :allow_nil or :allow_blank is true' do
|
59
|
-
person = Person.new(:
|
60
|
-
person.validates_cpf(:code, :
|
59
|
+
person = Person.new(code: nil)
|
60
|
+
person.validates_cpf(:code, allow_nil: true)
|
61
61
|
expect(person.errors).to be_empty
|
62
|
-
person.validates_cpf(:code, :
|
62
|
+
person.validates_cpf(:code, allow_blank: true)
|
63
63
|
expect(person.errors).to be_empty
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'value is empty and :allow_blank is true' do
|
67
67
|
person = Person.new(:code => '')
|
68
|
-
person.validates_cpf(:code, :
|
68
|
+
person.validates_cpf(:code, allow_blank: true)
|
69
69
|
expect(person.errors).to be_empty
|
70
|
-
person.validates_cpf(:code, :
|
70
|
+
person.validates_cpf(:code, allow_nil: true)
|
71
71
|
expect(person.errors).to_not be_empty
|
72
72
|
end
|
73
73
|
|
74
74
|
it ':if option evaluates false' do
|
75
|
-
person = Person.new(:
|
76
|
-
person.validates_cpf(:code, :
|
75
|
+
person = Person.new(code: '12345678901')
|
76
|
+
person.validates_cpf(:code, if: false)
|
77
77
|
expect(person.errors).to be_empty
|
78
78
|
end
|
79
79
|
|
80
80
|
it ':unless option evaluates true' do
|
81
|
-
person = Person.new(:
|
82
|
-
person.validates_cpf(:code, :
|
81
|
+
person = Person.new(code: '12345678901')
|
82
|
+
person.validates_cpf(:code, unless: true)
|
83
83
|
expect(person.errors).to be_empty
|
84
84
|
end
|
85
85
|
|
86
86
|
it ':on option is :update and the model instance is a new record' do
|
87
|
-
person = Person.new(:
|
88
|
-
person.validates_cpf(:code, :
|
87
|
+
person = Person.new(code: '12345678901')
|
88
|
+
person.validates_cpf(:code, on: :update)
|
89
89
|
expect(person.errors).to be_empty
|
90
90
|
end
|
91
91
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpf_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Lidenor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -78,7 +78,7 @@ files:
|
|
78
78
|
- Gemfile
|
79
79
|
- README.rdoc
|
80
80
|
- Rakefile
|
81
|
-
-
|
81
|
+
- cpf_validation.gemspec
|
82
82
|
- lib/validates_cpf.rb
|
83
83
|
- lib/validates_cpf/.DS_Store
|
84
84
|
- lib/validates_cpf/cpf.rb
|
@@ -86,7 +86,8 @@ files:
|
|
86
86
|
- spec/lib/validates_cpf_spec.rb
|
87
87
|
- spec/spec_helper.rb
|
88
88
|
homepage: https://github.com/GabrielLidenor/cpf_validation
|
89
|
-
licenses:
|
89
|
+
licenses:
|
90
|
+
- MIT
|
90
91
|
metadata: {}
|
91
92
|
post_install_message:
|
92
93
|
rdoc_options: []
|
@@ -104,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
105
|
version: '0'
|
105
106
|
requirements: []
|
106
107
|
rubyforge_project: validates_cpf
|
107
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.5.1
|
108
109
|
signing_key:
|
109
110
|
specification_version: 4
|
110
111
|
summary: CPF ActiveModel validation
|