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
@@ -13,21 +13,21 @@ describe BrDocuments::IE::SC do
13
13
  it 'is invalid with malformed number' do
14
14
  ['253.66.7852', '25.4062.407', 'A12345678'].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
  ['1234567890', '12345678'].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
  ['253667853', '254.062.408'].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
 
File without changes
@@ -5,21 +5,21 @@ shared_examples 'a pattern1' do |uf|
5
5
  it 'is invalid with malformed number' do
6
6
  ['1922212-21', '72.219.398-0', '63BA9943-8'].each do |number|
7
7
  ie = described_class.create(uf, number)
8
- expect(ie).to_not be_valid
8
+ expect(ie).not_to be_valid
9
9
  end
10
10
  end
11
11
 
12
12
  it 'is invalid with length different to 9' do
13
13
  ['1234567', '12345678901'].each do |number|
14
14
  ie = described_class.create(uf, number)
15
- expect(ie).to_not be_valid
15
+ expect(ie).not_to be_valid
16
16
  end
17
17
  end
18
18
 
19
19
  it 'is invalid with invalid check number' do
20
20
  ['226905727', '662637732'].each do |number|
21
21
  ie = described_class.create(uf, number)
22
- expect(ie).to_not be_valid
22
+ expect(ie).not_to be_valid
23
23
  end
24
24
  end
25
25
 
@@ -22,14 +22,14 @@ describe BrDocuments::IE::SP do
22
22
  it 'is invalid with malformed number' do
23
23
  ['36.9107.395114', '527.08212.8110'].each do |number|
24
24
  ie = described_class.new(number)
25
- expect(ie).to_not be_valid
25
+ expect(ie).not_to be_valid
26
26
  end
27
27
  end
28
28
 
29
29
  it 'is invalid with invalid check number' do
30
30
  ['110042490113', '110.042.491.114', 'P-01100424.4/002'].each do |number|
31
31
  ie = described_class.new(number)
32
- expect(ie).to_not be_valid
32
+ expect(ie).not_to be_valid
33
33
  end
34
34
  end
35
35
 
@@ -24,14 +24,14 @@ describe BrDocuments::IE::TO do
24
24
  it 'is invalid with malformed number' do
25
25
  ['2.903.593.362-3', '29.02.79268-45', '29.02.5AB420-5'].each do |number|
26
26
  ie = described_class.new(number)
27
- expect(ie).to_not be_valid
27
+ expect(ie).not_to be_valid
28
28
  end
29
29
  end
30
30
 
31
31
  it 'is invalid with length different of 9 or 11' do
32
32
  ['12345678', '1234567890', '123456789012'].each do |number|
33
33
  ie = described_class.new(number)
34
- expect(ie).to_not be_valid
34
+ expect(ie).not_to be_valid
35
35
  end
36
36
  end
37
37
 
@@ -39,14 +39,14 @@ describe BrDocuments::IE::TO do
39
39
  it 'is invalid with invalid check number' do
40
40
  ['290227835', '294083153'].each do |number|
41
41
  ie = described_class.new(number)
42
- expect(ie).to_not be_valid
42
+ expect(ie).not_to be_valid
43
43
  end
44
44
  end
45
45
 
46
46
  it 'is invalid with correct check number but invalid mask' do
47
47
  ['29-022783-6', '29.408315.4'].each do |number|
48
48
  ie = described_class.new(number)
49
- expect(ie).to_not be_valid
49
+ expect(ie).not_to be_valid
50
50
  end
51
51
  end
52
52
 
@@ -69,14 +69,14 @@ describe BrDocuments::IE::TO do
69
69
  it 'is invalid with invalid check number' do
70
70
  ['29023864406', '29023864409'].each do |number|
71
71
  ie = described_class.new(number)
72
- expect(ie).to_not be_valid
72
+ expect(ie).not_to be_valid
73
73
  end
74
74
  end
75
75
 
76
76
  it 'is invalid with correct check number but invalid mask' do
77
77
  ['29-99.200143-6', '29.99.231741.7'].each do |number|
78
78
  ie = described_class.new(number)
