br_documents 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/config.yml +12 -26
  3. data/.rubocop.yml +29 -21
  4. data/.tool-versions +1 -0
  5. data/Gemfile.lock +7 -4
  6. data/Rakefile +1 -1
  7. data/br_documents.gemspec +3 -0
  8. data/lib/br_documents/cnpj_cpf/document.rb +1 -1
  9. data/lib/br_documents/{gtin/gtin.rb → gtin.rb} +2 -2
  10. data/lib/br_documents/ie/ba.rb +1 -1
  11. data/lib/br_documents/ie/mg.rb +1 -1
  12. data/lib/br_documents/ie/mt.rb +1 -1
  13. data/lib/br_documents/ie_validator.rb +1 -1
  14. data/lib/br_documents/suframa.rb +46 -0
  15. data/lib/br_documents/version.rb +1 -1
  16. data/spec/{cnpj_cpf → br_documents/cnpj_cpf}/cnpj_spec.rb +13 -13
  17. data/spec/{cnpj_cpf → br_documents/cnpj_cpf}/cpf_spec.rb +13 -13
  18. data/spec/br_documents/cnpj_validator_spec.rb +36 -0
  19. data/spec/br_documents/cpf_validator_spec.rb +36 -0
  20. data/spec/{gtin → br_documents}/gtin_spec.rb +2 -2
  21. data/spec/{gtin_validator_spec.rb → br_documents/gtin_validator_spec.rb} +3 -3
  22. data/spec/{ie → br_documents/ie}/ac_spec.rb +3 -3
  23. data/spec/{ie → br_documents/ie}/al_spec.rb +2 -2
  24. data/spec/{ie → br_documents/ie}/am_spec.rb +3 -3
  25. data/spec/{ie → br_documents/ie}/ap_spec.rb +2 -2
  26. data/spec/{ie → br_documents/ie}/ba_spec.rb +4 -4
  27. data/spec/{ie → br_documents/ie}/ce_spec.rb +0 -0
  28. data/spec/{ie → br_documents/ie}/df_spec.rb +3 -3
  29. data/spec/{ie → br_documents/ie}/es_spec.rb +0 -0
  30. data/spec/{ie → br_documents/ie}/factory_spec.rb +28 -28
  31. data/spec/{ie → br_documents/ie}/go_spec.rb +3 -3
  32. data/spec/{ie → br_documents/ie}/ma_spec.rb +0 -0
  33. data/spec/{ie → br_documents/ie}/mg_spec.rb +6 -6
  34. data/spec/{ie → br_documents/ie}/ms_spec.rb +0 -0
  35. data/spec/{ie → br_documents/ie}/mt_spec.rb +8 -3
  36. data/spec/{ie → br_documents/ie}/pa_spec.rb +3 -3
  37. data/spec/{ie → br_documents/ie}/pb_spec.rb +0 -0
  38. data/spec/{ie → br_documents/ie}/pe_spec.rb +4 -4
  39. data/spec/{ie → br_documents/ie}/pi_spec.rb +0 -0
  40. data/spec/{ie → br_documents/ie}/pr_spec.rb +2 -2
  41. data/spec/{ie → br_documents/ie}/rj_spec.rb +3 -3
  42. data/spec/{ie → br_documents/ie}/rn_spec.rb +4 -4
  43. data/spec/{ie → br_documents/ie}/ro_spec.rb +4 -4
  44. data/spec/{ie → br_documents/ie}/rr_spec.rb +3 -3
  45. data/spec/{ie → br_documents/ie}/rs_spec.rb +3 -3
  46. data/spec/{ie → br_documents/ie}/sc_spec.rb +3 -3
  47. data/spec/{ie → br_documents/ie}/se_spec.rb +0 -0
  48. data/spec/{ie → br_documents/ie}/shared_examples_for_pattern1.rb +3 -3
  49. data/spec/{ie → br_documents/ie}/shared_examples_for_to_remove_all_masks.rb +0 -0
  50. data/spec/{ie → br_documents/ie}/sp_spec.rb +2 -2
  51. data/spec/{ie → br_documents/ie}/to_spec.rb +6 -6
  52. data/spec/{ie_validator_spec.rb → br_documents/ie_validator_spec.rb} +7 -6
  53. data/spec/br_documents/suframa_spec.rb +73 -0
  54. data/spec/{suframa_validator_spec.rb → br_documents/suframa_validator_spec.rb} +4 -4
  55. metadata +100 -85
  56. data/lib/br_documents/suframa/suframa.rb +0 -60
  57. data/spec/cnpj_validator_spec.rb +0 -36
  58. data/spec/cpf_validator_spec.rb +0 -36
  59. data/spec/suframa/suframa_spec.rb +0 -109
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26654dc4bd73502f9cf3fadf4a33104f218a47fb81e02c71c8a23f9d78c75d91
4
- data.tar.gz: 5ec58159f531151f3b759ac907d3d16dfd269fb3a26091f559a6e23798bcce07
3
+ metadata.gz: a893a246eb1c07b45241c0eec46268a58a01aa7e2bbb0f02f8294e3c1f6c0ccf
4
+ data.tar.gz: 8ad80b4d402567412752ed48eab9c0adec82fa6d92cf8dcf6bfbf788e72e8a6b
5
5
  SHA512:
