br_documents 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 70d69d78462e3ab61040e25f8540bf7775a80f0f
4
- data.tar.gz: da45afd43f7ab8283f2175a6d7202d1bbe34ae5e
2
+ SHA256:
3
+ metadata.gz: 25cf99032b0bea6b2a016595a560e0a7ea5777154f74d9259009b50323473a61
4
+ data.tar.gz: f19aa466afa9077bfbe14184d8311bc7db6486d36d1f73ed855c2b00218a062a
5
5
  SHA512:
6
- metadata.gz: 53f7b3ca1a384b09aa3a4ece17793fc5707e9443015b0916822c808278d1f1c18eb2e0dff24346b24a1b68815b85088fbe9478f38f92330bfeda1f58f1afd5ae
7
- data.tar.gz: f7bc5af898cd89ceaa00ac06261fa91559a9187d72bce79fc4121eba7cc501c69710774bac7b6c1eb032e542dde2351905a63ce306e4445784537ae5fbebfd5c
6
+ metadata.gz: 3f37a4a5244a984e8ed4bf93077e43dd92caec88ea2e9ee7243b8819c6c520050658d7fdcc3164518a7b324f0e777b78346cbe3e024bc019515e258d251d68a3
7
+ data.tar.gz: 67cf2292f3ca90a52ff6790155c6a32382f7c54475b7d572c3fd491f63a756676c88c333f83bd6f961cc97a6fc321df5139c2c7f10881a0af3239bafac313a5c
@@ -1,30 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_documents (0.1.2)
4
+ br_documents (0.1.3)
5
5
  activemodel (>= 4.0.0)
6
6
  i18n (>= 0.6.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.2.3)
12
- activesupport (= 5.2.3)
13
- activesupport (5.2.3)
11
+ activemodel (6.0.0)
12
+ activesupport (= 6.0.0)
13
+ activesupport (6.0.0)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 0.7, < 2)
16
16
  minitest (~> 5.1)
17
17
  tzinfo (~> 1.1)
18
+ zeitwerk (~> 2.1, >= 2.1.8)
18
19
  byebug (10.0.2)
19
20
  codeclimate-test-reporter (1.0.7)
20
21
  simplecov
21
22
  concurrent-ruby (1.1.5)
22
23
  diff-lcs (1.3)
23
24
  docile (1.1.5)
24
- i18n (1.6.0)
25
+ i18n (1.7.0)
25
26
  concurrent-ruby (~> 1.0)
26
27
  json (2.0.3)
27
- minitest (5.11.3)
28
+ minitest (5.13.0)
28
29
  rake (12.0.0)
29
30
  rspec (3.5.0)
30
31
  rspec-core (~> 3.5.0)
@@ -45,8 +46,9 @@ GEM
45
46
  simplecov-html (~> 0.10.0)
46
47
  simplecov-html (0.10.0)
47
48
  thread_safe (0.3.6)
48
- tzinfo (1.2.5)
49
+ tzinfo (1.2.6)
49
50
  thread_safe (~> 0.1)
51
+ zeitwerk (2.2.2)
50
52
 
51
53
  PLATFORMS
52
54
  ruby
@@ -61,4 +63,4 @@ DEPENDENCIES
61
63
  simplecov (>= 0.9.0)
62
64
 
63
65
  BUNDLED WITH
64
- 1.16.3
66
+ 1.17.2
@@ -1,10 +1,9 @@
1
1
  class IeValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
- if ie_present?(value)
4
- attribute_uf_was_configured_at_validator?(record) and
5
- can_read_uf_at_record?(options, record) and
3
+ ie_present?(value) &&
4
+ attribute_uf_was_configured_at_validator?(record) &&
5
+ can_read_uf_at_record?(options, record) &&
6
6
  ie_valid?(record, attribute, value)
7
- end
8
7
  end
9
8
 
10
9
  private
@@ -15,18 +14,20 @@ class IeValidator < ActiveModel::EachValidator
15
14
  def attribute_uf_was_configured_at_validator?(record)
16
15
  record.errors.add(:base,
17
16
  I18n.t("validator.ie.uf.no_configured")) unless options[:uf].present?
18
- record.errors.messages.empty?
17
+
18
+ options[:uf].present?
19
19
  end
20
20
 
21
21
  def can_read_uf_at_record?(options, record)
22
22
  begin
23
- read_uf(record)
23
+ uf = read_uf(record)
24
24
  rescue NoMethodError
25
25
  record.errors.add(:base, I18n.t("validator.ie.uf.no_present",
26
26
  uf: options[:uf])
27
27
  )
28
28
  end
29
- record.errors.messages.empty?
29
+
30
+ uf.present?
30
31
  end
31
32
 
32
33
  def ie_valid?(record, attribute, value)
@@ -42,7 +43,7 @@ class IeValidator < ActiveModel::EachValidator
42
43
  uf = read_uf(record)
43
44
  ie_number = BrDocuments::IE::Factory.create(uf, value)
44
45
  ie_number.valid?
45
- end
46
+ end
46
47
 
47
48
  def read_uf(record)
48
49
  attribute = record
@@ -1,3 +1,3 @@
1
1
  module BrDocuments
2
- VERSION = "0.1.2"
2
+ VERSION = '0.1.3'
3
3
  end