79
- expect(ie).to_not be_valid
79
+ expect(ie).not_to be_valid
80
80
  end
81
81
  end
82
82
 
@@ -1,10 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe IeValidator do
4
- let(:record) { double('model') }
4
+ subject { described_class.new(attributes: 'ie', uf: 'uf') }
5
+
6
+ let(:record) { instance_double('model') }
5
7
 
6
8
  before do
7
- allow(record).to receive(:uf) { 'SC' }
9
+ allow(record).to receive(:uf).and_return('SC')
8
10
  allow(record).to receive(:errors).and_return({})
9
11
  allow(record.errors).to receive(:messages).and_return({})
10
12
  allow(record.errors).to receive(:add) do |attribute, error|
@@ -14,8 +16,6 @@ RSpec.describe IeValidator do
14
16
  end
15
17
  end
16
18
 
17
- subject { IeValidator.new(attributes: 'ie', uf: 'uf') }
18
-
19
19
  context "when IE's number is valid" do
20
20
  before { subject.validate_each(record, 'ie', '253667852') }
21
21
 
@@ -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).and_return('XX')
54
54
  subject.validate_each(record, 'ie', '253667852')
55
55
  end
56
56
 
@@ -73,7 +73,8 @@ RSpec.describe IeValidator do
73
73
  end
74
74
 
75
75
  context 'when attribute uf is not defined' do
76
- subject { IeValidator.new(attributes: 'ie') }
76
+ subject { described_class.new(attributes: 'ie') }
77
+
77
78
  before { subject.validate_each(record, 'ie', '253667852') }
78
79
 
79
80
  it 'adds error in model' do
@@ -0,0 +1,73 @@
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 = described_class.new(number)
28
+
29
+ expect(suframa).not_to 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 = described_class.new(number)
36
+
37
+ expect(suframa).not_to 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 = described_class.new(number)
44
+
45
+ expect(suframa).not_to 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 = described_class.new(number)
52
+
53
+ expect(suframa).not_to 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 = described_class.new(number)
60
+
61
+ expect(suframa).not_to 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 = described_class.new(number)
68
+
69
+ expect(suframa).to be_valid
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SuframaValidator do
4
- let(:mock) { double('mode') }
4
+ subject { described_class.new(attributes: 'suframa') }
5
+
6
+ let(:mock) { instance_double('mode') }
5
7
 
6
8
  before do
7
9
  allow(mock).to receive(:errors).and_return([])
@@ -11,8 +13,6 @@ describe SuframaValidator do
11
13
  end
12
14
  end
13
15
 
14
- subject { SuframaValidator.new(attributes: 'suframa') }
15
-
16
16
  context 'when SUFRAMA is valid' do
17
17
  it "doesn't add errors in model" do
18
18
  subject.validate_each(mock, 'suframa', '600215105')
@@ -30,7 +30,7 @@ describe SuframaValidator do
30
30
  context 'when SUFRAMA is invalid' do
31
31
  it 'adds errors in model' do
32
32
  subject.validate_each(mock, 'suframa', '01233254121')
33
- expect(mock.errors.messages).to_not be_empty
33
+ expect(mock.errors.messages).not_to be_empty
34
34
  end
35
35
  end
36
36
  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.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ASSEINFO - Sistemas de Informação
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-08 00:00:00.000000000 Z
11
+ date: 2022-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.10.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 0.5.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 0.5.1
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-rspec
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -189,6 +203,7 @@ files:
189
203
  - ".gitignore"
190
204
  - ".rspec"
191
205
  - ".rubocop.yml"
206
+ - ".tool-versions"
192
207
  - Gemfile
193
208
  - Gemfile.lock
194
209
  - README.md
@@ -203,7 +218,7 @@ files:
203
218
  - lib/br_documents/commons/mod11.rb
204
219
  - lib/br_documents/commons/mod14.rb
205
220
  - lib/br_documents/cpf_validator.rb
206
- - lib/br_documents/gtin/gtin.rb
221
+ - lib/br_documents/gtin.rb
207
222
  - lib/br_documents/gtin_validator.rb
208
223
  - lib/br_documents/ie/ac.rb