6
- metadata.gz: 724248b106f9db144d555521a59728e100e881e77261d25d2399d630e10461694adc241b027f6b53577db2d3f68ab11806d6fecaf76261bf98401d0daef780a8
7
- data.tar.gz: 05b814e328dec4ef44f0ebe2f5af18a86ea35d920cb5537ca235e8ba30c2786a550577e4f86fc232d6760d9b589557a76c29f1c09f2848ad305ae1e8d184707b
6
+ metadata.gz: 43d5217a448c6ed1297084b59c4935021a0bfda1968be33b109985cd169ea80b435adaec30373ba84b3125828842e7cce71033e3f7d842db3af0610f2c0e87d0
7
+ data.tar.gz: 63538e8845f2143637a685af12b944cc37c2b5ecb34fc32f3eb67c859cbd28968daaadac4669146322794e2029a0a0034c9fbdf94a90dcf887a309e125ca4e7d
@@ -1,26 +1,27 @@
1
- name: Containers
1
+ name: Tests
2
2
 
3
3
  on: [push]
4
4
 
5
5
  jobs:
6
- build:
6
+ linter:
7
7
  runs-on: ubuntu-latest
8
8
 
9
9
  steps:
10
- - uses: actions/checkout@v2
11
10
 
12
- - uses: ruby/setup-ruby@v1
13
- with:
14
- ruby-version: 2.7.3
15
- bundler-cache: true
11
+ - uses: actions/checkout@v3
12
+
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.7.3
16
+ bundler-cache: true
17
+
18
+ - run: bundle exec rubocop --display-cop-names --parallel
16
19
 
17
20
  rspec:
18
21
  runs-on: ubuntu-latest
19
22
 
20
- needs: build
21
-
22
23
  steps:
23
- - uses: actions/checkout@v2
24
+ - uses: actions/checkout@v3
24
25
 
25
26
  - uses: ruby/setup-ruby@v1
26
27
  with:
@@ -30,25 +31,10 @@ jobs:
30
31
  - run: |
31
32
  curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
32
33
  chmod +x ./cc-test-reporter
34
+
33
35
  - run: |
34
36
  ./cc-test-reporter before-build
35
37
  bundle exec rspec
36
38
  ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID --exit-code $?
37
39
  env:
38
40
  CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
39
-
40
- lint:
41
- runs-on: ubuntu-latest
42
-
43
- needs: build
44
-
45
- steps:
46
-
47
- - uses: actions/checkout@v2
48
-
49
- - uses: ruby/setup-ruby@v1
50
- with:
51
- ruby-version: 2.7.3
52
- bundler-cache: true
53
-
54
- - run: bundle exec rubocop --display-cop-names --parallel
data/.rubocop.yml CHANGED
@@ -1,3 +1,20 @@
1
+ # You can find more information about RuboCop pending cops policy
2
+ # https://docs.rubocop.org/rubocop/versioning.html#pending-cops
3
+ #
4
+ # These are the default options. The .rubocop.yml inherit and
5
+ # override all the default options.
6
+ # https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
7
+ require:
8
+ - rubocop-rails
9
+ - rubocop-performance
10
+ - rubocop-rspec
11
+ - rubocop-rake
12
+ AllCops:
13
+ TargetRubyVersion: 2.7.3
14
+ DisplayCopNames: true
15
+ DisplayStyleGuide: true
16
+ NewCops: enable
17
+
1
18
  # Offense count: 1
2
19
  # Configuration parameters: Include.
