br_documents 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/config.yml +54 -0
  3. data/.rubocop.yml +65 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +76 -42
  6. data/README.md +33 -0
  7. data/Rakefile +3 -3
  8. data/br_documents.gemspec +23 -19
  9. data/lib/br_documents.rb +3 -3
  10. data/lib/br_documents/cnpj_cpf/cnpj.rb +2 -2
  11. data/lib/br_documents/cnpj_cpf/cpf.rb +2 -2
  12. data/lib/br_documents/cnpj_cpf/document.rb +9 -9
  13. data/lib/br_documents/cnpj_validator.rb +4 -4
  14. data/lib/br_documents/commons/mod11.rb +1 -2
  15. data/lib/br_documents/commons/mod14.rb +1 -2
  16. data/lib/br_documents/cpf_validator.rb +4 -4
  17. data/lib/br_documents/gtin/gtin.rb +1 -1
  18. data/lib/br_documents/gtin_validator.rb +6 -6
  19. data/lib/br_documents/ie/ac.rb +3 -2
  20. data/lib/br_documents/ie/al.rb +2 -1
  21. data/lib/br_documents/ie/am.rb +3 -2
  22. data/lib/br_documents/ie/ap.rb +20 -16
  23. data/lib/br_documents/ie/ba.rb +28 -25
  24. data/lib/br_documents/ie/base.rb +1 -1
  25. data/lib/br_documents/ie/ce.rb +3 -2
  26. data/lib/br_documents/ie/df.rb +3 -2
  27. data/lib/br_documents/ie/es.rb +2 -1
  28. data/lib/br_documents/ie/factory.rb +3 -3
  29. data/lib/br_documents/ie/go.rb +3 -2
  30. data/lib/br_documents/ie/ma.rb +2 -1
  31. data/lib/br_documents/ie/mg.rb +14 -17
  32. data/lib/br_documents/ie/ms.rb +2 -1
  33. data/lib/br_documents/ie/mt.rb +6 -5
  34. data/lib/br_documents/ie/pa.rb +3 -2
  35. data/lib/br_documents/ie/pattern1.rb +10 -7
  36. data/lib/br_documents/ie/pattern2.rb +9 -8
  37. data/lib/br_documents/ie/pb.rb +3 -2
  38. data/lib/br_documents/ie/pe.rb +10 -10
  39. data/lib/br_documents/ie/pi.rb +2 -1
  40. data/lib/br_documents/ie/pr.rb +3 -2
  41. data/lib/br_documents/ie/rj.rb +3 -2
  42. data/lib/br_documents/ie/rn.rb +19 -16
  43. data/lib/br_documents/ie/ro.rb +16 -13
  44. data/lib/br_documents/ie/rr.rb +4 -3
  45. data/lib/br_documents/ie/rs.rb +3 -2
  46. data/lib/br_documents/ie/sc.rb +3 -2
  47. data/lib/br_documents/ie/se.rb +3 -2
  48. data/lib/br_documents/ie/sp.rb +17 -14
  49. data/lib/br_documents/ie/to.rb +6 -5
  50. data/lib/br_documents/ie_validator.rb +7 -7
  51. data/lib/br_documents/suframa/suframa.rb +60 -0
  52. data/lib/br_documents/suframa_validator.rb +8 -0
  53. data/lib/br_documents/version.rb +1 -1
  54. data/spec/cnpj_cpf/cnpj_spec.rb +21 -21
  55. data/spec/cnpj_cpf/cpf_spec.rb +21 -21
  56. data/spec/cnpj_validator_spec.rb +12 -12
  57. data/spec/cpf_validator_spec.rb +12 -12
  58. data/spec/gtin/gtin_spec.rb +2 -2
  59. data/spec/gtin_validator_spec.rb +13 -13
  60. data/spec/ie/ac_spec.rb +16 -16
  61. data/spec/ie/al_spec.rb +14 -14
  62. data/spec/ie/am_spec.rb +16 -16
  63. data/spec/ie/ap_spec.rb +14 -14
  64. data/spec/ie/ba_spec.rb +28 -28
  65. data/spec/ie/ce_spec.rb +9 -9
  66. data/spec/ie/df_spec.rb +16 -16
  67. data/spec/ie/es_spec.rb +9 -9
  68. data/spec/ie/factory_spec.rb +88 -89
  69. data/spec/ie/go_spec.rb +16 -16
  70. data/spec/ie/ma_spec.rb +9 -9
  71. data/spec/ie/mg_spec.rb +16 -16
  72. data/spec/ie/ms_spec.rb +9 -9
  73. data/spec/ie/mt_spec.rb +17 -17
  74. data/spec/ie/pa_spec.rb +16 -16
  75. data/spec/ie/pb_spec.rb +9 -9
  76. data/spec/ie/pe_spec.rb +27 -27
  77. data/spec/ie/pi_spec.rb +9 -9
  78. data/spec/ie/pr_spec.rb +14 -14
  79. data/spec/ie/rj_spec.rb +16 -16
  80. data/spec/ie/rn_spec.rb +27 -27
  81. data/spec/ie/ro_spec.rb +27 -27
  82. data/spec/ie/rr_spec.rb +16 -16
  83. data/spec/ie/rs_spec.rb +16 -16
  84. data/spec/ie/sc_spec.rb +16 -16
  85. data/spec/ie/se_spec.rb +9 -9
  86. data/spec/ie/shared_examples_for_pattern1.rb +11 -11
  87. data/spec/ie/shared_examples_for_to_remove_all_masks.rb +7 -8
  88. data/spec/ie/sp_spec.rb +19 -19
  89. data/spec/ie/to_spec.rb +35 -35
  90. data/spec/ie_validator_spec.rb +7 -5
  91. data/spec/spec_helper.rb +6 -6
  92. data/spec/suframa/suframa_spec.rb +109 -0
  93. data/spec/suframa_validator_spec.rb +36 -0
  94. data/spec/support/utilities.rb +2 -2
  95. metadata +86 -23
  96. data/.circleci/config.yml +0 -42