209
224
  - lib/br_documents/ie/al.rb
@@ -237,55 +252,55 @@ files:
237
252
  - lib/br_documents/ie/sp.rb
238
253
  - lib/br_documents/ie/to.rb
239
254
  - lib/br_documents/ie_validator.rb
240
- - lib/br_documents/suframa/suframa.rb
255
+ - lib/br_documents/suframa.rb
241
256
  - lib/br_documents/suframa_validator.rb
242
257
  - lib/br_documents/version.rb
243
- - spec/cnpj_cpf/cnpj_spec.rb
244
- - spec/cnpj_cpf/cpf_spec.rb
245
- - spec/cnpj_validator_spec.rb
246
- - spec/cpf_validator_spec.rb
247
- - spec/gtin/gtin_spec.rb
248
- - spec/gtin_validator_spec.rb
249
- - spec/ie/ac_spec.rb
250
- - spec/ie/al_spec.rb
251
- - spec/ie/am_spec.rb
252
- - spec/ie/ap_spec.rb
253
- - spec/ie/ba_spec.rb
254
- - spec/ie/ce_spec.rb
255
- - spec/ie/df_spec.rb
256
- - spec/ie/es_spec.rb
257
- - spec/ie/factory_spec.rb
258
- - spec/ie/go_spec.rb
259
- - spec/ie/ma_spec.rb
260
- - spec/ie/mg_spec.rb
261
- - spec/ie/ms_spec.rb
262
- - spec/ie/mt_spec.rb
263
- - spec/ie/pa_spec.rb
264
- - spec/ie/pb_spec.rb
265
- - spec/ie/pe_spec.rb
266
- - spec/ie/pi_spec.rb
267
- - spec/ie/pr_spec.rb
268
- - spec/ie/rj_spec.rb
269
- - spec/ie/rn_spec.rb
270
- - spec/ie/ro_spec.rb
271
- - spec/ie/rr_spec.rb
272
- - spec/ie/rs_spec.rb
273
- - spec/ie/sc_spec.rb
274
- - spec/ie/se_spec.rb
275
- - spec/ie/shared_examples_for_pattern1.rb
276
- - spec/ie/shared_examples_for_to_remove_all_masks.rb
277
- - spec/ie/sp_spec.rb
278
- - spec/ie/to_spec.rb
279
- - spec/ie_validator_spec.rb
258
+ - spec/br_documents/cnpj_cpf/cnpj_spec.rb
259
+ - spec/br_documents/cnpj_cpf/cpf_spec.rb
260
+ - spec/br_documents/cnpj_validator_spec.rb
261
+ - spec/br_documents/cpf_validator_spec.rb
262
+ - spec/br_documents/gtin_spec.rb
263
+ - spec/br_documents/gtin_validator_spec.rb
264
+ - spec/br_documents/ie/ac_spec.rb
265
+ - spec/br_documents/ie/al_spec.rb
266
+ - spec/br_documents/ie/am_spec.rb
267
+ - spec/br_documents/ie/ap_spec.rb
268
+ - spec/br_documents/ie/ba_spec.rb
269
+ - spec/br_documents/ie/ce_spec.rb
270
+ - spec/br_documents/ie/df_spec.rb
271
+ - spec/br_documents/ie/es_spec.rb
272
+ - spec/br_documents/ie/factory_spec.rb
273
+ - spec/br_documents/ie/go_spec.rb
274
+ - spec/br_documents/ie/ma_spec.rb
275
+ - spec/br_documents/ie/mg_spec.rb
276
+ - spec/br_documents/ie/ms_spec.rb
277
+ - spec/br_documents/ie/mt_spec.rb
278
+ - spec/br_documents/ie/pa_spec.rb
279
+ - spec/br_documents/ie/pb_spec.rb
280
+ - spec/br_documents/ie/pe_spec.rb
281
+ - spec/br_documents/ie/pi_spec.rb
282
+ - spec/br_documents/ie/pr_spec.rb
283
+ - spec/br_documents/ie/rj_spec.rb
284
+ - spec/br_documents/ie/rn_spec.rb
285
+ - spec/br_documents/ie/ro_spec.rb
286
+ - spec/br_documents/ie/rr_spec.rb
287
+ - spec/br_documents/ie/rs_spec.rb
288
+ - spec/br_documents/ie/sc_spec.rb
289
+ - spec/br_documents/ie/se_spec.rb
290
+ - spec/br_documents/ie/shared_examples_for_pattern1.rb
291
+ - spec/br_documents/ie/shared_examples_for_to_remove_all_masks.rb
292
+ - spec/br_documents/ie/sp_spec.rb
293
+ - spec/br_documents/ie/to_spec.rb
294
+ - spec/br_documents/ie_validator_spec.rb
295
+ - spec/br_documents/suframa_spec.rb
296
+ - spec/br_documents/suframa_validator_spec.rb
280
297
  - spec/spec_helper.rb