3
20
  # Include: **/*.gemspec
@@ -24,6 +41,18 @@ Metrics/BlockLength:
24
41
  Style/Documentation:
25
42
  Enabled: false
26
43
 
44
+ RSpec/NamedSubject:
45
+ Enabled: false # default: true
46
+
47
+ RSpec/MultipleExpectations:
48
+ Enabled: false # default: true
49
+
50
+ RSpec/NestedGroups:
51
+ Enabled: false # default: true
52
+
53
+ Style/RegexpLiteral:
54
+ Enabled: false # default: true
55
+
27
56
  Style/FrozenStringLiteralComment:
28
57
  EnforcedStyle: never # default: always
29
58
 
@@ -32,27 +61,6 @@ Style/FrozenStringLiteralComment:
32
61
  Style/RedundantRegexpEscape:
33
62
  Enabled: false
34
63
 
35
- # Offense count: 18
36
- # Cop supports --auto-correct.
37
- # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
38
- # SupportedStyles: slashes, percent_r, mixed
39
- Style/RegexpLiteral:
40
- Exclude:
41
- - 'lib/br_documents/cnpj_cpf/cnpj.rb'
42
- - 'lib/br_documents/cnpj_cpf/document.rb'
43
- - 'lib/br_documents/ie/ac.rb'
44
- - 'lib/br_documents/ie/ba.rb'
45
- - 'lib/br_documents/ie/mg.rb'
46
- - 'lib/br_documents/ie/mt.rb'
47
- - 'lib/br_documents/ie/pattern1.rb'
48
- - 'lib/br_documents/ie/pattern2.rb'
49
- - 'lib/br_documents/ie/pe.rb'
50
- - 'lib/br_documents/ie/rn.rb'
51
- - 'lib/br_documents/ie/ro.rb'
52
- - 'lib/br_documents/ie/rs.rb'
53
- - 'lib/br_documents/ie/sp.rb'
54
- - 'spec/ie/shared_examples_for_to_remove_all_masks.rb'
55
-
56
64
  # Offense count: 1
57
65
  # Cop supports --auto-correct.
58
66
  # Configuration parameters: EnforcedStyle.
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_documents (0.2.0)
4
+ br_documents (0.2.3)
5
5
  activemodel (>= 4.0.0)
6
6
  i18n (>= 0.6.5)
7
7
 
@@ -31,7 +31,7 @@ GEM
31
31
  ast (~> 2.4.1)
32
32
  rack (2.2.3)
33
33
  rainbow (3.0.0)
34
- rake (13.0.3)
34
+ rake (13.0.6)
35
35
  regexp_parser (2.1.1)
36
36
  rexml (3.2.5)
37
37
  rspec (3.10.0)
@@ -58,13 +58,15 @@ GEM
58
58
  unicode-display_width (>= 1.4.0, < 3.0)
59
59
  rubocop-ast (1.7.0)
60
60
  parser (>= 3.0.1.1)
61
- rubocop-performance (1.11.3)
61
+ rubocop-performance (1.11.4)
62
62
  rubocop (>= 1.7.0, < 2.0)
63
63
  rubocop-ast (>= 0.4.0)
64
64
  rubocop-rails (2.10.1)
65
65
  activesupport (>= 4.2.0)
66
66
  rack (>= 1.1)
67
67
  rubocop (>= 1.7.0, < 2.0)
68
+ rubocop-rake (0.5.1)
69
+ rubocop
68
70
  rubocop-rspec (2.3.0)
69
71
  rubocop (~> 1.0)
70
72
  rubocop-ast (>= 1.1.0)
@@ -93,8 +95,9 @@ DEPENDENCIES
93
95
  rubocop (~> 1.15.0)
94
96
  rubocop-performance (~> 1.11.3)
95
97
  rubocop-rails (~> 2.10.1)
98
+ rubocop-rake (>= 0.5.1)
96
99
  rubocop-rspec (~> 2.3.0)
97
100
  simplecov (>= 0.21.2)
98
101
 
99
102
  BUNDLED WITH
100
- 2.1.4
103
+ 2.2.33
data/Rakefile CHANGED
@@ -5,6 +5,6 @@ task default: :spec
5
5
  RSpec::Core::RakeTask.new
6
6
 
7
7
  desc "Open an irb session preloaded class's"
8
- task :console do
8
+ task console: :enviroment do
9
9
  sh 'irb -rubygems -I lib -r br_documents.rb'