@@ -1,73 +1,83 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe IeValidator do
4
- let(:record) { double("model") }
3
+ RSpec.describe IeValidator do
4
+ let(:record) { double('model') }
5
5
 
6
6
  before do
7
- allow(record).to receive(:uf) {"SC"}
8
- allow(record).to receive(:errors).and_return([])
7
+ allow(record).to receive(:uf) {'SC'}
8
+ allow(record).to receive(:errors).and_return({})
9
9
  allow(record.errors).to receive(:messages).and_return({})
10
10
  allow(record.errors).to receive(:add) do | attribute, error |
11
- record.errors.messages[attribute] = [error]
11
+ record.errors[attribute] ||= []
12
+ record.errors[attribute] << error
13
+ record.errors.messages[attribute] = record.errors[attribute]
12
14
  end
13
15
  end
14
16
 
15
- subject { IeValidator.new(attributes: "ie", uf: "uf") }
17
+ subject { IeValidator.new(attributes: 'ie', uf: 'uf') }
16
18
 
17
19
  context "when IE's number is valid" do
18
- before { subject.validate_each(record, "ie", "253667852") }
20
+ before { subject.validate_each(record, 'ie', '253667852') }
19
21
 
20
- it "doesn't add errors in model" do
22
+ it 'does not add errors in model' do
21
23
  expect(record.errors.messages).to be_empty
22
24
  end
23
25
  end
24
26
 
25
- context "when IE is blank" do
26
- before { subject.validate_each(record, "ie", "") }
27
+ context 'when IE is blank' do
28
+ before { subject.validate_each(record, 'ie', '') }
27
29
 
28
- it "doesn't add errors in model" do
30
+ it 'does not add errors in model' do
29
31
  expect(record.errors.messages).to be_empty
30
32
  end
31
33
  end
32
34
 
33
- context "when IE is invalid" do
34
- before { subject.validate_each(record, "ie", "253667853") }
35
+ context 'when IE is invalid' do
36
+ it 'adds :invalid error in the model' do
37
+ subject.validate_each(record, 'ie', '253667853')
35
38
 
36
- it "adds errors in model" do
37
- expect(record.errors.messages).to_not be_empty
39
+ expect(record.errors.messages['ie']).to include(:invalid)
40
+ end
41
+
42
+ it 'does not override the previous message' do
43
+ record.errors.add('ie', 'another error message')
44
+ subject.validate_each(record, 'ie', '253667853')
45
+
46
+ expect(record.errors.messages['ie']).to include('another error message')
47
+ expect(record.errors.messages['ie']).to include(:invalid)
38
48
  end
39
49
  end
40
50
 
41
- context "when UF is invalid" do
51
+ context 'when UF is invalid' do
42
52
  before do
43
- allow(record).to receive(:uf){""}
44
- subject.validate_each(record, "ie", "253667852")
53
+ allow(record).to receive(:uf) {'XX'}
54
+ subject.validate_each(record, 'ie', '253667852')
45
55
  end
46
56
 
47
- it "adds error in model" do
48
- expect(record.errors.messages["ie"]).to eql [t("validator.ie.uf.invalid")]
57
+ it 'adds error in model' do
58
+ expect(record.errors.messages['ie']).to include t('validator.ie.uf.invalid')
49
59
  end
50
60
  end
51
61
 
52
- context "when it can't find attribute uf in model" do
62
+ context 'when cannot be found attribute uf in model' do
53
63
  before do
54
64
  allow(record).to receive(:uf).and_raise(NoMethodError)
55
- subject.validate_each(record, "ie", "253667852")
65
+ subject.validate_each(record, 'ie', '253667852')
56
66
  end
57
67
 
58
- it "adds error in model" do
68
+ it 'adds error in model' do
59
69
  expect(record.errors.messages[:base]).to eql [
60
- t("validator.ie.uf.no_present", uf: "uf")]
70
+ t('validator.ie.uf.no_present', uf: 'uf')]
61
71
  end
62
72
  end
63
73
 
64
- context "when attribute uf is not defined" do
65
- subject { IeValidator.new(attributes: "ie") }
66
- before { subject.validate_each(record, "ie", "253667852") }
74
+ context 'when attribute uf is not defined' do
75
+ subject { IeValidator.new(attributes: 'ie') }
76
+ before { subject.validate_each(record, 'ie', '253667852') }
67
77
 
68
- it "adds error in model" do
78
+ it 'adds error in model' do
69
79
  expect(record.errors.messages[:base]).to eql [
70
- t("validator.ie.uf.no_configured")]
80
+ t('validator.ie.uf.no_configured')]
71
81
  end
72
82
  end
73
83
  end
@@ -15,5 +15,8 @@ RSpec.configure do |config|
15
15
  c.syntax = :expect
16
16
  end
17
17
 
18
+ config.filter_run focus: true
19
+ config.run_all_when_everything_filtered = true
20
+
18
21
  config.order = "random"
19
22
  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.2
4
+ version: 0.1.3
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: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2020-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -239,8 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0'
241
241
  requirements: []
242
- rubyforge_project:
243
- rubygems_version: 2.6.14.1
242
+ rubygems_version: 3.0.3
244
243
  signing_key:
245
244
  specification_version: 4
246
245
  summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with