281
- - spec/suframa/suframa_spec.rb
282
- - spec/suframa_validator_spec.rb
283
298
  - spec/support/utilities.rb
284
299
  homepage: http://github.com/asseinfo/br_documents
285
300
  licenses:
286
301
  - MIT
287
302
  metadata: {}
288
- post_install_message:
303
+ post_install_message:
289
304
  rdoc_options: []
290
305
  require_paths:
291
306
  - lib
@@ -301,49 +316,49 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
316
  version: '0'
302
317
  requirements: []
303
318
  rubygems_version: 3.1.6
304
- signing_key:
319
+ signing_key:
305
320
  specification_version: 4
306
321
  summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with
307
322
  active record or just in ruby.
308
323
  test_files:
309
- - spec/cnpj_cpf/cnpj_spec.rb
310
- - spec/cnpj_cpf/cpf_spec.rb
311
- - spec/cnpj_validator_spec.rb
312
- - spec/cpf_validator_spec.rb
313
- - spec/gtin/gtin_spec.rb
314
- - spec/gtin_validator_spec.rb
315
- - spec/ie/ac_spec.rb
316
- - spec/ie/al_spec.rb
317
- - spec/ie/am_spec.rb
318
- - spec/ie/ap_spec.rb
319
- - spec/ie/ba_spec.rb
320
- - spec/ie/ce_spec.rb
321
- - spec/ie/df_spec.rb
322
- - spec/ie/es_spec.rb
323
- - spec/ie/factory_spec.rb
324
- - spec/ie/go_spec.rb
325
- - spec/ie/ma_spec.rb
326
- - spec/ie/mg_spec.rb
327
- - spec/ie/ms_spec.rb
328
- - spec/ie/mt_spec.rb
329
- - spec/ie/pa_spec.rb
330
- - spec/ie/pb_spec.rb
331
- - spec/ie/pe_spec.rb
332
- - spec/ie/pi_spec.rb
333
- - spec/ie/pr_spec.rb
334
- - spec/ie/rj_spec.rb
335
- - spec/ie/rn_spec.rb
336
- - spec/ie/ro_spec.rb
337
- - spec/ie/rr_spec.rb
338
- - spec/ie/rs_spec.rb
339
- - spec/ie/sc_spec.rb
340
- - spec/ie/se_spec.rb
341
- - spec/ie/shared_examples_for_pattern1.rb
342
- - spec/ie/shared_examples_for_to_remove_all_masks.rb
343
- - spec/ie/sp_spec.rb
344
- - spec/ie/to_spec.rb
345
- - spec/ie_validator_spec.rb
324
+ - spec/br_documents/cnpj_cpf/cnpj_spec.rb
325
+ - spec/br_documents/cnpj_cpf/cpf_spec.rb
326
+ - spec/br_documents/cnpj_validator_spec.rb
327
+ - spec/br_documents/cpf_validator_spec.rb
328
+ - spec/br_documents/gtin_spec.rb
329
+ - spec/br_documents/gtin_validator_spec.rb
330
+ - spec/br_documents/ie/ac_spec.rb
331
+ - spec/br_documents/ie/al_spec.rb
332
+ - spec/br_documents/ie/am_spec.rb
333
+ - spec/br_documents/ie/ap_spec.rb
334
+ - spec/br_documents/ie/ba_spec.rb
335
+ - spec/br_documents/ie/ce_spec.rb
336
+ - spec/br_documents/ie/df_spec.rb
337
+ - spec/br_documents/ie/es_spec.rb
338
+ - spec/br_documents/ie/factory_spec.rb
339
+ - spec/br_documents/ie/go_spec.rb
340
+ - spec/br_documents/ie/ma_spec.rb
341
+ - spec/br_documents/ie/mg_spec.rb
342
+ - spec/br_documents/ie/ms_spec.rb
343
+ - spec/br_documents/ie/mt_spec.rb
344
+ - spec/br_documents/ie/pa_spec.rb
345
+ - spec/br_documents/ie/pb_spec.rb
346
+ - spec/br_documents/ie/pe_spec.rb
347
+ - spec/br_documents/ie/pi_spec.rb
348
+ - spec/br_documents/ie/pr_spec.rb
349
+ - spec/br_documents/ie/rj_spec.rb
350
+ - spec/br_documents/ie/rn_spec.rb
351
+ - spec/br_documents/ie/ro_spec.rb
352
+ - spec/br_documents/ie/rr_spec.rb
353
+ - spec/br_documents/ie/rs_spec.rb
354
+ - spec/br_documents/ie/sc_spec.rb
355
+ - spec/br_documents/ie/se_spec.rb
356
+ - spec/br_documents/ie/shared_examples_for_pattern1.rb
357
+ - spec/br_documents/ie/shared_examples_for_to_remove_all_masks.rb
358
+ - spec/br_documents/ie/sp_spec.rb
359
+ - spec/br_documents/ie/to_spec.rb
360
+ - spec/br_documents/ie_validator_spec.rb
361
+ - spec/br_documents/suframa_spec.rb
362
+ - spec/br_documents/suframa_validator_spec.rb
346
363
  - spec/spec_helper.rb