10
10
  end
data/br_documents.gemspec CHANGED
@@ -2,6 +2,7 @@ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'br_documents/version'
4
4
 
5
+ # rubocop:disable Metrics/BlockLength
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = 'br_documents'
7
8
  spec.version = BrDocuments::VERSION
@@ -29,6 +30,8 @@ Gem::Specification.new do |spec|
29
30
  spec.add_development_dependency 'rubocop', '~> 1.15.0'
30
31
  spec.add_development_dependency 'rubocop-performance', '~> 1.11.3'
31
32
  spec.add_development_dependency 'rubocop-rails', '~> 2.10.1'
33
+ spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
32
34
  spec.add_development_dependency 'rubocop-rspec', '~> 2.3.0'
33
35
  spec.add_development_dependency 'simplecov', '>= 0.21.2'
34
36
  end
37
+ # rubocop:enable Metrics/BlockLength
@@ -24,7 +24,7 @@ module BrDocuments
24
24
  end
25
25
 
26
26
  def sequence_of_equal_numbers?
27
- number_without_mask.split('').uniq.length == 1
27
+ number_without_mask.chars.uniq.length == 1
28
28
  end
29
29
 
30
30
  def valid_check_digit?
@@ -15,14 +15,14 @@ module BrDocuments
15
15
  end
16
16
 
17
17
  def valid_checksum?
18
- numbers = @code.chars[0, @code.length - 1].reverse
18
+ numbers = @code[0, @code.length - 1].chars.reverse
19
19
  odd = even = 0
20
20
 
21
21
  numbers.each_with_index do |number, i|
22
22
  (i + 1).even? ? (even += number.to_i) : (odd += number.to_i * 3)
23
23
  end
24
24
 
25
- @code.chars.last.to_i == ((10 - (odd + even)) % 10)
25
+ @code[-1].to_i == ((10 - (odd + even)) % 10)
26
26
  end
27
27
  end
28
28
  end
@@ -9,7 +9,7 @@ module BrDocuments
9
9
  protected
10
10
 
11
11
  def format_ie(number)
12
- if number.gsub(/-/, '').length == 8
12
+ if number.delete('-').length == 8
13
13
  number.sub(/(\d{6})(\d{2})/, '\\1-\\2')
14
14
  else
15
15
  number.sub(/(\d{7})(\d{2})/, '\\1-\\2')
@@ -13,7 +13,7 @@ module BrDocuments
13
13
  end
14
14
 
15
15
  def valid_format?
16
- regex = /^(\d{3}\.\d{3}\.\d{3}\.\d{2}\-\d{2})$|^(\d{13})$/
16
+ regex = /^(\d{3}\.\d{3}\.\d{3}\/\d{4})$|^(\d{13})$/
17
17
  regex.match(@number).present?
18
18
  end
19
19
 
@@ -15,7 +15,7 @@ module BrDocuments
15
15
 
16
16
  def generate_zeros(number)
17
17
  just_numbers = number.gsub(/[\.\/-]/, '')
18
- zeros = ('0' * 11).slice(just_numbers.length, 11)
18
+ zeros = ('0' * 11).slice(just_numbers.length, 11) if just_numbers.present?
19
19
  yield zeros.to_s if block_given?
20
20
  end
21
21
 
@@ -13,7 +13,7 @@ class IeValidator < ActiveModel::EachValidator
13
13
  end
14
14
 
15
15
  def attribute_uf_was_configured_at_validator?(record)
16
- record.errors.add(:base, I18n.t('validator.ie.uf.no_configured')) unless options[:uf].present?
16
+ record.errors.add(:base, I18n.t('validator.ie.uf.no_configured')) if options[:uf].blank?
17
17
 
18
18
  options[:uf].present?
19
19
  end
