activevalidators 5.0.1 → 5.1.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.circleci/config.yml +84 -0
- data/AUTHORS.md +33 -0
- data/ChangeLog.md +12 -0
- data/README.md +6 -13
- data/activevalidators.gemspec +2 -2
- data/lib/active_validators/active_model/validations/sin_validator.rb +15 -6
- data/script/generate_authors +10 -0
- data/test/validations/date_test.rb +7 -2
- data/test/validations/email_test.rb +1 -0
- data/test/validations/sin_test.rb +11 -0
- metadata +6 -11
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e28fd41e5406e9d587414ae53528c6ab0ea6542950b16ba990a6f51f120bd192
|
|
4
|
+
data.tar.gz: 55add0e3513f0fe48f4924322e06456f4481ec4ce213be561b24cacd5342ebd0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0866bce8c7f7d4bbb327681eb31b185534c5322533281e2adf56919dd6fbb6ca2d1315500a88b0b85d89b9524ff83b5435c3df41a164cab0c5f4154e07f52332'
|
|
7
|
+
data.tar.gz: 065aea8ed9dc5f4581163ec02e92a25671e548714c05b90b6e229b0af8856795fe07c2a4037beea6d2a9a0332bc840a6ee56682d75994b32fb8f543ac8075802
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
|
|
3
|
+
shared: &shared
|
|
4
|
+
working_directory: ~/repo
|
|
5
|
+
steps:
|
|
6
|
+
- checkout
|
|
7
|
+
|
|
8
|
+
# Download and cache dependencies
|
|
9
|
+
- restore_cache:
|
|
10
|
+
keys:
|
|
11
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
12
|
+
# fallback to using the latest cache if no exact match is found
|
|
13
|
+
- v1-dependencies-
|
|
14
|
+
|
|
15
|
+
- run:
|
|
16
|
+
name: install dependencies
|
|
17
|
+
command: |
|
|
18
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
19
|
+
|
|
20
|
+
- save_cache:
|
|
21
|
+
paths:
|
|
22
|
+
- ./vendor/bundle
|
|
23
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
24
|
+
|
|
25
|
+
# run tests!
|
|
26
|
+
- run:
|
|
27
|
+
name: run tests
|
|
28
|
+
command: bundle exec rake
|
|
29
|
+
|
|
30
|
+
jobs:
|
|
31
|
+
# RAILS_VERSION=5.1.6
|
|
32
|
+
"ruby-2.4/rails-5.1.6":
|
|
33
|
+
<<: *shared
|
|
34
|
+
docker:
|
|
35
|
+
- image: circleci/ruby:2.4
|
|
36
|
+
environment:
|
|
37
|
+
RAILS_VERSION=5.1.6
|
|
38
|
+
|
|
39
|
+
"ruby-2.5/rails-5.1.6":
|
|
40
|
+
<<: *shared
|
|
41
|
+
docker:
|
|
42
|
+
- image: circleci/ruby:2.5
|
|
43
|
+
environment:
|
|
44
|
+
RAILS_VERSION=5.1.6
|
|
45
|
+
|
|
46
|
+
"ruby-2.6/rails-5.1.6":
|
|
47
|
+
<<: *shared
|
|
48
|
+
docker:
|
|
49
|
+
- image: circleci/ruby:2.6
|
|
50
|
+
environment:
|
|
51
|
+
RAILS_VERSION=5.1.6
|
|
52
|
+
|
|
53
|
+
# RAILS_VERSION=5.2.2
|
|
54
|
+
"ruby-2.4/rails-5.2.2":
|
|
55
|
+
<<: *shared
|
|
56
|
+
docker:
|
|
57
|
+
- image: circleci/ruby:2.4
|
|
58
|
+
environment:
|
|
59
|
+
RAILS_VERSION=5.2.2
|
|
60
|
+
|
|
61
|
+
"ruby-2.5/rails-5.2.2":
|
|
62
|
+
<<: *shared
|
|
63
|
+
docker:
|
|
64
|
+
- image: circleci/ruby:2.5
|
|
65
|
+
environment:
|
|
66
|
+
RAILS_VERSION=5.2.2
|
|
67
|
+
|
|
68
|
+
"ruby-2.6/rails-5.2.2":
|
|
69
|
+
<<: *shared
|
|
70
|
+
docker:
|
|
71
|
+
- image: circleci/ruby:2.6
|
|
72
|
+
environment:
|
|
73
|
+
RAILS_VERSION=5.2.2
|
|
74
|
+
|
|
75
|
+
workflows:
|
|
76
|
+
version: 2
|
|
77
|
+
build:
|
|
78
|
+
jobs:
|
|
79
|
+
- "ruby-2.4/rails-5.1.6"
|
|
80
|
+
- "ruby-2.5/rails-5.1.6"
|
|
81
|
+
- "ruby-2.6/rails-5.1.6"
|
|
82
|
+
- "ruby-2.4/rails-5.2.2"
|
|
83
|
+
- "ruby-2.5/rails-5.2.2"
|
|
84
|
+
- "ruby-2.6/rails-5.2.2"
|
data/AUTHORS.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Authors
|
|
2
|
+
|
|
3
|
+
In alphabetical order:
|
|
4
|
+
|
|
5
|
+
* Abe Fehr
|
|
6
|
+
* Alyssa Ross
|
|
7
|
+
* Brian Moseley
|
|
8
|
+
* Cédric FABIANSKI
|
|
9
|
+
* Etienne Depaulis
|
|
10
|
+
* Franck Verrot
|
|
11
|
+
* Garrett Bjerkhoel
|
|
12
|
+
* Guten
|
|
13
|
+
* Igor Fedoronchuk
|
|
14
|
+
* John
|
|
15
|
+
* Julien Fusco
|
|
16
|
+
* Kevin Sołtysiak
|
|
17
|
+
* Kris Windham
|
|
18
|
+
* Manuel Menezes de Sequeira
|
|
19
|
+
* Oriol Gual
|
|
20
|
+
* Paco Guzmán
|
|
21
|
+
* Pierre-Baptiste Béchu
|
|
22
|
+
* Radovan Šmitala
|
|
23
|
+
* Ray Krueger
|
|
24
|
+
* Renato Riccieri
|
|
25
|
+
* Richard Michael
|
|
26
|
+
* Rob Zuber
|
|
27
|
+
* Serj L
|
|
28
|
+
* Stefan Kracht
|
|
29
|
+
* William Howard
|
|
30
|
+
* Zachary Porter
|
|
31
|
+
* daslicious
|
|
32
|
+
* dewski
|
|
33
|
+
* lukas
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ActiveValidators [](https://circleci.com/gh/franckverrot/activevalidators)
|
|
2
2
|
|
|
3
3
|
# Description
|
|
4
4
|
|
|
@@ -124,7 +124,7 @@ Exhaustive list of supported validators and their implementation:
|
|
|
124
124
|
* `respond_to` : generic Ruby `respond_to`
|
|
125
125
|
* `siren` : [SIREN](http://fr.wikipedia.org/wiki/SIREN) company numbers in France
|
|
126
126
|
* `slug` : based on `ActiveSupport::String#parameterize`
|
|
127
|
-
* `sin` : Social Insurance Number (only for Canada). You may also allow permanent resident cards (such cards start with '9'): `:sin => {:country => :canada, :country_options => {allow_permanent_residents: true}}`
|
|
127
|
+
* `sin` : Social Insurance Number (only for Canada). You may also allow permanent resident cards (such cards start with '9') or business numbers (such numbers start with '8'): `:sin => {:country => :canada, :country_options => {allow_permanent_residents: true, allow_business_numbers: true}}`
|
|
128
128
|
* `ssn` : Social Security Number (only for USA).
|
|
129
129
|
* `tracking_number`: based on a set of predefined masks
|
|
130
130
|
* `twitter` : based on a regular expression
|
|
@@ -176,18 +176,11 @@ Lots of improvements can be made:
|
|
|
176
176
|
|
|
177
177
|
## Contributors
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
* Paco Guzmán
|
|
182
|
-
* Garrett Bjerkhoel
|
|
183
|
-
* Renato Riccieri Santos Zannon
|
|
184
|
-
* Brian Moseley
|
|
185
|
-
* Travis Vachon
|
|
186
|
-
* Rob Zuber
|
|
187
|
-
* Manuel Menezes de Sequeira
|
|
188
|
-
* Serj L aka Loremaster
|
|
189
|
-
* Pierre-Baptiste Béchu
|
|
179
|
+
Please checkout [AUTHORS.md](authors) to see who contributed. Get involved!
|
|
180
|
+
|
|
190
181
|
|
|
191
182
|
## Copyright
|
|
192
183
|
|
|
193
184
|
Copyright (c) 2010-2018 Franck Verrot. MIT LICENSE. See LICENSE for details.
|
|
185
|
+
|
|
186
|
+
[authors]: https://github.com/franckverrot/activevalidators/blob/master/AUTHORS.md
|
data/activevalidators.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'activevalidators'
|
|
4
|
-
s.version = '5.0
|
|
4
|
+
s.version = '5.1.0'
|
|
5
5
|
s.platform = Gem::Platform::RUBY
|
|
6
|
-
s.authors = ['Franck Verrot'
|
|
6
|
+
s.authors = ['Franck Verrot']
|
|
7
7
|
s.email = ['franck@verrot.fr']
|
|
8
8
|
s.homepage = 'http://github.com/franckverrot/activevalidators'
|
|
9
9
|
s.summary = %q{Collection of ActiveModel/ActiveRecord validations}
|
|
@@ -20,28 +20,31 @@ module ActiveModel
|
|
|
20
20
|
# The Social Insurance Number is a nine-digit number in the format "AAA BBB CCC".
|
|
21
21
|
# The number is divided into three parts.
|
|
22
22
|
# AAA - is the first, BBB - is the second and the CCC is the third.
|
|
23
|
-
# Numbers that begin with the number "9" are issued to temporary residents who are not Canadian citizens
|
|
23
|
+
# Numbers that begin with the number "9" are issued to temporary residents who are not Canadian citizens.
|
|
24
|
+
# Numbers that begin with the number "8" are issued to businesses as "Business Numbers".
|
|
24
25
|
# More details: http://en.wikipedia.org/wiki/Social_Insurance_Number
|
|
25
26
|
#
|
|
26
27
|
# Possible flags:
|
|
27
28
|
# allow_permanent_residents - citizens with cars, which begins with "9" are valid. By default it is false.
|
|
29
|
+
# allow_business_numbers - business numbers, which begins with "8" are valid. By default it is false.
|
|
28
30
|
#
|
|
29
|
-
# validates :sin, :sin => {:country => :canada, :country_options => {:allow_permanent_residents => true}}
|
|
31
|
+
# validates :sin, :sin => {:country => :canada, :country_options => {:allow_permanent_residents => true, :allow_business_numbers => true}}
|
|
30
32
|
class SinValidatorCanada
|
|
31
33
|
def initialize(str_value, options)
|
|
32
34
|
@sin = str_value.gsub(/\D/, '') # keep only integers
|
|
33
35
|
@allow_permanent_residents = false
|
|
36
|
+
@allow_business_numbers = false
|
|
34
37
|
|
|
35
38
|
country_options = options.fetch(:country_options, {})
|
|
36
39
|
allow_permanent_residents = country_options.fetch(:allow_permanent_residents, :nil)
|
|
40
|
+
allow_business_numbers = country_options.fetch(:allow_business_numbers, :nil)
|
|
37
41
|
|
|
38
|
-
if allow_permanent_residents == true
|
|
39
|
-
|
|
40
|
-
end
|
|
42
|
+
@allow_permanent_residents = true if allow_permanent_residents == true
|
|
43
|
+
@allow_business_numbers = true if allow_business_numbers == true
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
def valid?
|
|
44
|
-
size_is?(9) && is_not_full_of_zeroes && allow_permanent_residents? && LuhnChecker.valid?(@sin)
|
|
47
|
+
size_is?(9) && is_not_full_of_zeroes && allow_permanent_residents? && allow_business_numbers? && LuhnChecker.valid?(@sin)
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
def size_is?(count)
|
|
@@ -61,6 +64,12 @@ module ActiveModel
|
|
|
61
64
|
true
|
|
62
65
|
end
|
|
63
66
|
end
|
|
67
|
+
|
|
68
|
+
def allow_business_numbers?
|
|
69
|
+
business_indentifier = '8'
|
|
70
|
+
|
|
71
|
+
!(@allow_business_numbers == false && @sin.start_with?(business_indentifier))
|
|
72
|
+
end
|
|
64
73
|
end
|
|
65
74
|
end
|
|
66
75
|
end
|
|
@@ -9,10 +9,15 @@ ActiveValidators.activate(:date)
|
|
|
9
9
|
# [on Github](https://github.com/codegram/date_validator)
|
|
10
10
|
describe "Date Validation" do
|
|
11
11
|
it "finds the translations" do
|
|
12
|
-
|
|
13
|
-
d = TestRecord.new(:start_date => Time.now, :end_date => Time.now - 1)
|
|
12
|
+
d = build_date_record
|
|
14
13
|
|
|
15
14
|
refute d.valid?
|
|
16
15
|
refute_includes d.errors.to_s, 'translation missing'
|
|
17
16
|
end
|
|
17
|
+
|
|
18
|
+
def build_date_record
|
|
19
|
+
TestRecord.reset_callbacks(:validate)
|
|
20
|
+
TestRecord.validates :start_date, :date => { :before => :end_date }
|
|
21
|
+
TestRecord.new(:start_date => Time.now, :end_date => Time.now - 1)
|
|
22
|
+
end
|
|
18
23
|
end
|
|
@@ -110,6 +110,7 @@ describe "Email Validation" do
|
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
+
before { TestRecord.reset_callbacks(:validate) }
|
|
113
114
|
it "checks validity of the arguments" do
|
|
114
115
|
[3, "foo", 1..6].each do |wrong_argument|
|
|
115
116
|
assert_raises(ArgumentError,"Not a callable object #{wrong_argument.inspect}") do
|
|
@@ -34,6 +34,11 @@ describe "SIN validations" do
|
|
|
34
34
|
subject.valid?.must_equal false
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
it "rejects valid business numbers by default" do
|
|
38
|
+
subject = build_sin_record({:sin => '897 454 286'}, {:country => :canada })
|
|
39
|
+
subject.valid?.must_equal false
|
|
40
|
+
end
|
|
41
|
+
|
|
37
42
|
it "rejects invalid sin for permanent residents" do
|
|
38
43
|
subject = build_sin_record({:sin => '123 456 789'}, {:country => :canada })
|
|
39
44
|
subject.valid?.must_equal false
|
|
@@ -56,6 +61,12 @@ describe "SIN validations" do
|
|
|
56
61
|
{:country => :canada, :country_options => { allow_permanent_residents: true } })
|
|
57
62
|
subject.valid?.must_equal true
|
|
58
63
|
end
|
|
64
|
+
|
|
65
|
+
it "accept valid business numbers when flag is provided" do
|
|
66
|
+
subject = build_sin_record({:sin => '897 454 286'},
|
|
67
|
+
{:country => :canada, :country_options => { allow_business_numbers: true } })
|
|
68
|
+
subject.valid?.must_equal true
|
|
69
|
+
end
|
|
59
70
|
end
|
|
60
71
|
end
|
|
61
72
|
|
metadata
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activevalidators
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.0
|
|
4
|
+
version: 5.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Franck Verrot
|
|
8
|
-
- Paco Guzmán
|
|
9
|
-
- Oriol Gual
|
|
10
|
-
- Garrett Bjerkhoel
|
|
11
|
-
- Renato Riccieri Santos Zannon
|
|
12
|
-
- Brian Moseley
|
|
13
|
-
- Serj L aka Loremaster
|
|
14
8
|
autorequire:
|
|
15
9
|
bindir: bin
|
|
16
10
|
cert_chain:
|
|
@@ -40,7 +34,7 @@ cert_chain:
|
|
|
40
34
|
akLQjJWKHQCzyqDChJHRGhlxyVFKP2JwqFgzE3p1l64JArsb7BEqhpoBPXMwlChE
|
|
41
35
|
HgzCBTsCU0syQBb1s6lBz2HrWA4=
|
|
42
36
|
-----END CERTIFICATE-----
|
|
43
|
-
date:
|
|
37
|
+
date: 2019-03-28 00:00:00.000000000 Z
|
|
44
38
|
dependencies:
|
|
45
39
|
- !ruby/object:Gem::Dependency
|
|
46
40
|
name: bundler
|
|
@@ -181,8 +175,9 @@ executables: []
|
|
|
181
175
|
extensions: []
|
|
182
176
|
extra_rdoc_files: []
|
|
183
177
|
files:
|
|
178
|
+
- ".circleci/config.yml"
|
|
184
179
|
- ".gitignore"
|
|
185
|
-
-
|
|
180
|
+
- AUTHORS.md
|
|
186
181
|
- ChangeLog.md
|
|
187
182
|
- Gemfile
|
|
188
183
|
- LICENSE
|
|
@@ -218,6 +213,7 @@ files:
|
|
|
218
213
|
- lib/active_validators/active_model/validations/url_validator.rb
|
|
219
214
|
- lib/active_validators/one_nine_shims/one_nine_string.rb
|
|
220
215
|
- lib/activevalidators.rb
|
|
216
|
+
- script/generate_authors
|
|
221
217
|
- test/test_helper.rb
|
|
222
218
|
- test/validations/barcode_test.rb
|
|
223
219
|
- test/validations/credit_card_test.rb
|
|
@@ -257,8 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
257
253
|
- !ruby/object:Gem::Version
|
|
258
254
|
version: '0'
|
|
259
255
|
requirements: []
|
|
260
|
-
|
|
261
|
-
rubygems_version: 3.0.0.beta1
|
|
256
|
+
rubygems_version: 3.0.2
|
|
262
257
|
signing_key:
|
|
263
258
|
specification_version: 4
|
|
264
259
|
summary: Collection of ActiveModel/ActiveRecord validations
|
metadata.gz.sig
CHANGED
|
Binary file
|