validates_cpf 2.0.1 → 3.0.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 +5 -13
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -1
- data/.travis.yml +7 -14
- data/Gemfile +3 -1
- data/{LICENSE → LICENSE.md} +0 -0
- data/README.md +22 -6
- data/Rakefile +6 -4
- data/gemfiles/Gemfile.rails4 +1 -1
- data/gemfiles/Gemfile.rails5 +5 -0
- data/lib/validates_cpf.rb +2 -0
- data/lib/validates_cpf/cpf.rb +11 -11
- data/lib/validates_cpf/cpf_validator.rb +9 -1
- data/lib/validates_cpf/require_a_valid_cpf_matcher.rb +9 -4
- data/lib/validates_cpf/version.rb +3 -1
- data/spec/cpf_validator_spec.rb +51 -0
- data/spec/fake_app/user.rb +7 -12
- data/spec/shoulda/matchers/active_model/require_a_valid_cpf_matcher_spec.rb +11 -0
- data/spec/spec_helper.rb +19 -2
- data/spec/validates_cpf/cpf_spec.rb +84 -63
- data/validates_cpf.gemspec +17 -10
- metadata +75 -34
- data/gemfiles/Gemfile.rails3 +0 -5
- data/spec/fake_app/admin.rb +0 -3
- data/spec/validates_cpf/require_a_valid_cpf_matcher_spec.rb +0 -20
- data/spec/validates_cpf_spec.rb +0 -42
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MDJmYTRiNmE4NjIwMjhkOTFjNjBhMzEwM2UxZjkwMzNmNWEwN2VjNA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c63e36872345aafbf0fb180cdb45d2f7c6874e43582c3495c062b6cc842bbcb
|
4
|
+
data.tar.gz: 3b721a3c68eedb4689bde07eb8ff53bd132cca531a445224476590afa0b58247
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NDA0NzM3NDA5MWJiZmRhMzhiZDFjMGFiYWY5N2U5MjA1OTQ5ZjM3M2I4ODc1
|
11
|
-
YmE1NDgzMDcyYmQzYzVlN2NiMzk1ZWQ5OTM3OTdjNmY2NTFlOTA=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MjRlMjFjY2U4MTFiMWVjYzQxMGI3NmFmOWMwYmFkMzU1MzNiZWY2ODFkZmNh
|
14
|
-
MzQzOWFiNjk0NDg2OWJhNzcwNzg2N2IyYzQxNjBlOTIyYzkwZDU2YTQwMDdm
|
15
|
-
ODcxOWIzZmZiYWEyYzRmNGM1YzNhNTM0NGYwYzI1YTY5ZmEyMmU=
|
6
|
+
metadata.gz: d3028bb83e97784e3d5cc950a3a1067f21c63b5cf521e3641f5134b03fd2b367367d179b27379a61fc0b32a46710712f64d6c6bf58e9e98250e961242e588ccb
|
7
|
+
data.tar.gz: 1ebd89dcb90fdfe3fb37d170021fcada0c4d294ebb41fe13708e497cb40b13ed3046f7a7343b69675151da3db7cb27ff37224634aa3e557cf36dc5eeaddfc791
|
data/.rubocop.yml
ADDED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.2
|
data/.travis.yml
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
rvm:
|
2
|
-
-
|
3
|
-
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
- ree
|
2
|
+
- 2.2
|
3
|
+
- 2.3
|
4
|
+
- 2.4
|
5
|
+
- 2.5
|
7
6
|
gemfile:
|
8
|
-
- gemfiles/Gemfile.rails3
|
9
7
|
- gemfiles/Gemfile.rails4
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
gemfile: gemfiles/Gemfile.rails4
|
14
|
-
- rvm: 1.9.2
|
15
|
-
gemfile: gemfiles/Gemfile.rails4
|
16
|
-
- rvm: ree
|
17
|
-
gemfile: gemfiles/Gemfile.rails4
|
8
|
+
- gemfiles/Gemfile.rails5
|
9
|
+
before_script:
|
10
|
+
- bundle exec rubocop
|
data/Gemfile
CHANGED
data/{LICENSE → LICENSE.md}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/validates_cpf) [](http://travis-ci.org/plribeiro3000/validates_cpf) [](https://gemnasium.com/plribeiro3000/validates_cpf) [](https://coveralls.io/r/plribeiro3000/validates_cpf) [](https://codeclimate.com/github/plribeiro3000/validates_cpf)
|
4
4
|
|
5
|
-
Validates cpf and test it in a simple way
|
5
|
+
Validates cpf and test it in a simple way. Depends on ruby `>= 2.2`. For older ruby versions use the version `2` series.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -24,16 +24,32 @@ Just use as any other validator:
|
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
class User < ActiveRecord::Base
|
27
|
-
|
27
|
+
validates :cpf, cpf: true
|
28
28
|
end
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
To force the attribute to be masked pass option `mask`:
|
32
32
|
|
33
|
-
|
33
|
+
```ruby
|
34
|
+
class User < ActiveRecord::Base
|
35
|
+
validates :cpf, cpf: { mask: true }
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Testing
|
40
|
+
|
41
|
+
Require the matcher:
|
34
42
|
|
35
|
-
|
36
|
-
|
43
|
+
```ruby
|
44
|
+
require 'validates_cpf/require_a_valid_matcher'
|
45
|
+
```
|
46
|
+
|
47
|
+
Use in your tests:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
it { is_expected.to require_a_valid_cpf } # It will test the attribute :cpf by default
|
51
|
+
it { is_expected.to require_a_valid_cpf(:id) }
|
52
|
+
```
|
37
53
|
|
38
54
|
## Contributing
|
39
55
|
|
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
3
5
|
|
4
6
|
RSpec::Core::RakeTask.new
|
5
7
|
|
6
|
-
desc
|
7
|
-
task :
|
8
|
+
desc 'Default Task'
|
9
|
+
task default: [:spec]
|
data/gemfiles/Gemfile.rails4
CHANGED
data/lib/validates_cpf.rb
CHANGED
data/lib/validates_cpf/cpf.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ValidatesCpf
|
2
4
|
class Cpf
|
3
5
|
def initialize(number)
|
4
6
|
number =~ /^(\d{3}\.?\d{3}\.?\d{3})-?(\d{2})$/
|
5
7
|
@number = number
|
6
|
-
@pure_number =
|
7
|
-
@result =
|
8
|
-
@cleaned_number = @pure_number.nil? ? nil : @number.gsub(/[\.-]/,
|
8
|
+
@pure_number = Regexp.last_match(1)
|
9
|
+
@result = Regexp.last_match(2)
|
10
|
+
@cleaned_number = @pure_number.nil? ? nil : @number.gsub(/[\.-]/, '')
|
9
11
|
format_number! if @pure_number
|
10
12
|
end
|
11
13
|
|
@@ -15,31 +17,29 @@ module ValidatesCpf
|
|
15
17
|
check_cpf
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
@number
|
20
|
-
end
|
20
|
+
attr_reader :number
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def check_cpf
|
25
|
-
return false if @cleaned_number.length != 11
|
25
|
+
return false if @cleaned_number.length != 11 || @cleaned_number.scan(/\d/).uniq.length == 1
|
26
26
|
@result == first_digit_verifier + second_digit_verifier
|
27
27
|
end
|
28
28
|
|
29
29
|
def first_digit_verifier
|
30
30
|
sum = multiply_and_sum([10, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number)
|
31
|
-
digit_verifier(sum%11).to_s
|
31
|
+
digit_verifier(sum % 11).to_s
|
32
32
|
end
|
33
33
|
|
34
34
|
def second_digit_verifier
|
35
35
|
sum = multiply_and_sum([11, 10, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number + first_digit_verifier)
|
36
|
-
digit_verifier(sum%11).to_s
|
36
|
+
digit_verifier(sum % 11).to_s
|
37
37
|
end
|
38
38
|
|
39
39
|
def multiply_and_sum(array, number)
|
40
40
|
multiplied = []
|
41
41
|
number.scan(/\d{1}/).each_with_index { |e, i| multiplied[i] = e.to_i * array[i] }
|
42
|
-
multiplied.inject { |s,e| s + e }
|
42
|
+
multiplied.inject { |s, e| s + e }
|
43
43
|
end
|
44
44
|
|
45
45
|
def digit_verifier(rest)
|
@@ -48,7 +48,7 @@ module ValidatesCpf
|
|
48
48
|
|
49
49
|
def format_number!
|
50
50
|
@cleaned_number =~ /(\d{3})(\d{3})(\d{3})(\d{2})/
|
51
|
-
@number = "#{
|
51
|
+
@number = "#{Regexp.last_match(1)}.#{Regexp.last_match(2)}.#{Regexp.last_match(3)}-#{Regexp.last_match(4)}"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -1,5 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class CpfValidator < ActiveModel::EachValidator
|
2
4
|
def validate_each(record, attribute, value)
|
3
|
-
|
5
|
+
cpf = ValidatesCpf::Cpf.new(value)
|
6
|
+
|
7
|
+
if cpf.valid?
|
8
|
+
record.send("#{attribute}=", cpf.number) if options[:mask]
|
9
|
+
else
|
10
|
+
record.errors.add(attribute, :invalid, options)
|
11
|
+
end
|
4
12
|
end
|
5
13
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'shoulda-matchers'
|
2
|
-
require 'active_support/core_ext/array/wrap'
|
3
4
|
|
4
5
|
module Shoulda
|
5
6
|
module Matchers
|
@@ -10,14 +11,18 @@ module Shoulda
|
|
10
11
|
|
11
12
|
class RequireAValidCpfMatcher < ValidationMatcher
|
12
13
|
def description
|
13
|
-
'
|
14
|
+
'requires a valid CPF'
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
'does not require a valid CPF'
|
14
19
|
end
|
15
20
|
|
16
21
|
def matches?(subject)
|
17
|
-
|
22
|
+
super(subject)
|
18
23
|
disallows_value_of('123456') && allows_value_of('897.546.112-20')
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
23
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CpfValidator do
|
6
|
+
let(:user) { User.new }
|
7
|
+
|
8
|
+
context 'with invalid cpf' do
|
9
|
+
before do
|
10
|
+
user.cpf = '12345'
|
11
|
+
I18n.stub(:t).with(:'activerecord.errors.models.user.attributes.cpf.invalid',
|
12
|
+
default: :'activerecord.errors.messages.invalid').and_return('is invalid')
|
13
|
+
user.valid?
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'invalidates the object' do
|
17
|
+
expect(user).not_to be_valid
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets an error message' do
|
21
|
+
expect(user.errors[:cpf]).to match(['is invalid'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with valid cpf' do
|
26
|
+
before do
|
27
|
+
user.cpf = '11144477735'
|
28
|
+
user.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'validates the object' do
|
32
|
+
expect(user).to be_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not set an error message' do
|
36
|
+
expect(user.errors[:cpf]).to be_blank
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with nil value' do
|
41
|
+
before { user.cpf = nil }
|
42
|
+
|
43
|
+
it 'validates the object' do
|
44
|
+
expect(user).to be_valid
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'does not set an error message' do
|
48
|
+
expect(user.errors[:cpf]).to be_blank
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/fake_app/user.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
|
2
|
-
include ActiveModel::Validations
|
3
|
-
include ActiveModel::Conversion
|
4
|
-
extend ActiveModel::Naming
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
3
|
+
class User
|
4
|
+
include ActiveModel::Model
|
7
5
|
|
8
|
-
|
6
|
+
attr_accessor :cpf, :masked_cpf, :name
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
8
|
+
validates :cpf, cpf: true
|
9
|
+
validates :masked_cpf, cpf: { mask: true }
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Shoulda::Matchers::ActiveModel::RequireAValidCpfMatcher do
|
6
|
+
subject { User.new }
|
7
|
+
|
8
|
+
it { is_expected.to require_a_valid_cpf(:cpf) }
|
9
|
+
it { is_expected.to require_a_valid_cpf }
|
10
|
+
it { is_expected.not_to require_a_valid_cpf(:name) }
|
11
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rspec'
|
2
4
|
require 'active_model'
|
3
5
|
require 'coveralls'
|
6
|
+
require 'jazz_fingers'
|
7
|
+
require 'shoulda-matchers'
|
8
|
+
|
9
|
+
JazzFingers.configure do |config|
|
10
|
+
config.colored_prompt = false
|
11
|
+
config.awesome_print = false
|
12
|
+
config.coolline = false
|
13
|
+
config.application_name = ValidatesCpf
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'jazz_fingers/setup'
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.include Shoulda::Matchers::ActiveModel
|
20
|
+
end
|
4
21
|
|
5
22
|
Coveralls.wear!
|
6
23
|
|
7
|
-
|
8
|
-
|
24
|
+
require File.expand_path('lib/validates_cpf')
|
25
|
+
require File.expand_path('spec/fake_app/user')
|
@@ -1,95 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe ValidatesCpf::Cpf do
|
4
|
-
|
5
|
-
it "345.65.67.3 as number" do
|
6
|
-
ValidatesCpf::Cpf.new('345.65.67.3').should_not be_valid
|
7
|
-
end
|
5
|
+
RSpec.describe ValidatesCpf::Cpf do
|
6
|
+
let(:user) { User.new }
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
it 'rejects 345.65.67.3' do
|
9
|
+
expect(ValidatesCpf::Cpf.new('345.65.67.3')).not_to be_valid
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
it 'rejects 567.765-87698' do
|
13
|
+
expect(ValidatesCpf::Cpf.new('567.765-87698')).not_to be_valid
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it 'rejects 345456-654-01' do
|
17
|
+
expect(ValidatesCpf::Cpf.new('345456-654-01')).not_to be_valid
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
it 'rejects 123456' do
|
21
|
+
expect(ValidatesCpf::Cpf.new('123456')).not_to be_valid
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
it 'rejects 23342345699' do
|
25
|
+
expect(ValidatesCpf::Cpf.new('23342345699')).not_to be_valid
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
it 'rejects 34.543.567-98' do
|
29
|
+
expect(ValidatesCpf::Cpf.new('34.543.567-98')).not_to be_valid
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
it 'rejects 456.676456-87' do
|
33
|
+
expect(ValidatesCpf::Cpf.new('456.676456-87')).not_to be_valid
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
it 'rejects 333333333-33' do
|
37
|
+
expect(ValidatesCpf::Cpf.new('333333333-33')).not_to be_valid
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
it 'rejects 00000000000' do
|
41
|
+
expect(ValidatesCpf::Cpf.new('00000000000')).not_to be_valid
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
it 'rejects 000.000.000-00' do
|
45
|
+
expect(ValidatesCpf::Cpf.new('000.000.000-00')).not_to be_valid
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
48
|
+
it 'rejects 111.444.777-3500' do
|
49
|
+
expect(ValidatesCpf::Cpf.new('111.444.777-3500')).not_to be_valid
|
52
50
|
end
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
52
|
+
it 'rejects 11144477735AB' do
|
53
|
+
expect(ValidatesCpf::Cpf.new('11144477735AB')).not_to be_valid
|
54
|
+
end
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
it 'accepts blank string' do
|
57
|
+
expect(ValidatesCpf::Cpf.new('')).to be_valid
|
58
|
+
end
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
it 'accepts nil' do
|
61
|
+
expect(ValidatesCpf::Cpf.new(nil)).to be_valid
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'accepts 111.444.777-35' do
|
65
|
+
expect(ValidatesCpf::Cpf.new('111.444.777-35')).to be_valid
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
68
|
+
it 'accepts 11144477735' do
|
69
|
+
expect(ValidatesCpf::Cpf.new('11144477735')).to be_valid
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'accepts 111.444777-35' do
|
73
|
+
expect(ValidatesCpf::Cpf.new('111.444777-35')).to be_valid
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'accepts 111444.777-35' do
|
77
|
+
expect(ValidatesCpf::Cpf.new('111444.777-35')).to be_valid
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'accepts 111.444.77735' do
|
81
|
+
expect(ValidatesCpf::Cpf.new('111.444.77735')).to be_valid
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'with a valid value on not masked attribute' do
|
85
|
+
before do
|
86
|
+
user.cpf = '11144477735'
|
87
|
+
user.valid?
|
69
88
|
end
|
70
89
|
|
71
|
-
it
|
72
|
-
|
90
|
+
it 'leaves the original value' do
|
91
|
+
expect(user.cpf).to eq('11144477735')
|
73
92
|
end
|
93
|
+
end
|
74
94
|
|
75
|
-
|
76
|
-
|
95
|
+
context 'with a valid value on masked attribute' do
|
96
|
+
before do
|
97
|
+
user.masked_cpf = '11144477735'
|
98
|
+
user.valid?
|
77
99
|
end
|
78
100
|
|
79
|
-
it
|
80
|
-
|
101
|
+
it 'masks the original value' do
|
102
|
+
expect(user.masked_cpf).to eq('111.444.777-35')
|
81
103
|
end
|
82
104
|
end
|
83
105
|
|
84
|
-
context
|
85
|
-
|
86
|
-
|
106
|
+
context 'with an invalid value' do
|
107
|
+
before do
|
108
|
+
user.cpf = '123456'
|
109
|
+
user.valid?
|
87
110
|
end
|
88
|
-
end
|
89
111
|
|
90
|
-
|
91
|
-
|
92
|
-
ValidatesCpf::Cpf.new('123456').number.should == '123456'
|
112
|
+
it 'leaves the original value' do
|
113
|
+
expect(user.cpf).to eq('123456')
|
93
114
|
end
|
94
115
|
end
|
95
116
|
end
|
data/validates_cpf.gemspec
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require File.expand_path('lib/validates_cpf/version', __dir__)
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
5
7
|
gem.name = 'validates_cpf'
|
6
8
|
gem.version = ValidatesCpf::VERSION
|
7
|
-
gem.authors =
|
8
|
-
gem.email =
|
9
|
-
gem.summary =
|
9
|
+
gem.authors = 'Paulo Henrique Lopes Ribeiro'
|
10
|
+
gem.email = 'plribeiro3000@gmail.com'
|
11
|
+
gem.summary = 'Validates CPF and test it with matchers in a simple way.'
|
10
12
|
|
11
13
|
gem.files = `git ls-files`.split("\n")
|
12
14
|
gem.test_files = `git ls-files -- {test,spec,features,examples,gemfiles}/*`.split("\n")
|
13
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
-
gem.require_paths = %w
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
16
|
+
gem.require_paths = %w[lib]
|
17
|
+
|
18
|
+
gem.required_ruby_version = '>= 2.2'
|
15
19
|
|
16
20
|
gem.license = 'MIT'
|
17
21
|
|
22
|
+
gem.add_development_dependency 'coveralls'
|
23
|
+
gem.add_development_dependency 'jazz_fingers'
|
18
24
|
gem.add_development_dependency 'rake'
|
19
25
|
gem.add_development_dependency 'rspec'
|
20
|
-
gem.add_development_dependency '
|
21
|
-
gem.add_development_dependency '
|
26
|
+
gem.add_development_dependency 'rubocop'
|
27
|
+
gem.add_development_dependency 'rubocop-rspec'
|
28
|
+
gem.add_development_dependency 'shoulda-matchers'
|
22
29
|
|
23
30
|
gem.add_runtime_dependency 'activemodel'
|
24
|
-
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_cpf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Henrique Lopes Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coveralls
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jazz_fingers
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rake
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
|
-
- -
|
45
|
+
- - ">="
|
18
46
|
- !ruby/object:Gem::Version
|
19
47
|
version: '0'
|
20
48
|
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- -
|
52
|
+
- - ">="
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rspec
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
|
-
- -
|
59
|
+
- - ">="
|
32
60
|
- !ruby/object:Gem::Version
|
33
61
|
version: '0'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
|
-
- -
|
66
|
+
- - ">="
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
70
|
+
name: rubocop
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- -
|
73
|
+
- - ">="
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
75
|
+
version: '0'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- -
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: shoulda-matchers
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
|
-
- -
|
101
|
+
- - ">="
|
60
102
|
- !ruby/object:Gem::Version
|
61
103
|
version: '0'
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
|
-
- -
|
108
|
+
- - ">="
|
67
109
|
- !ruby/object:Gem::Version
|
68
110
|
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: activemodel
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
|
-
- -
|
115
|
+
- - ">="
|
74
116
|
- !ruby/object:Gem::Version
|
75
117
|
version: '0'
|
76
118
|
type: :runtime
|
77
119
|
prerelease: false
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
80
|
-
- -
|
122
|
+
- - ">="
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
125
|
description:
|
@@ -86,28 +128,28 @@ executables: []
|
|
86
128
|
extensions: []
|
87
129
|
extra_rdoc_files: []
|
88
130
|
files:
|
89
|
-
- .gitignore
|
90
|
-
- .rspec
|
91
|
-
- .
|
92
|
-
- .ruby-
|
93
|
-
- .
|
131
|
+
- ".gitignore"
|
132
|
+
- ".rspec"
|
133
|
+
- ".rubocop.yml"
|
134
|
+
- ".ruby-gemset"
|
135
|
+
- ".ruby-version"
|
136
|
+
- ".travis.yml"
|
94
137
|
- Gemfile
|
95
|
-
- LICENSE
|
138
|
+
- LICENSE.md
|
96
139
|
- README.md
|
97
140
|
- Rakefile
|
98
|
-
- gemfiles/Gemfile.rails3
|
99
141
|
- gemfiles/Gemfile.rails4
|
142
|
+
- gemfiles/Gemfile.rails5
|
100
143
|
- lib/validates_cpf.rb
|
101
144
|
- lib/validates_cpf/cpf.rb
|
102
145
|
- lib/validates_cpf/cpf_validator.rb
|
103
146
|
- lib/validates_cpf/require_a_valid_cpf_matcher.rb
|
104
147
|
- lib/validates_cpf/version.rb
|
105
|
-
- spec/
|
148
|
+
- spec/cpf_validator_spec.rb
|
106
149
|
- spec/fake_app/user.rb
|
150
|
+
- spec/shoulda/matchers/active_model/require_a_valid_cpf_matcher_spec.rb
|
107
151
|
- spec/spec_helper.rb
|
108
152
|
- spec/validates_cpf/cpf_spec.rb
|
109
|
-
- spec/validates_cpf/require_a_valid_cpf_matcher_spec.rb
|
110
|
-
- spec/validates_cpf_spec.rb
|
111
153
|
- validates_cpf.gemspec
|
112
154
|
homepage:
|
113
155
|
licenses:
|
@@ -119,26 +161,25 @@ require_paths:
|
|
119
161
|
- lib
|
120
162
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
163
|
requirements:
|
122
|
-
- -
|
164
|
+
- - ">="
|
123
165
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
166
|
+
version: '2.2'
|
125
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
168
|
requirements:
|
127
|
-
- -
|
169
|
+
- - ">="
|
128
170
|
- !ruby/object:Gem::Version
|
129
171
|
version: '0'
|
130
172
|
requirements: []
|
131
173
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.7.6
|
133
175
|
signing_key:
|
134
176
|
specification_version: 4
|
135
177
|
summary: Validates CPF and test it with matchers in a simple way.
|
136
178
|
test_files:
|
137
|
-
- gemfiles/Gemfile.rails3
|
138
179
|
- gemfiles/Gemfile.rails4
|
139
|
-
-
|
180
|
+
- gemfiles/Gemfile.rails5
|
181
|
+
- spec/cpf_validator_spec.rb
|
140
182
|
- spec/fake_app/user.rb
|
183
|
+
- spec/shoulda/matchers/active_model/require_a_valid_cpf_matcher_spec.rb
|
141
184
|
- spec/spec_helper.rb
|
142
185
|
- spec/validates_cpf/cpf_spec.rb
|
143
|
-
- spec/validates_cpf/require_a_valid_cpf_matcher_spec.rb
|
144
|
-
- spec/validates_cpf_spec.rb
|
data/gemfiles/Gemfile.rails3
DELETED
data/spec/fake_app/admin.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'shoulda-matchers'
|
3
|
-
|
4
|
-
describe Shoulda::Matchers::ActiveModel::RequireAValidCpfMatcher do
|
5
|
-
before :each do
|
6
|
-
@user = User.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should accept on cpf' do
|
10
|
-
@user.should require_a_valid_cpf(:cpf)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should accept without a specified attribute' do
|
14
|
-
@user.should require_a_valid_cpf
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should reject on name' do
|
18
|
-
@user.should_not require_a_valid_cpf(:name)
|
19
|
-
end
|
20
|
-
end
|
data/spec/validates_cpf_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CpfValidator do
|
4
|
-
context 'when cpf is invalid' do
|
5
|
-
context 'on a non namespaced model' do
|
6
|
-
before :each do
|
7
|
-
@user = User.new(:cpf => '12345')
|
8
|
-
I18n.stub(:t).with(:'activerecord.errors.models.user.attributes.cpf.invalid',
|
9
|
-
:default => :'activerecord.errors.messages.invalid').and_return('is invalid')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should set object as invalid' do
|
13
|
-
@user.valid?.should be_false
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should set an error message on attribute' do
|
17
|
-
@user.valid?
|
18
|
-
@user.errors[:cpf].should == ['is invalid']
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when cpf is valid' do
|
24
|
-
before :each do
|
25
|
-
@user = User.new(:cpf => '11144477735')
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should set object as valid' do
|
29
|
-
@user.valid?.should be_true
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should not set an error message on attribute' do
|
33
|
-
@user.valid?
|
34
|
-
@user.errors[:cpf].should be_blank
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should accept a nil value' do
|
39
|
-
@user = User.new(:cpf => nil)
|
40
|
-
@user.valid?.should be_true
|
41
|
-
end
|
42
|
-
end
|