@@ -0,0 +1,46 @@
1
+ require_relative './commons/mod11'
2
+
3
+ module BrDocuments
4
+ class Suframa
5
+ include BrDocuments::Commons::Mod11
6
+
7
+ def initialize(number)
8
+ @number = number
9
+ end
10
+
11
+ def formatted
12
+ valid? ? format_number : ''
13
+ end
14
+
15
+ def valid?
16
+ valid_pattern? &&
17
+ !sequence_of_equal_numbers? &&
18
+ valid_check_digit?
19
+ end
20
+
21
+ private
22
+
23
+ def valid_pattern?
24
+ /^(\d{2}\.\d{4}\.\d{3})$|^(\d{9})$/.match(@number).present?
25
+ end
26
+
27
+ def sequence_of_equal_numbers?
28
+ number_without_mask.chars.uniq.length == 1
29
+ end
30
+
31
+ def number_without_mask
32
+ @number_without_mask ||= @number.delete('.')
33
+ end
34
+
35
+ def valid_check_digit?
36
+ weights = [9, 8, 7, 6, 5, 4, 3, 2]
37
+
38
+ check_digit = generate_check_digit(number_without_mask, weights)
39
+ number_without_mask[8] == check_digit.to_s
40
+ end
41
+
42
+ def format_number
43
+ @number.sub(/(\d{2})(\d{4})(\d{3})/, '\\1.\\2.\\3')
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module BrDocuments
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  describe BrDocuments::CnpjCpf::Cnpj do
4
4
  describe '#formatted' do
5
5
  it 'returns a formatted number' do
6
- cnpj = BrDocuments::CnpjCpf::Cnpj.new('04001155000101')
6
+ cnpj = described_class.new('04001155000101')
7
7
  expect(cnpj.formatted).to eq '04.001.155/0001-01'
8
8
  end
9
9
 
10
10
  context 'when is invalid' do
11
11
  it 'returns an empty string' do
12
- cnpj = BrDocuments::CnpjCpf::Cnpj.new('123')
12
+ cnpj = described_class.new('123')
13
13
  expect(cnpj.formatted).to eq ''
14
14
  end
15
15
  end
@@ -17,42 +17,42 @@ describe BrDocuments::CnpjCpf::Cnpj do
17
17
 
18
18
  it 'is invalid with malformed number' do
19
19
  ['242.2818/50001-54', '35.611.011/000192'].each do |number|
20
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(number)
21
- expect(cnpj).to_not be_valid
20
+ cnpj = described_class.new(number)
21
+ expect(cnpj).not_to be_valid
22
22
  end
23
23
  end
24
24
 
25
25
  it 'is invalid with a number longer than 14' do
26
26
  ['24.228.185/0001-544', '936710360001881'].each do |number|
27
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(number)
28
- expect(cnpj).to_not be_valid
27
+ cnpj = described_class.new(number)
28
+ expect(cnpj).not_to be_valid
29
29
  end
30
30
  end
31
31
 
32
32
  it 'is invalid with a number shorter than 14' do
33
33
  ['24.228.185/0001-5', '9367103600018'].each do |number|
34
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(number)
35
- expect(cnpj).to_not be_valid
34
+ cnpj = described_class.new(number)
35
+ expect(cnpj).not_to be_valid
36
36
  end
37
37
  end
38
38
 
39
39
  it 'is invalid with a sequence of the same number' do
40
40
  ['11.111.111/1111-11', '22222222222222'].each do |number|
41
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(number)
42
- expect(cnpj).to_not be_valid
41
+ cnpj = described_class.new(number)
42
+ expect(cnpj).not_to be_valid
43
43
  end
44
44
  end
45
45
 
46
46
  it 'is invalid with invalid check number' do
47
47
  ['04.001.155/0001-03', '85961757000101'].each do |number|
48
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(number)
49
- expect(cnpj).to_not be_valid
48
+ cnpj = described_class.new(number)
49
+ expect(cnpj).not_to be_valid
50
50
  end
51
51
  end
52
52
 
53
53
  it 'is valid with correct number' do
54
54
  ['04.001.155/0001-01', '85961757000102'].each do |number|
55
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(number)
55
+ cnpj = described_class.new(number)
56
56
  expect(cnpj).to be_valid
57
57
  end
58
58
  end
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  describe BrDocuments::CnpjCpf::Cpf do
4
4
  describe '#formatted' do
5
5
  it 'returns a formatted number' do
6
- cpf = BrDocuments::CnpjCpf::Cpf.new('11144477735')
6
+ cpf = described_class.new('11144477735')
7
7
  expect(cpf.formatted).to eq '111.444.777-35'
8
8
  end
9
9
 
10
10
  context 'when is invalid' do
11
11
  it 'returns an empty string' do
12
- cpf = BrDocuments::CnpjCpf::Cpf.new('123')
12
+ cpf = described_class.new('123')
13
13
  expect(cpf.formatted).to eq ''
14
14
  end
15
15
  end
@@ -17,42 +17,42 @@ describe BrDocuments::CnpjCpf::Cpf do
17
17
 