@@ -4,10 +4,10 @@ RSpec.describe IeValidator do
4
4
  let(:record) { double('model') }
5
5
 
6
6
  before do
7
- allow(record).to receive(:uf) {'SC'}
7
+ allow(record).to receive(:uf) { 'SC' }
8
8
  allow(record).to receive(:errors).and_return({})
9
9
  allow(record.errors).to receive(:messages).and_return({})
10
- allow(record.errors).to receive(:add) do | attribute, error |
10
+ allow(record.errors).to receive(:add) do |attribute, error|
11
11
  record.errors[attribute] ||= []
12
12
  record.errors[attribute] << error
13
13
  record.errors.messages[attribute] = record.errors[attribute]
@@ -50,7 +50,7 @@ RSpec.describe IeValidator do
50
50
 
51
51
  context 'when UF is invalid' do
52
52
  before do
53
- allow(record).to receive(:uf) {'XX'}
53
+ allow(record).to receive(:uf) { 'XX' }
54
54
  subject.validate_each(record, 'ie', '253667852')
55
55
  end
56
56
 
@@ -67,7 +67,8 @@ RSpec.describe IeValidator do
67
67
 
68
68
  it 'adds error in model' do
69
69
  expect(record.errors.messages[:base]).to eql [
70
- t('validator.ie.uf.no_present', uf: 'uf')]
70
+ t('validator.ie.uf.no_present', uf: 'uf')
71
+ ]
71
72
  end
72
73
  end
73
74
 
@@ -77,7 +78,8 @@ RSpec.describe IeValidator do
77
78
 
78
79
  it 'adds error in model' do
79
80
  expect(record.errors.messages[:base]).to eql [
80
- t('validator.ie.uf.no_configured')]
81
+ t('validator.ie.uf.no_configured')
82
+ ]
81
83
  end
82
84
  end
83
85
  end
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,14 @@
1
- require "simplecov"
1
+ require 'simplecov'
2
2
  SimpleCov.start
3
3
 
4
- require "bundler/setup"
4
+ require 'bundler/setup'
5
5
  Bundler.require(:default, :development)
6
6
 
7
- require "br_documents"
7
+ require 'br_documents'
8
8
 
9
- Dir[File.dirname(__FILE__) + "/support/*.rb"].each { |f| require f }
9
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each { |f| require f }
10
10
 
11
- I18n.default_locale = "pt-BR"
11
+ I18n.default_locale = 'pt-BR'
12
12
 
13
13
  RSpec.configure do |config|
14
14
  config.expect_with :rspec do |c|
@@ -18,5 +18,5 @@ RSpec.configure do |config|
18
18
  config.filter_run focus: true
19
19
  config.run_all_when_everything_filtered = true
20
20
 
21
- config.order = "random"
21
+ config.order = 'random'
22
22
  end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDocuments::Suframa do