347
- - spec/suframa/suframa_spec.rb
348
- - spec/suframa_validator_spec.rb
349
364
  - spec/support/utilities.rb
@@ -1,60 +0,0 @@
1
- require_relative '../commons/mod11'
2
-
3
- # rubocop:disable Style/ClassAndModuleChildren
4
- class BrDocuments::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
- valid_activity_sector? &&
20
- valid_administrative_unit?
21
- end
22
-
23
- private
24
-
25
- def valid_pattern?
26
- /^(\d{2}\.\d{4}\.\d{3})$|^(\d{9})$/.match(@number).present?
27
- end
28
-
29
- def sequence_of_equal_numbers?
30
- number_without_mask.split('').uniq.length == 1
31
- end
32
-
33
- def number_without_mask
34
- @number_without_mask ||= @number.gsub('.', '')
35
- end
36
-
37
- def valid_check_digit?
38
- weights = [9, 8, 7, 6, 5, 4, 3, 2]
39
-
40
- check_digit = generate_check_digit(number_without_mask, weights)
41
- number_without_mask[8] == check_digit.to_s
42
- end
43
-
44
- def valid_activity_sector?
45
- activity_sector = number_without_mask[0] + number_without_mask[1]
46
-
47
- ['01', '02', '10', '11', '20', '60'].include?(activity_sector)
48
- end
49
-
50
- def valid_administrative_unit?
51
- administrative_unit = number_without_mask[6] + number_without_mask[7]
52
-
53
- ['01', '10', '30'].include?(administrative_unit)
54
- end
55
-
56
- def format_number
57
- @number.sub(/(\d{2})(\d{4})(\d{3})/, '\\1.\\2.\\3')
58
- end
59
- end
60
- # rubocop:enable Style/ClassAndModuleChildren
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CnpjValidator do
4
- before(:each) do
5
- @validator = CnpjValidator.new(attributes: 'cnpj')
6
- @mock = double('model')
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 { @validator }
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).to_not be_empty
34
- end
35
- end
36
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CpfValidator do
4
- before(:each) do
5
- @validator = CpfValidator.new(attributes: 'cpf')
6
- @mock = double('model')
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 { @validator }
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).to_not be_empty
34
- end
35
- end
36
- end