validates_cnpj 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 +16 -0
- data/.ruby-version +1 -1
- data/.travis.yml +7 -14
- data/Gemfile +3 -1
- data/README.md +24 -5
- data/Rakefile +6 -4
- data/gemfiles/Gemfile.rails4 +1 -1
- data/gemfiles/Gemfile.rails5 +5 -0
- data/lib/validates_cnpj.rb +2 -0
- data/lib/validates_cnpj/cnpj.rb +22 -13
- data/lib/validates_cnpj/cnpj_validator.rb +9 -1
- data/lib/validates_cnpj/require_a_valid_cnpj_matcher.rb +3 -1
- data/lib/validates_cnpj/version.rb +3 -1
- data/spec/cnpj_validator_spec.rb +43 -0
- data/spec/fake_app/company.rb +4 -2
- data/spec/shoulda/matchers/active_model/require_a_valid_cnpj_matcher_spec.rb +19 -0
- data/spec/spec_helper.rb +19 -2
- data/spec/validates_cnpj/cnpj_spec.rb +28 -26
- data/validates_cnpj.gemspec +16 -10
- metadata +81 -35
- data/gemfiles/Gemfile.rails3 +0 -5
- data/spec/fake_app/admin.rb +0 -3
- data/spec/validates_cnpj/validate_as_cnpj_matcher_spec.rb +0 -20
- data/spec/validates_cnpj_spec.rb +0 -40
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDM5ZjA3NzJkYzVkYjAwYTI3YWY3YmUwMzI1MzhlNzQ0ZGNjNmZhYw==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fe45c5e355e2676e043807b3adee04fdaae824d333df328529f397cb585f3b0
|
4
|
+
data.tar.gz: f6205a0583c337bc030944f12129bec61334655c655611fcc2b725a2e2a0ecf1
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YmM0M2Q3Mjg5YTdjYjA5MGVjZmZkYzY1Mjk1MDNhYTkwYWJhZDk4ZDhhNjZk
|
11
|
-
YTVkMTc0MGJiOWU1NjVlNzUxM2EyNjg4YjRmNzdjNThlMDk2Nzk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZDEzMTkzNzZjNWI1MWNkN2IzZTM3MWVlMTg1ZDk4Njg4ODkxNTY3NWQ1MzQ0
|
14
|
-
YjIxODBjYTVjNGM2Yzc4N2U1ZTlhZWMyNGRiMTZkMGFiN2FmMjljZDg0NzNm
|
15
|
-
ODc5MzJiOGZhMDVhNTg3NmNiMDZiZDdmMjg3ZTEyZmRkODIwMjk=
|
6
|
+
metadata.gz: 4900d074a6a9658a0cf256ada2d30e4beb83017b94ee77d02bd0d9afd0f184d64d17d3428f8a7e9cbcf6c507b5f2cb3320100494965012b808bc5f4466f7cd3a
|
7
|
+
data.tar.gz: d09478b9a608031cb86e6bfc3724f4b09ee35f6fe90b7f8d704812dae26dec0c8c0eee5dd0aef8e3e0642f8ad742db64a121e0c93ba43b69f5478dca487f085e
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
Gemspec/RequiredRubyVersion:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
Metrics/BlockLength:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 125
|
11
|
+
|
12
|
+
RSpec/DescribedClass:
|
13
|
+
EnforcedStyle: explicit
|
14
|
+
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.6.6
|
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/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ValidatesCnpj
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/validates_cnpj) [](http://travis-ci.org/plribeiro3000/validates_cnpj) [](http://badge.fury.io/rb/validates_cnpj) [](http://travis-ci.org/plribeiro3000/validates_cnpj) [](https://coveralls.io/r/plribeiro3000/validates_cnpj) [](https://codeclimate.com/github/plribeiro3000/validates_cnpj)
|
4
4
|
|
5
5
|
Validates cnpj and test it in a simple way
|
6
6
|
|
@@ -23,14 +23,33 @@ Or install it yourself as:
|
|
23
23
|
Just use as any other validator:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
class
|
27
|
-
validates :cnpj, :
|
26
|
+
class Company < ActiveRecord::Base
|
27
|
+
validates :cnpj, cnpj: 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 Company < ActiveRecord::Base
|
35
|
+
validates :cnpj, cnpj: { mask: true }
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Testing
|
40
|
+
|
41
|
+
Require the matcher:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'validates_cnpj/require_a_valid_cnpj_matcher'
|
45
|
+
```
|
46
|
+
|
47
|
+
Use in your tests:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
it { is_expected.to require_a_valid_cnpj } # It will test the attribute :cnpj by default
|
51
|
+
it { is_expected.to require_a_valid_cnpj(:id) }
|
52
|
+
```
|
34
53
|
|
35
54
|
## Mantainers
|
36
55
|
[@plribeiro3000](https://github.com/plribeiro3000)
|
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_cnpj.rb
CHANGED
data/lib/validates_cnpj/cnpj.rb
CHANGED
@@ -1,45 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ValidatesCnpj
|
2
4
|
class Cnpj
|
3
5
|
def initialize(number)
|
4
|
-
number =~
|
6
|
+
number =~ %r{^(\d{2}\.?\d{3}\.?\d{3}/?\d{4})-?(\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(%r{[\./-]}, '')
|
9
11
|
format_number! if @pure_number
|
10
12
|
end
|
11
13
|
|
12
14
|
def valid?
|
13
15
|
return true if @number.blank?
|
14
16
|
return false unless @pure_number
|
17
|
+
|
15
18
|
check_cnpj
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
@number
|
20
|
-
end
|
21
|
+
attr_reader :number
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
25
|
def check_cnpj
|
25
|
-
return false if @cleaned_number.length != 14
|
26
|
+
return false if (@cleaned_number.length != 14) || (@cleaned_number.scan(/\d/).uniq.length == 1)
|
27
|
+
|
26
28
|
@result == first_digit_verifier + second_digit_verifier
|
27
29
|
end
|
28
30
|
|
29
31
|
def first_digit_verifier
|
30
32
|
sum = multiply_and_sum([5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number)
|
31
|
-
digit_verifier(sum%11).to_s
|
33
|
+
digit_verifier(sum % 11).to_s
|
32
34
|
end
|
33
35
|
|
34
36
|
def second_digit_verifier
|
35
37
|
sum = multiply_and_sum([6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number + first_digit_verifier)
|
36
|
-
digit_verifier(sum%11).to_s
|
38
|
+
digit_verifier(sum % 11).to_s
|
37
39
|
end
|
38
40
|
|
39
41
|
def multiply_and_sum(array, number)
|
40
42
|
multiplied = []
|
41
43
|
number.scan(/\d{1}/).each_with_index { |e, i| multiplied[i] = e.to_i * array[i] }
|
42
|
-
multiplied.inject { |s,e| s + e }
|
44
|
+
multiplied.inject { |s, e| s + e }
|
43
45
|
end
|
44
46
|
|
45
47
|
def digit_verifier(rest)
|
@@ -48,7 +50,14 @@ module ValidatesCnpj
|
|
48
50
|
|
49
51
|
def format_number!
|
50
52
|
@cleaned_number =~ /(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/
|
51
|
-
|
53
|
+
|
54
|
+
match1 = Regexp.last_match(1)
|
55
|
+
match2 = Regexp.last_match(2)
|
56
|
+
match3 = Regexp.last_match(3)
|
57
|
+
match4 = Regexp.last_match(4)
|
58
|
+
match5 = Regexp.last_match(5)
|
59
|
+
|
60
|
+
@number = "#{match1}.#{match2}.#{match3}/#{match4}-#{match5}"
|
52
61
|
end
|
53
62
|
end
|
54
|
-
end
|
63
|
+
end
|
@@ -1,5 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class CnpjValidator < ActiveModel::EachValidator
|
2
4
|
def validate_each(record, attribute, value)
|
3
|
-
|
5
|
+
cnpj = ValidatesCnpj::Cnpj.new(value)
|
6
|
+
|
7
|
+
if cnpj.valid?
|
8
|
+
record.send("#{attribute}=", cnpj.number) if options[:mask]
|
9
|
+
else
|
10
|
+
record.errors.add(attribute, :invalid, options)
|
11
|
+
end
|
4
12
|
end
|
5
13
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe CnpjValidator do
|
6
|
+
let(:company) { Company.new }
|
7
|
+
|
8
|
+
context 'when cnpj is invalid' do
|
9
|
+
before do
|
10
|
+
company.cnpj = 12_345
|
11
|
+
allow(I18n).to receive(:t).with(:"activerecord.errors.models.company.attributes.cnpj.invalid",
|
12
|
+
default: :"activerecord.errors.messages.invalid").and_return('is invalid')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets object as invalid' do
|
16
|
+
expect(company.valid?).to eq(false)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sets an error on attribute' do
|
20
|
+
company.valid?
|
21
|
+
expect(company.errors[:cnpj]).to eq(['is invalid'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when cnpj is valid' do
|
26
|
+
before do
|
27
|
+
company.cnpj = '37525685000108'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'sets object as valid' do
|
31
|
+
expect(company.valid?).to eq(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not set an error on attribute' do
|
35
|
+
company.valid?
|
36
|
+
expect(company.errors[:cnpj]).to eq([])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'accepts a nil value' do
|
41
|
+
expect(company.valid?).to eq(true)
|
42
|
+
end
|
43
|
+
end
|
data/spec/fake_app/company.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Company
|
2
4
|
include ActiveModel::Validations
|
3
5
|
include ActiveModel::Conversion
|
@@ -5,11 +7,11 @@ class Company
|
|
5
7
|
|
6
8
|
attr_accessor :cnpj, :name
|
7
9
|
|
8
|
-
validates :cnpj, :
|
10
|
+
validates :cnpj, cnpj: true
|
9
11
|
|
10
12
|
def initialize(attributes = {})
|
11
13
|
attributes.each do |key, value|
|
12
14
|
instance_variable_set("@#{key}", value)
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Shoulda::Matchers::ActiveModel::RequireAValidCnpjMatcher do
|
6
|
+
let(:company) { Company.new }
|
7
|
+
|
8
|
+
it 'accepts on cnpj' do
|
9
|
+
expect(company).to require_a_valid_cnpj(:cnpj)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts without a specified attribute' do
|
13
|
+
expect(company).to require_a_valid_cnpj
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'rejects on name' do
|
17
|
+
expect(company).not_to require_a_valid_cnpj(:name)
|
18
|
+
end
|
19
|
+
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 = ValidatesCnpj
|
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_cnpj')
|
25
|
+
require File.expand_path('spec/fake_app/company')
|
@@ -1,91 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ValidatesCnpj::Cnpj do
|
4
|
-
context '
|
6
|
+
context 'with invalid option' do
|
5
7
|
it '04.22A.284/0001-11 as number' do
|
6
|
-
ValidatesCnpj::Cnpj.new('04.22A.284/0001-11').
|
8
|
+
expect(ValidatesCnpj::Cnpj.new('04.22A.284/0001-11')).not_to be_valid
|
7
9
|
end
|
8
10
|
|
9
11
|
it '04.222-284.0001-11 as number' do
|
10
|
-
ValidatesCnpj::Cnpj.new('04.222-284.0001-11').
|
12
|
+
expect(ValidatesCnpj::Cnpj.new('04.222-284.0001-11')).not_to be_valid
|
11
13
|
end
|
12
14
|
|
13
15
|
it '04222/284/0001-11 as number' do
|
14
|
-
ValidatesCnpj::Cnpj.new('04222/284/0001-11').
|
16
|
+
expect(ValidatesCnpj::Cnpj.new('04222/284/0001-11')).not_to be_valid
|
15
17
|
end
|
16
18
|
|
17
19
|
it '69103604020160 as number' do
|
18
|
-
ValidatesCnpj::Cnpj.new('69103604020160').
|
20
|
+
expect(ValidatesCnpj::Cnpj.new('69103604020160')).not_to be_valid
|
19
21
|
end
|
20
22
|
|
21
23
|
it '00000000000000 as number' do
|
22
|
-
ValidatesCnpj::Cnpj.new('00000000000000').
|
24
|
+
expect(ValidatesCnpj::Cnpj.new('00000000000000')).not_to be_valid
|
23
25
|
end
|
24
26
|
|
25
27
|
it '69.103.604/0001-61 as number' do
|
26
|
-
ValidatesCnpj::Cnpj.new('69.103.604/0001-61').
|
28
|
+
expect(ValidatesCnpj::Cnpj.new('69.103.604/0001-61')).not_to be_valid
|
27
29
|
end
|
28
30
|
|
29
31
|
it '01618211000264 as number' do
|
30
|
-
ValidatesCnpj::Cnpj.new('01618211000264').
|
32
|
+
expect(ValidatesCnpj::Cnpj.new('01618211000264')).not_to be_valid
|
31
33
|
end
|
32
34
|
|
33
35
|
it '691036040001-601 as number' do
|
34
|
-
ValidatesCnpj::Cnpj.new('691036040001-601').
|
36
|
+
expect(ValidatesCnpj::Cnpj.new('691036040001-601')).not_to be_valid
|
35
37
|
end
|
36
38
|
|
37
39
|
it '69103604000160a as number' do
|
38
|
-
ValidatesCnpj::Cnpj.new('69103604000160a').
|
40
|
+
expect(ValidatesCnpj::Cnpj.new('69103604000160a')).not_to be_valid
|
39
41
|
end
|
40
42
|
|
41
43
|
it '69103604000160ABC as number' do
|
42
|
-
ValidatesCnpj::Cnpj.new('69103604000160ABC').
|
44
|
+
expect(ValidatesCnpj::Cnpj.new('69103604000160ABC')).not_to be_valid
|
43
45
|
end
|
44
46
|
|
45
47
|
it '6910360400016000 as number' do
|
46
|
-
ValidatesCnpj::Cnpj.new('6910360400016000').
|
48
|
+
expect(ValidatesCnpj::Cnpj.new('6910360400016000')).not_to be_valid
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
context '
|
52
|
+
context 'with valid option' do
|
51
53
|
it 'blank number' do
|
52
|
-
ValidatesCnpj::Cnpj.new('').
|
54
|
+
expect(ValidatesCnpj::Cnpj.new('')).to be_valid
|
53
55
|
end
|
54
|
-
|
56
|
+
|
55
57
|
it 'nil as number' do
|
56
|
-
ValidatesCnpj::Cnpj.new(nil).
|
58
|
+
expect(ValidatesCnpj::Cnpj.new(nil)).to be_valid
|
57
59
|
end
|
58
60
|
|
59
61
|
it '69103604000160 as number' do
|
60
|
-
ValidatesCnpj::Cnpj.new('69103604000160').
|
62
|
+
expect(ValidatesCnpj::Cnpj.new('69103604000160')).to be_valid
|
61
63
|
end
|
62
64
|
|
63
65
|
it '69.103.604/0001-60 as number' do
|
64
|
-
ValidatesCnpj::Cnpj.new('69.103.604/0001-60').
|
66
|
+
expect(ValidatesCnpj::Cnpj.new('69.103.604/0001-60')).to be_valid
|
65
67
|
end
|
66
68
|
|
67
69
|
it '01518211/000264 as number' do
|
68
|
-
ValidatesCnpj::Cnpj.new('01518211/000264').
|
70
|
+
expect(ValidatesCnpj::Cnpj.new('01518211/000264')).to be_valid
|
69
71
|
end
|
70
72
|
|
71
73
|
it '01.5182110002-64 as number' do
|
72
|
-
ValidatesCnpj::Cnpj.new('01.5182110002-64').
|
74
|
+
expect(ValidatesCnpj::Cnpj.new('01.5182110002-64')).to be_valid
|
73
75
|
end
|
74
76
|
|
75
77
|
it '00.000.000/1447-89 as number' do
|
76
|
-
ValidatesCnpj::Cnpj.new('00.000.000/1447-89').
|
78
|
+
expect(ValidatesCnpj::Cnpj.new('00.000.000/1447-89')).to be_valid
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
80
82
|
context 'with a valid value' do
|
81
|
-
it '
|
82
|
-
ValidatesCnpj::Cnpj.new('69103604000160').number.
|
83
|
+
it 'returns it formatted' do
|
84
|
+
expect(ValidatesCnpj::Cnpj.new('69103604000160').number).to eq('69.103.604/0001-60')
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
88
|
context 'with an invalid value' do
|
87
|
-
it '
|
88
|
-
ValidatesCnpj::Cnpj.new('123456').number.
|
89
|
+
it 'returns as it was' do
|
90
|
+
expect(ValidatesCnpj::Cnpj.new('123456').number).to eq('123456')
|
89
91
|
end
|
90
92
|
end
|
91
|
-
end
|
93
|
+
end
|
data/validates_cnpj.gemspec
CHANGED
@@ -1,24 +1,30 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/validates_cnpj/version', __dir__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
5
6
|
gem.name = 'validates_cnpj'
|
6
7
|
gem.version = ValidatesCnpj::VERSION
|
7
|
-
gem.authors =
|
8
|
-
gem.email =
|
9
|
-
gem.summary =
|
8
|
+
gem.authors = 'Paulo Henrique Lopes Ribeiro'
|
9
|
+
gem.email = 'plribeiro3000@gmail.com'
|
10
|
+
gem.summary = 'Validates CNPJ and test it with matchers in a simple way.'
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split("\n")
|
12
13
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
-
gem.require_paths = %w
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
15
|
+
gem.require_paths = %w[lib]
|
16
|
+
|
17
|
+
gem.required_ruby_version = '>= 2.2'
|
15
18
|
|
16
19
|
gem.license = 'MIT'
|
17
20
|
|
21
|
+
gem.add_development_dependency 'coveralls'
|
22
|
+
gem.add_development_dependency 'jazz_fingers', '< 5.0.0'
|
18
23
|
gem.add_development_dependency 'rake'
|
19
24
|
gem.add_development_dependency 'rspec'
|
20
|
-
gem.add_development_dependency '
|
21
|
-
gem.add_development_dependency '
|
25
|
+
gem.add_development_dependency 'rubocop'
|
26
|
+
gem.add_development_dependency 'rubocop-rspec'
|
27
|
+
gem.add_development_dependency 'shoulda-matchers'
|
22
28
|
|
23
|
-
gem.add_runtime_dependency 'activemodel'
|
29
|
+
gem.add_runtime_dependency 'activemodel', '> 4.0', '< 6.0'
|
24
30
|
end
|
metadata
CHANGED
@@ -1,113 +1,161 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_cnpj
|
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: 2020-05-18 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: 5.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "<"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.0.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
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- -
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
89
|
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- -
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
98
|
+
name: shoulda-matchers
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
|
-
- -
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
103
|
version: '0'
|
76
|
-
type: :
|
104
|
+
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- -
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activemodel
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.0'
|
118
|
+
- - "<"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '6.0'
|
121
|
+
type: :runtime
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '4.0'
|
128
|
+
- - "<"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '6.0'
|
83
131
|
description:
|
84
132
|
email: plribeiro3000@gmail.com
|
85
133
|
executables: []
|
86
134
|
extensions: []
|
87
135
|
extra_rdoc_files: []
|
88
136
|
files:
|
89
|
-
- .gitignore
|
90
|
-
- .rspec
|
91
|
-
- .
|
92
|
-
- .ruby-
|
93
|
-
- .
|
137
|
+
- ".gitignore"
|
138
|
+
- ".rspec"
|
139
|
+
- ".rubocop.yml"
|
140
|
+
- ".ruby-gemset"
|
141
|
+
- ".ruby-version"
|
142
|
+
- ".travis.yml"
|
94
143
|
- Gemfile
|
95
144
|
- LICENSE
|
96
145
|
- README.md
|
97
146
|
- Rakefile
|
98
|
-
- gemfiles/Gemfile.rails3
|
99
147
|
- gemfiles/Gemfile.rails4
|
148
|
+
- gemfiles/Gemfile.rails5
|
100
149
|
- lib/validates_cnpj.rb
|
101
150
|
- lib/validates_cnpj/cnpj.rb
|
102
151
|
- lib/validates_cnpj/cnpj_validator.rb
|
103
152
|
- lib/validates_cnpj/require_a_valid_cnpj_matcher.rb
|
104
153
|
- lib/validates_cnpj/version.rb
|
105
|
-
- spec/
|
154
|
+
- spec/cnpj_validator_spec.rb
|
106
155
|
- spec/fake_app/company.rb
|
156
|
+
- spec/shoulda/matchers/active_model/require_a_valid_cnpj_matcher_spec.rb
|
107
157
|
- spec/spec_helper.rb
|
108
158
|
- spec/validates_cnpj/cnpj_spec.rb
|
109
|
-
- spec/validates_cnpj/validate_as_cnpj_matcher_spec.rb
|
110
|
-
- spec/validates_cnpj_spec.rb
|
111
159
|
- validates_cnpj.gemspec
|
112
160
|
homepage:
|
113
161
|
licenses:
|
@@ -119,24 +167,22 @@ require_paths:
|
|
119
167
|
- lib
|
120
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
169
|
requirements:
|
122
|
-
- -
|
170
|
+
- - ">="
|
123
171
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
172
|
+
version: '2.2'
|
125
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
174
|
requirements:
|
127
|
-
- -
|
175
|
+
- - ">="
|
128
176
|
- !ruby/object:Gem::Version
|
129
177
|
version: '0'
|
130
178
|
requirements: []
|
131
|
-
|
132
|
-
rubygems_version: 2.1.11
|
179
|
+
rubygems_version: 3.1.3
|
133
180
|
signing_key:
|
134
181
|
specification_version: 4
|
135
182
|
summary: Validates CNPJ and test it with matchers in a simple way.
|
136
183
|
test_files:
|
137
|
-
- spec/
|
184
|
+
- spec/cnpj_validator_spec.rb
|
138
185
|
- spec/fake_app/company.rb
|
186
|
+
- spec/shoulda/matchers/active_model/require_a_valid_cnpj_matcher_spec.rb
|
139
187
|
- spec/spec_helper.rb
|
140
188
|
- spec/validates_cnpj/cnpj_spec.rb
|
141
|
-
- spec/validates_cnpj/validate_as_cnpj_matcher_spec.rb
|
142
|
-
- spec/validates_cnpj_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::RequireAValidCnpjMatcher do
|
5
|
-
before :each do
|
6
|
-
@company = Company.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on cnpj" do
|
10
|
-
@company.should require_a_valid_cnpj(:cnpj)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@company.should require_a_valid_cnpj
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on name" do
|
18
|
-
@company.should_not require_a_valid_cnpj(:name)
|
19
|
-
end
|
20
|
-
end
|
data/spec/validates_cnpj_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CnpjValidator do
|
4
|
-
context "when cnpj is invalid" do
|
5
|
-
before :each do
|
6
|
-
@company = Company.new(:cnpj => "12345")
|
7
|
-
I18n.stub(:t).with(:"activerecord.errors.models.company.attributes.cnpj.invalid",
|
8
|
-
:default => :"activerecord.errors.messages.invalid").and_return("is invalid")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should set object as invalid" do
|
12
|
-
@company.valid?.should be_false
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set an error on attribute" do
|
16
|
-
@company.valid?
|
17
|
-
@company.errors[:cnpj].should == ['is invalid']
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when cnpj is valid" do
|
22
|
-
before :each do
|
23
|
-
@company = Company.new(:cnpj => "37525685000108")
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should set object as valid" do
|
27
|
-
@company.valid?.should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should not set an error on attribute" do
|
31
|
-
@company.valid?
|
32
|
-
@company.errors[:cnpj].should be_blank
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should accept a nil value" do
|
37
|
-
@company = Company.new(:cnpj => nil)
|
38
|
-
@company.valid?.should be_true
|
39
|
-
end
|
40
|
-
end
|