4
+ subject { described_class.new }
5
+
6
+ describe '#formatted' do
7
+ it 'returns the formatted number' do
8
+ value = '100698107'
9
+
10
+ subject = described_class.new(value)
11
+
12
+ expect(subject.formatted).to eql '10.0698.107'
13
+ end
14
+
15
+ context 'when number is invalid' do
16
+ it 'returns a empty string' do
17
+ value = '123'
18
+
19
+ subject = described_class.new(value)
20
+
21
+ expect(subject.formatted).to eql ''
22
+ end
23
+ end
24
+
25
+ it 'is invalid if number is malformed' do
26
+ ['121.23.4123', '5.50.309.012', '5.503.090.12'].each do |number|
27
+ suframa = BrDocuments::Suframa.new(number)
28
+
29
+ expect(suframa).to_not be_valid
30
+ end
31
+ end
32
+
33
+ it 'is invalid with a number longer than 9' do
34
+ ['1234567890', '12.3456.7890'].each do |number|
35
+ suframa = BrDocuments::Suframa.new(number)
36
+
37
+ expect(suframa).to_not be_valid
38
+ end
39
+ end
40
+
41
+ it 'is invalid with a number shorter than 9' do
42
+ ['12345678', '12.3456.78'].each do |number|
43
+ suframa = BrDocuments::Suframa.new(number)
44
+
45
+ expect(suframa).to_not be_valid
46
+ end
47
+ end
48
+
49
+ it 'is invalid with a sequence of the same number' do
50
+ ['11.1111.111', '111111111'].each do |number|
51
+ suframa = BrDocuments::Suframa.new(number)
52
+
53
+ expect(suframa).to_not be_valid
54
+ end
55
+ end
56
+
57
+ it 'is invalid with invalid verifying digit' do
58
+ ['55.0309.010', '550309010'].each do |number|
59
+ suframa = BrDocuments::Suframa.new(number)
60
+
61
+ expect(suframa).to_not be_valid
62
+ end
63
+ end
64
+
65
+ it 'is valid with correct number' do
66
+ ['11.1279.100', '10.1040.105', '100628109', '100698107'].each do |number|
67
+ suframa = BrDocuments::Suframa.new(number)
68
+
69
+ expect(suframa).to be_valid
70
+ end
71
+ end
72
+
73
+ context 'activity sector' do
74
+ it 'is valid when activity_sector is in 01, 02, 10, 11, 20, 60' do
75
+ ['11.1279.100', '10.1040.105'].each do |number|
76
+ suframa = BrDocuments::Suframa.new(number)
77
+
78
+ expect(suframa).to be_valid
79
+ end
80
+ end
81
+
82
+ it 'is invalid when activity_sector is not in 01, 02, 10, 11, 20, 60' do
83
+ ['17.1279.107', '141161108'].each do |number|
84
+ suframa = BrDocuments::Suframa.new(number)
85
+
86
+ expect(suframa).to_not be_valid
87
+ end
88
+ end
89
+ end
90
+
91
+ context 'administration unit' do
92
+ it 'is valid when adm_unit is in 01, 10, 30' do
93
+ ['11.1279.100', '101160100'].each do |number|
94
+ suframa = BrDocuments::Suframa.new(number)
95
+
96
+ expect(suframa).to be_valid
97
+ end
98
+ end
99
+
100
+ it 'is invalid when adm_unit is not in 01, 10, 30' do
101
+ ['11.1279.124', '101160160'].each do |number|
102
+ suframa = BrDocuments::Suframa.new(number)
103
+
104
+ expect(suframa).to_not be_valid
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe SuframaValidator do
4
+ let(:mock) { double('mode') }
5
+
6
+ before do
7
+ allow(mock).to receive(:errors).and_return([])
8
+ allow(mock.errors).to receive(:messages).and_return({})
9
+ allow(mock.errors).to receive(:add) do |attribute, error|
10
+ mock.errors.messages[attribute] = [error]
11
+ end
12
+ end
13
+
14
+ subject { SuframaValidator.new(attributes: 'suframa') }
15
+
16
+ context 'when SUFRAMA is valid' do
17
+ it "doesn't add errors in model" do
18
+ subject.validate_each(mock, 'suframa', '600215105')
19
+ expect(mock.errors.messages).to be_empty
20
+ end
21
+ end
22
+
23
+ context 'when SUFRAMA is blank' do
24
+ it "doesn't add errors in model" do
25
+ subject.validate_each(mock, 'suframa', '')
26
+ expect(mock.errors.messages).to be_empty
27
+ end
28
+ end
29
+
30
+ context 'when SUFRAMA is invalid' do
31
+ it 'adds errors in model' do
32
+ subject.validate_each(mock, 'suframa', '01233254121')
33
+ expect(mock.errors.messages).to_not be_empty
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
- def t(string, options={})
1
+ def t(string, options = {})
2
2
  I18n.t(string, options)