18
18
  it 'is invalid with malformed number' do
19
19
  ['111.126.491.07', '482.261.15-663', '111444.777-35'].each do |number|
20
- cpf = BrDocuments::CnpjCpf::Cpf.new(number)
21
- expect(cpf).to_not be_valid
20
+ cpf = described_class.new(number)
21
+ expect(cpf).not_to be_valid
22
22
  end
23
23
  end
24
24
 
25
25
  it 'is invalid with a number longer than 11' do
26
26
  ['045.769.421-150', '308514217766'].each do |number|
27
- cpf = BrDocuments::CnpjCpf::Cpf.new(number)
28
- expect(cpf).to_not be_valid
27
+ cpf = described_class.new(number)
28
+ expect(cpf).not_to be_valid
29
29
  end
30
30
  end
31
31
 
32
32
  it 'is invalid with a number shorter than 11' do
33
33
  ['111.444.777-3', '1234567890'].each do |number|
34
- cpf = BrDocuments::CnpjCpf::Cpf.new(number)
35
- expect(cpf).to_not be_valid
34
+ cpf = described_class.new(number)
35
+ expect(cpf).not_to be_valid
36
36
  end
37
37
  end
38
38
 
39
39
  it 'is invalid with a sequence of the same number' do
40
40
  ['111.111.111-11', '22222222222'].each do |number|
41
- cpf = BrDocuments::CnpjCpf::Cpf.new(number)
42
- expect(cpf).to_not be_valid
41
+ cpf = described_class.new(number)
42
+ expect(cpf).not_to be_valid
43
43
  end
44
44
  end
45
45
 
46
46
  it 'is invalid with invalid check number' do
47
47
  ['111.111.111-22', '2222222233'].each do |number|
48
- cpf = BrDocuments::CnpjCpf::Cpf.new(number)
49
- expect(cpf).to_not be_valid
48
+ cpf = described_class.new(number)
49
+ expect(cpf).not_to be_valid
50
50
  end
51
51
  end
52
52
 
53
53
  it 'is valid with correct number' do
54
54
  ['111.444.777-35', '01233254120'].each do |number|
55
- cpf = BrDocuments::CnpjCpf::Cpf.new(number)
55
+ cpf = described_class.new(number)
56
56
  expect(cpf).to be_valid
57
57
  end
58
58
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe CnpjValidator do
4
+ subject { described_class.new(attributes: 'cnpj') }
5
+
6
+ let(:mock) { instance_double('model') }
7
+
8
+ before do
9
+ allow(mock).to receive(:errors).and_return([])
10
+ allow(mock.errors).to receive(:messages).and_return({})
11
+ allow(mock.errors).to receive(:add) do |attribute, error|
12
+ mock.errors.messages[attribute] = [error]
13
+ end
14
+ end
15
+
16
+ context 'when Cnpj is valid' do
17
+ it "doesn't add errors in model" do
18
+ subject.validate_each(mock, 'cnpj', '85961757000102')
19
+ expect(mock.errors.messages).to be_empty
20
+ end
21
+ end
22
+
23
+ context 'when Cnpj is blank' do
24
+ it "doesn't add errors in model" do
25
+ subject.validate_each(mock, 'cnpj', '')
26
+ expect(mock.errors.messages).to be_empty
27
+ end
28
+ end
29
+
30
+ context 'when Cnpj is invalid' do
31
+ it 'adds errors in model' do
32
+ subject.validate_each(mock, 'cnpj', '85961757000103')
33
+ expect(mock.errors.messages).not_to be_empty
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe CpfValidator do
4
+ subject { described_class.new(attributes: 'cpf') }
5
+
6
+ let(:mock) { instance_double('model') }
7
+
8
+ before do
9
+ allow(mock).to receive(:errors).and_return([])
10
+ allow(mock.errors).to receive(:messages).and_return({})
11
+ allow(mock.errors).to receive(:add) do |attribute, error|
12
+ mock.errors.messages[attribute] = [error]
13
+ end
14
+ end
15
+
16
+ context 'when Cpf is valid' do
17
+ it "doesn't add errors in model" do
18
+ subject.validate_each(mock, 'cpf', '01233254120')
19
+ expect(mock.errors.messages).to be_empty
20
+ end
21
+ end
22
+
23
+ context 'when Cpf is blank' do
24
+ it "doesn't add errors in model" do
25
+ subject.validate_each(mock, 'cpf', '')
26
+ expect(mock.errors.messages).to be_empty
27
+ end
28
+ end
29
+
30
+ context 'when Cpf is invalid' do
31
+ it 'adds errors in model' do
32
+ subject.validate_each(mock, 'cpf', '01233254121')
33
+ expect(mock.errors.messages).not_to be_empty
34
+ end
35
+ end
36
+ end
@@ -36,14 +36,14 @@ describe BrDocuments::Gtin do
36
36
  context 'when the number of digits is different of 8, 13 or 14' do
