valicuit 0.2.2
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 +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/README.md +77 -0
- data/Rakefile +9 -0
- data/lib/active_model/validations/cuit_validator.rb +119 -0
- data/lib/valicuit/engine.rb +8 -0
- data/lib/valicuit/version.rb +3 -0
- data/lib/valicuit.rb +6 -0
- data/locales/es.yml +7 -0
- data/locales/test.yml +7 -0
- data/spec/cuit_validator_spec.rb +216 -0
- data/spec/spec_helper.rb +23 -0
- data/valicuit.gemspec +25 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 152af78be77b708c5f1250b822ba6e51c3f3a0d9
|
4
|
+
data.tar.gz: eb3e1a106becb4ee13dacca3d027a3428027fb37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59f2ecf49e180404dae2d6e239d55dee15c2423f70ab8b311a9c78aa5a9857a64bdacce91c223273e22839978dc95cdb8a8e9bbf51241d9c277e39ab0a804088
|
7
|
+
data.tar.gz: d30e08ff153bf3f0b6dd5c1526a060288e8767cff022bdfc7429f1e62157a817f5083ff895843cf3663a603cad25e61daf2096c239fee1a45a4cc5768ed6316f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# ValiCUIT
|
2
|
+
|
3
|
+
[](https://travis-ci.org/lndl/valicuit) [](https://codeclimate.com/github/lndl/valicuit) [](https://codeclimate.com/github/lndl/valicuit/coverage) [](https://codeclimate.com/github/lndl/valicuit)
|
4
|
+
|
5
|
+
Un validador de CUIT/CUIL para ActiveModel & Rails.
|
6
|
+
|
7
|
+
## Instalación
|
8
|
+
|
9
|
+
Lo de siempre... agregar esta línea en el Gemfile del proyecto:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'valicuit', github: 'lndl/valicuit'
|
13
|
+
```
|
14
|
+
|
15
|
+
Y, finalmente, ejecutar **bundle install**
|
16
|
+
|
17
|
+
## Uso
|
18
|
+
|
19
|
+
Es un validador más. Dentro de cualquier modelo se especifica que un atributo X se valide con cuit (o cuil, es indistinto), de esta forma:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class Persona < ActiveRecord::Base
|
23
|
+
validates :cuit, cuit: true # Notar que también podría usarse cuil: true
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Con esto, se dispone de validación por formato (por defecto 11 dígitos, sin separador) y por dígito verificador (con el algoritomo módulo 11)
|
28
|
+
|
29
|
+
## Opciones adicionales
|
30
|
+
|
31
|
+
Se puede agregar la opción de incluir y validar un separador para los grupos que componen el CUIT/CUIL, de esta forma:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Persona < ActiveRecord::Base
|
35
|
+
validates :cuit, cuit: { separator: '-' }
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Adicionalmente se puede validar que la parte del género y del DNI del CUIT se corresponda con dichos campos propios en el mismo modelo.
|
40
|
+
|
41
|
+
Por ejemplo, para el caso del DNI podría ser:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class Persona < ActiveRecord::Base
|
45
|
+
validates :cuit, cuit: { dni_compatible: :documento }
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Y eso verificaría que la parte central del CUIT (que corresponde al DNI) sea igual al valor del campo 'documento' (qué, en dicho modelo, representaría el DNI de la persona)
|
50
|
+
|
51
|
+
Análogamente se cumple lo mismo para el género:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class Persona < ActiveRecord::Base
|
55
|
+
validates :cuit, cuit: { gender_compatible: { field: :genero, male: 'M', female: 'F' } }
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
Y se especifica el campo que representa el género en el modelo, más los valores para validar tales géneros.
|
60
|
+
|
61
|
+
|
62
|
+
## Tests
|
63
|
+
|
64
|
+
Se corren con RSpec.
|
65
|
+
|
66
|
+
## Agradecimientos
|
67
|
+
|
68
|
+
- https://github.com/maxigarciaf/cuit_validator
|
69
|
+
- https://github.com/codegram/date_validator
|
70
|
+
|
71
|
+
## Contribuciones
|
72
|
+
|
73
|
+
1. Clonar el proyecto.
|
74
|
+
2. Crear un *feature branch* (`git checkout -b mi-nuevo-feature`).
|
75
|
+
3. *Commitear* los cambios realizados (`git commit -am 'Agrego algo nuevo o mejoro algo'`).
|
76
|
+
4. *Pushear* el *feature* (`git push origin mi-nuevo-feature`).
|
77
|
+
5. Crear un *Pull Request*.
|
data/Rakefile
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'active_model/validations'
|
2
|
+
|
3
|
+
# ActiveModel module.
|
4
|
+
module ActiveModel
|
5
|
+
|
6
|
+
# ActiveModel::Validations module. Contains all the default validators.
|
7
|
+
module Validations
|
8
|
+
|
9
|
+
# Here start the implementation of CUIT/CUIL validator
|
10
|
+
class CuitValidator < ActiveModel::EachValidator
|
11
|
+
CHECKS = [ :separator, :dni_compatible, :gender_compatible ].freeze
|
12
|
+
|
13
|
+
# Hook that checks the options validity
|
14
|
+
# for this validator
|
15
|
+
def check_validity!
|
16
|
+
invalid_options = options.keys - CHECKS
|
17
|
+
raise ArgumentError, "#{invalid_options} are invalid CUIT/CUIL options. You can use only these: #{CHECKS.join(', ')}" unless invalid_options.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_each(record, attr_name, value)
|
21
|
+
return if detect_any_failure_in :length, :digits, :dni_compatibility, :gender_compatibility, :v_digit,
|
22
|
+
data: [ record, attr_name, value ]
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
# Sugar, turutu-tu-tuut-tu, ohhh, honey, honey
|
28
|
+
def detect_any_failure_in(*properties, data: [])
|
29
|
+
properties.detect { |prop| send "check_#{prop}_failure", *data }
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_length_failure(record, attr_name, value)
|
33
|
+
type, dni, v_digit = separate_cuit_groups value
|
34
|
+
unless type.length == 2 && dni.length == 8 && v_digit.length == 1
|
35
|
+
record.errors.add(attr_name, :cuit_invalid_format)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_digits_failure(record, attr_name, value)
|
40
|
+
type, dni, v_digit = separate_cuit_groups value
|
41
|
+
unless (type + dni + v_digit) =~ /\A\d+\Z/
|
42
|
+
record.errors.add(attr_name, :cuit_invalid_format)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def check_dni_compatibility_failure(record, attr_name, value)
|
47
|
+
_, dni, _ = separate_cuit_groups value
|
48
|
+
unless !options[:dni_compatible].present? || record.public_send(options[:dni_compatible]) == dni
|
49
|
+
record.errors.add(attr_name, :cuit_dni_incompatible)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_gender_compatibility_failure(record, attr_name, value)
|
54
|
+
type, _, _ = separate_cuit_groups value
|
55
|
+
|
56
|
+
if options[:gender_compatible].present?
|
57
|
+
unless gender_validation_passing?(record, type)
|
58
|
+
record.errors.add(attr_name, :cuit_gender_incompatible)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_v_digit_failure(record, attr_name, value)
|
64
|
+
type, dni, v_digit = separate_cuit_groups value
|
65
|
+
unless v_digit.to_i == compute_v_digit(type, dni)
|
66
|
+
record.errors.add(attr_name, :cuit_invalid_v_digit)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# AFIP dependent logic. Trust or die
|
71
|
+
def compute_v_digit(type, dni)
|
72
|
+
sequence = [2,3,4,5,6,7,2,3,4,5].reverse
|
73
|
+
precomputed_v_digit = 11 - (type + dni)
|
74
|
+
.chars
|
75
|
+
.each_with_index
|
76
|
+
.inject(0) do |acc, (n, i)|
|
77
|
+
acc + n.to_i * sequence[i]
|
78
|
+
end % 11
|
79
|
+
|
80
|
+
case precomputed_v_digit
|
81
|
+
when 11
|
82
|
+
0
|
83
|
+
when 10
|
84
|
+
9
|
85
|
+
else
|
86
|
+
precomputed_v_digit
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def separate_cuit_groups(cuit)
|
91
|
+
separator = options[:separator]
|
92
|
+
if separator
|
93
|
+
cuit.split(separator).first 3
|
94
|
+
else
|
95
|
+
# Take standard CUIT/CUIL layout (2 digit, 8 digit, 1 digit)
|
96
|
+
[ cuit[0..1], cuit[2..9], cuit[10] ]
|
97
|
+
end.map(&:to_s)
|
98
|
+
end
|
99
|
+
|
100
|
+
def gender_validation_passing?(record, type)
|
101
|
+
raise ArgumentError, 'Valicuit: gender field specification must be present!' unless options[:gender_compatible][:field].present?
|
102
|
+
raise ArgumentError, 'Valicuit: declaration of male value missing!' unless options[:gender_compatible][:male].present?
|
103
|
+
raise ArgumentError, 'Valicuit: declaration of female value missing!' unless options[:gender_compatible][:female].present?
|
104
|
+
case type
|
105
|
+
when '20'
|
106
|
+
options[:gender_compatible][:male]
|
107
|
+
when '27'
|
108
|
+
options[:gender_compatible][:female]
|
109
|
+
else
|
110
|
+
# Machist!
|
111
|
+
options[:gender_compatible][:male]
|
112
|
+
end == record.public_send(options[:gender_compatible][:field])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# CUIT/CUIL is the same for the purposes of validation
|
117
|
+
CuilValidator = CuitValidator
|
118
|
+
end
|
119
|
+
end
|
data/lib/valicuit.rb
ADDED
data/locales/es.yml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
es:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
cuit_invalid_format: no posee el formato correcto
|
5
|
+
cuit_dni_incompatible: no es compatible con DNI de la persona
|
6
|
+
cuit_gender_incompatible: no es compatible con el género de la persona
|
7
|
+
cuit_invalid_v_digit: tiene colocado incorrectamente su dígito verificador
|
data/locales/test.yml
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActiveModel::Validations::CuitValidator do
|
4
|
+
before do
|
5
|
+
TestModel.reset_callbacks(:validate)
|
6
|
+
end
|
7
|
+
|
8
|
+
context '#check_validity!' do
|
9
|
+
context 'when pass cuil option as validator' do
|
10
|
+
it 'returns the validation options passed (therefore, all is well defined)' do
|
11
|
+
expect(TestModel.validates :cuit, cuil: true).to eq(cuil: true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
context 'when invalid options are passed' do
|
15
|
+
it 'throws an ArgumentError' do
|
16
|
+
expect do
|
17
|
+
TestModel.validates :cuit, cuit: { separator: '/', wrong_param: true }
|
18
|
+
end.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context 'when valid options are passed' do
|
22
|
+
it 'returns the validation options passed (therefore, all is well defined)' do
|
23
|
+
expect(TestModel.validates :cuit, cuit: { separator: '/' }).to eq(cuit: { separator: '/' })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context 'when no options are passed (only true)' do
|
27
|
+
it 'returns the validation options passed (therefore, all is well defined)' do
|
28
|
+
expect(TestModel.validates :cuit, cuit: true).to eq(cuit: true)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context '#separate_cuit_groups' do
|
34
|
+
context 'without provide separator' do
|
35
|
+
let(:validator) { ActiveModel::Validations::CuitValidator.new attributes: { _: :_ } }
|
36
|
+
it 'must return an 3-elements Array (Happy)' do
|
37
|
+
expect(validator.send(:separate_cuit_groups, '30615459190')).to be_an_instance_of(Array)
|
38
|
+
expect(validator.send(:separate_cuit_groups, '30615459190').size).to eq(3)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'must return an 3-elements Array (Sad)' do
|
42
|
+
expect(validator.send(:separate_cuit_groups, '306')).to be_an_instance_of(Array)
|
43
|
+
expect(validator.send(:separate_cuit_groups, '306').size).to eq(3)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'each element must be an instance of String (Happy)' do
|
47
|
+
validator.send(:separate_cuit_groups, '30615459190').each do |group|
|
48
|
+
expect(group).to be_an_instance_of String
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'each element must be an instance of String (Sad)' do
|
53
|
+
validator.send(:separate_cuit_groups, '306').each do |group|
|
54
|
+
expect(group).to be_an_instance_of String
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context 'providing separator' do
|
59
|
+
let(:validator) do
|
60
|
+
ActiveModel::Validations::CuitValidator.new attributes: { _: :_ },
|
61
|
+
separator: '-'
|
62
|
+
end
|
63
|
+
it 'must return an 3-elements Array (Happy)' do
|
64
|
+
expect(validator.send(:separate_cuit_groups, '30-61545919-0')).to be_an_instance_of(Array)
|
65
|
+
expect(validator.send(:separate_cuit_groups, '30-61545919-0').size).to eq(3)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'must return an 3-elements Array (Sad)' do
|
69
|
+
expect(validator.send(:separate_cuit_groups, '30- - - --')).to be_an_instance_of(Array)
|
70
|
+
expect(validator.send(:separate_cuit_groups, '30- - - --').size).to eq(3)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'each element must be an instance of String (Happy)' do
|
74
|
+
validator.send(:separate_cuit_groups, '30-61545919-0').each do |group|
|
75
|
+
expect(group).to be_an_instance_of String
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'each element must be an instance of String (Sad)' do
|
80
|
+
validator.send(:separate_cuit_groups, '306---').each do |group|
|
81
|
+
expect(group).to be_an_instance_of String
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context '#valid' do
|
88
|
+
context 'with standard options' do
|
89
|
+
before do
|
90
|
+
TestModel.validates :cuit, cuit: true
|
91
|
+
end
|
92
|
+
it 'must return true when CUIT/CUIL is valid' do
|
93
|
+
expect(TestModel.new(cuit: '30615459190')).to be_valid
|
94
|
+
expect(TestModel.new(cuit: '20118748698')).to be_valid
|
95
|
+
expect(TestModel.new(cuit: '20120112989')).to be_valid
|
96
|
+
expect(TestModel.new(cuit: '27049852032')).to be_valid
|
97
|
+
expect(TestModel.new(cuit: '23218381669')).to be_valid
|
98
|
+
expect(TestModel.new(cuit: '30709316547')).to be_valid
|
99
|
+
expect(TestModel.new(cuit: '20000000019')).to be_valid
|
100
|
+
end
|
101
|
+
context 'when CUIT/CUIL has strange characters' do
|
102
|
+
it 'must return false' do
|
103
|
+
expect(TestModel.new(cuit: '2061s459190')).to be_invalid
|
104
|
+
end
|
105
|
+
it 'must leave a specific message over :cuit in #errors array' do
|
106
|
+
record = TestModel.new(cuit: '2061s459190')
|
107
|
+
record.valid?
|
108
|
+
expect(record.errors[:cuit]).to match_array(['invalid_format'])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
context 'when CUIT/CUIL has not the correct length' do
|
112
|
+
it 'must return false' do
|
113
|
+
expect(TestModel.new(cuit: '301110')).to be_invalid
|
114
|
+
end
|
115
|
+
it 'must leave a specific message over :cuit in #errors array' do
|
116
|
+
record = TestModel.new(cuit: '301110')
|
117
|
+
record.valid?
|
118
|
+
expect(record.errors[:cuit]).to match_array(['invalid_format'])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
context 'when CUIT/CUIL is logically invalid, because verification digit is incorrect' do
|
122
|
+
it 'must return false' do
|
123
|
+
expect(TestModel.new(cuit: '20111111110')).to be_invalid
|
124
|
+
end
|
125
|
+
it 'must leave a specific message over :cuit in #errors array' do
|
126
|
+
record = TestModel.new(cuit: '20111111110')
|
127
|
+
record.valid?
|
128
|
+
expect(record.errors[:cuit]).to match_array(['invalid_v_digit'])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
context 'with separator option' do
|
133
|
+
before do
|
134
|
+
TestModel.validates :cuit, cuit: { separator: '-' }
|
135
|
+
end
|
136
|
+
it 'must return true when CUIT/CUIL is valid' do
|
137
|
+
expect(TestModel.new(cuit: '30-61545919-0')).to be_valid
|
138
|
+
expect(TestModel.new(cuit: '20-11874869-8')).to be_valid
|
139
|
+
expect(TestModel.new(cuit: '20-12011298-9')).to be_valid
|
140
|
+
expect(TestModel.new(cuit: '27-04985203-2')).to be_valid
|
141
|
+
expect(TestModel.new(cuit: '23-21838166-9')).to be_valid
|
142
|
+
expect(TestModel.new(cuit: '30-70931654-7')).to be_valid
|
143
|
+
expect(TestModel.new(cuit: '20-00000001-9')).to be_valid
|
144
|
+
end
|
145
|
+
context 'when CUIT/CUIL has not the correct length' do
|
146
|
+
it 'must return false' do
|
147
|
+
expect(TestModel.new(cuit: '30-1110222222222-4')).to be_invalid
|
148
|
+
end
|
149
|
+
it 'must leave a specific message over :cuit in #errors array' do
|
150
|
+
record = TestModel.new(cuit: '30-1110222222222-4')
|
151
|
+
record.valid?
|
152
|
+
expect(record.errors[:cuit]).to match_array(['invalid_format'])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
context 'when CUIT/CUIL has misplaced the separator' do
|
156
|
+
it 'must return false' do
|
157
|
+
expect(TestModel.new(cuit: '30-123-11114')).to be_invalid
|
158
|
+
end
|
159
|
+
it 'must leave a specific message over :cuit in #errors array' do
|
160
|
+
record = TestModel.new(cuit: '30-123-11114')
|
161
|
+
record.valid?
|
162
|
+
expect(record.errors[:cuit]).to match_array(['invalid_format'])
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
context 'with dni compatible option' do
|
167
|
+
before do
|
168
|
+
TestModel.validates :cuit, cuit: { dni_compatible: :dni }
|
169
|
+
end
|
170
|
+
it 'must return true when CUIT/CUIL is valid and central part of CUIT is equal to DNI' do
|
171
|
+
expect(TestModel.new(cuit: '30615459190', dni: '61545919')).to be_valid
|
172
|
+
expect(TestModel.new(cuit: '20118748698', dni: '11874869')).to be_valid
|
173
|
+
expect(TestModel.new(cuit: '20120112989', dni: '12011298')).to be_valid
|
174
|
+
expect(TestModel.new(cuit: '27049852032', dni: '04985203')).to be_valid
|
175
|
+
expect(TestModel.new(cuit: '23218381669', dni: '21838166')).to be_valid
|
176
|
+
expect(TestModel.new(cuit: '30709316547', dni: '70931654')).to be_valid
|
177
|
+
expect(TestModel.new(cuit: '20000000019', dni: '00000001')).to be_valid
|
178
|
+
end
|
179
|
+
it 'must return false when CUIT/CUIL is valid but central part of CUIT is not equal to DNI' do
|
180
|
+
expect(TestModel.new(cuit: '30615459190', dni: '62545919')).to be_invalid
|
181
|
+
expect(TestModel.new(cuit: '20118748698', dni: '11875869')).to be_invalid
|
182
|
+
expect(TestModel.new(cuit: '20120112989', dni: '12011278')).to be_invalid
|
183
|
+
expect(TestModel.new(cuit: '27049852032', dni: '04945203')).to be_invalid
|
184
|
+
expect(TestModel.new(cuit: '23218381669', dni: '21838196')).to be_invalid
|
185
|
+
expect(TestModel.new(cuit: '30709316547', dni: '70901654')).to be_invalid
|
186
|
+
expect(TestModel.new(cuit: '20000000019', dni: '03000001')).to be_invalid
|
187
|
+
end
|
188
|
+
it 'must leave a specific message over :cuit in #errors array' do
|
189
|
+
record = TestModel.new(cuit: '20120112989', dni: '12011278')
|
190
|
+
record.valid?
|
191
|
+
expect(record.errors[:cuit]).to match_array(['cuit_dni_incompatible'])
|
192
|
+
end
|
193
|
+
end
|
194
|
+
context 'with gender compatible option' do
|
195
|
+
before do
|
196
|
+
TestModel.validates :cuit, cuit: { gender_compatible: { field: :gender, male: 'M', female: 'F' } }
|
197
|
+
end
|
198
|
+
it 'must return true when CUIT/CUIL is valid and gender part is compatible with gender model' do
|
199
|
+
expect(TestModel.new(cuit: '20120112989', gender: 'M')).to be_valid
|
200
|
+
expect(TestModel.new(cuit: '27049852032', gender: 'F')).to be_valid
|
201
|
+
end
|
202
|
+
it 'must return true with cuit type different of 20/27 as "Male"' do
|
203
|
+
expect(TestModel.new(cuit: '30709316547', gender: 'M')).to be_valid
|
204
|
+
end
|
205
|
+
it 'must return false when CUIT/CUIL is valid but gender part is incompatible with gender model' do
|
206
|
+
expect(TestModel.new(cuit: '20120112989', gender: 'F')).to be_invalid
|
207
|
+
expect(TestModel.new(cuit: '27049852032', gender: 'M')).to be_invalid
|
208
|
+
end
|
209
|
+
it 'must leave a specific message over :cuit in #errors array' do
|
210
|
+
record = TestModel.new(cuit: '20120112989', gender: 'F')
|
211
|
+
record.valid?
|
212
|
+
expect(record.errors[:cuit]).to match_array(['cuit_gender_incompatible'])
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'active_model'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
|
8
|
+
require 'valicuit'
|
9
|
+
|
10
|
+
I18n.load_path += Dir[File.expand_path(File.join(File.dirname(__FILE__), '../locales', '*.yml')).to_s]
|
11
|
+
I18n.default_locale = :test
|
12
|
+
|
13
|
+
class TestModel
|
14
|
+
include ActiveModel::Validations
|
15
|
+
|
16
|
+
attr_accessor :cuit, :dni, :gender
|
17
|
+
|
18
|
+
def initialize(attributes = {})
|
19
|
+
self.cuit = attributes[:cuit]
|
20
|
+
self.dni = attributes[:dni]
|
21
|
+
self.gender = attributes[:gender]
|
22
|
+
end
|
23
|
+
end
|
data/valicuit.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'valicuit/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'valicuit'
|
7
|
+
s.version = Valicuit::VERSION
|
8
|
+
s.authors = ['Lautaro Nahuel De León']
|
9
|
+
s.email = ['laudleon@gmail.com', 'ldeleon@cespi.unlp.edu.ar']
|
10
|
+
s.homepage = 'http://github.com/lndl/valicuit'
|
11
|
+
s.summary = %q{A CUIT/CUIL validator for ActiveModel & Rails}
|
12
|
+
s.description = %q{A CUIT/CUIL validator for ActiveModel & Rails with multiple customizable options}
|
13
|
+
s.licenses = ['MIT']
|
14
|
+
|
15
|
+
s.add_runtime_dependency 'activemodel', '~> 4'
|
16
|
+
|
17
|
+
s.add_development_dependency 'rake', '~> 11.3'
|
18
|
+
s.add_development_dependency 'rspec', '~> 3.5'
|
19
|
+
s.add_development_dependency 'simplecov', '~> 0.12'
|
20
|
+
s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valicuit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lautaro Nahuel De León
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
description: A CUIT/CUIL validator for ActiveModel & Rails with multiple customizable
|
84
|
+
options
|
85
|
+
email:
|
86
|
+
- laudleon@gmail.com
|
87
|
+
- ldeleon@cespi.unlp.edu.ar
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/active_model/validations/cuit_validator.rb
|
99
|
+
- lib/valicuit.rb
|
100
|
+
- lib/valicuit/engine.rb
|
101
|
+
- lib/valicuit/version.rb
|
102
|
+
- locales/es.yml
|
103
|
+
- locales/test.yml
|
104
|
+
- spec/cuit_validator_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- valicuit.gemspec
|
107
|
+
homepage: http://github.com/lndl/valicuit
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: A CUIT/CUIL validator for ActiveModel & Rails
|
131
|
+
test_files:
|
132
|
+
- spec/cuit_validator_spec.rb
|
133
|
+
- spec/spec_helper.rb
|