3
- end
3
+ end
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.1.3
4
+ version: 0.2.0
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: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -53,75 +53,131 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 10.1.0
61
+ version: 11.1.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 10.1.0
68
+ version: 11.1.3
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: codeclimate-test-reporter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 3.0.0
75
+ version: 1.0.7
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.0.0
82
+ version: 1.0.7
83
83
  - !ruby/object:Gem::Dependency
84
- name: codeclimate-test-reporter
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 13.0.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 13.0.3
97
97
  - !ruby/object:Gem::Dependency
98
- name: simplecov
98
+ name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 0.9.0
103
+ version: 3.10.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 0.9.0
110
+ version: 3.10.0
111
111
  - !ruby/object:Gem::Dependency
112
- name: byebug
112
+ name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '='
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 10.0.2
117
+ version: 1.15.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '='
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.15.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.11.3
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.11.3
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.10.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.10.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 2.3.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 2.3.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: 0.21.2
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
123
179
  - !ruby/object:Gem::Version
124
- version: 10.0.2
180
+ version: 0.21.2
125
181
  description: Validates brazilian documents like CPF, CNPJ and IE.
126
182
  email:
127
183
  - asseinfo@asseinfo.com.br
@@ -129,9 +185,10 @@ executables: []
129
185
  extensions: []
130
186
  extra_rdoc_files: []
131
187
  files:
132
- - ".circleci/config.yml"
188
+ - ".github/workflows/config.yml"
133
189
  - ".gitignore"
134
190
  - ".rspec"
191
+ - ".rubocop.yml"
135
192
  - Gemfile
136
193
  - Gemfile.lock
137
194
  - README.md
@@ -180,6 +237,8 @@ files:
180
237
  - lib/br_documents/ie/sp.rb
181
238
  - lib/br_documents/ie/to.rb
182
239
  - lib/br_documents/ie_validator.rb
240
+ - lib/br_documents/suframa/suframa.rb
241
+ - lib/br_documents/suframa_validator.rb
183
242
  - lib/br_documents/version.rb
184
243
  - spec/cnpj_cpf/cnpj_spec.rb
185
244
  - spec/cnpj_cpf/cpf_spec.rb
@@ -219,6 +278,8 @@ files:
219
278
  - spec/ie/to_spec.rb
220
279
  - spec/ie_validator_spec.rb
221
280
  - spec/spec_helper.rb
281
+ - spec/suframa/suframa_spec.rb
282
+ - spec/suframa_validator_spec.rb
222
283
  - spec/support/utilities.rb
223
284
  homepage: http://github.com/asseinfo/br_documents
224
285
  licenses:
@@ -239,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
300
  - !ruby/object:Gem::Version
240
301
  version: '0'
241
302
  requirements: []
242
- rubygems_version: 3.0.3
303
+ rubygems_version: 3.1.6
243
304
  signing_key:
244
305
  specification_version: 4
245
306
  summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with
@@ -283,4 +344,6 @@ test_files:
283
344
  - spec/ie/to_spec.rb
284
345
  - spec/ie_validator_spec.rb
285
346
  - spec/spec_helper.rb
347
+ - spec/suframa/suframa_spec.rb
348
+ - spec/suframa_validator_spec.rb
286
349
  - spec/support/utilities.rb
data/.circleci/config.yml DELETED
@@ -1,42 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.5.1
6
- steps:
7
- - checkout
8
- - restore_cache:
9
- key: br-documents-cache-v1-{{ checksum "Gemfile.lock" }}
10
- - run: bundle check || bundle install
11
- - save_cache:
12
- key: br-documents-cache-v1-{{ .Environment.CIRCLE_SHA1 }}
13
- paths:
14
- - .
15
- - save_cache:
16
- key: br-documents-cache-v1-{{ checksum "Gemfile.lock" }}
17
- paths:
18
- - ./vendor/bundle
19
- rspec:
20
- docker:
21
- - image: circleci/ruby:2.5.1
22
- steps:
23
- - restore_cache:
24
- key: br-documents-cache-v1-{{ .Environment.CIRCLE_SHA1 }}
25
- - restore_cache:
26
- key: br-documents-cache-v1-{{ checksum "Gemfile.lock" }}
27
- - run:
28
- name: Install Test Coverage for CodeClimate
29
- command: |
30
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
31
- chmod +x ./cc-test-reporter
32
- - run: ./cc-test-reporter before-build
33
- - run: bundle exec rspec
34
- - run: ./cc-test-reporter after-build --exit-code $?
35
- workflows:
36
- version: 2
37
- main:
38
- jobs:
39
- - build
40
- - rspec:
41
- requires:
42
- - build