37
37
  subject { described_class.new('12345678901234560') }
38
38
 
39
- it { is_expected.to_not be_valid }
39
+ it { is_expected.not_to be_valid }
40
40
  end
41
41
  end
42
42
 
43
43
  context 'when the checksum is invald' do
44
44
  subject { described_class.new('1145678548712') }
45
45
 
46
- it { is_expected.to_not be_valid }
46
+ it { is_expected.not_to be_valid }
47
47
  end
48
48
  end
49
49
  end
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GtinValidator do
4
- let(:record) { double('model') }
4
+ subject { described_class.new(attributes: 'gtin') }
5
+
6
+ let(:record) { instance_double('model') }
5
7
 
6
8
  before do
7
9
  allow(record).to receive(:errors).and_return([])
@@ -11,8 +13,6 @@ describe GtinValidator do
11
13
  end
12
14
  end
13
15
 
14
- subject { GtinValidator.new(attributes: 'gtin') }
15
-
16
16
  context 'when GTIN code is valid' do
17
17
  before { subject.validate_each(record, 'gtin', '1243658721548') }
18
18
 
@@ -13,21 +13,21 @@ RSpec.describe BrDocuments::IE::AC do
13
13
  it 'is invalid with malformed number' do
14
14
  ['01.448.52/88.91-50', '01.278.704/5555-7', '01.AB7.904/028-50'].each do |number|
15
15
  ie = described_class.new(number)
16
- expect(ie).to_not be_valid
16
+ expect(ie).not_to be_valid
17
17
  end
18
18
  end
19
19
 
20
20
  it 'is invalid with length different to 13' do
21
21
  ['1234567890', '123456789012'].each do |number|
22
22
  ie = described_class.new(number)
23
- expect(ie).to_not be_valid
23
+ expect(ie).not_to be_valid
24
24
  end
25
25
  end
26
26
 
27
27
  it 'is invalid with invalid check number' do
28
28
  ['0135184641523', '0172567054082'].each do |number|
29
29
  ie = described_class.new(number)
30
- expect(ie).to_not be_valid
30
+ expect(ie).not_to be_valid
31
31
  end
32
32
  end
33
33
 
@@ -13,14 +13,14 @@ describe BrDocuments::IE::AL do
13
13
  it 'is invalid with length different to 9' do
14
14
  ['1234567', '122345678901'].each do |number|
15
15
  ie = described_class.new(number)
16
- expect(ie).to_not be_valid
16
+ expect(ie).not_to be_valid
17
17
  end
18
18
  end
19
19
 
20
20
  it 'is invalid with invalid check number' do
21
21
  ['245320152', '240046248'].each do |number|
22
22
  ie = described_class.new(number)
23
- expect(ie).to_not be_valid
23
+ expect(ie).not_to be_valid
24
24
  end
25
25
  end
26
26
 
@@ -13,21 +13,21 @@ describe BrDocuments::IE::AM do
13
13
  it 'is invalid with malformed number' do
14
14
  ['8.535.410-60', '884.67.826-1', '13.BA9.093-6'].each do |number|
15
15
  ie = described_class.new(number)
16
- expect(ie).to_not be_valid
16
+ expect(ie).not_to be_valid
17
17
  end
18
18
  end
19
19
 
20
20
  it 'is invalid with length different to 9' do
21
21
  ['1234567', '12345678901'].each do |number|
22
22
  ie = described_class.new(number)
23
- expect(ie).to_not be_valid
23
+ expect(ie).not_to be_valid
24
24
  end
25
25
  end
26
26
 
27
27
  it 'is invalid with invalid check number' do
28
28
  ['500085276', '886770232'].each do |number|
29
29
  ie = described_class.new(number)
30
- expect(ie).to_not be_valid
30
+ expect(ie).not_to be_valid
31
31
  end
32
32
  end
33
33