ssn_validation 0.1.3 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d6fc2b63bb6a88c25c5f12e6893f8981a38b5c370401208ae3545f5a5de62ba
4
- data.tar.gz: b8d05dcfcf93ef235727dd14e495e84219ca3bdf58f560f93c60538ed9dd62a0
3
+ metadata.gz: 38c6472153b88ebf4f6a4104c6c26bde9ef6502aa2ea2e0baa46a6424586070c
4
+ data.tar.gz: c0128cc9d311f0d2cb517a093ee40c4e29cec094ea269b027cce9673f4f1f05a
5
5
  SHA512:
6
- metadata.gz: f851627f3d715d7df181ce92c1039296ae1ab535fca5459632d4b584f317fcb2c79bc18b634993caa56d1508e5d353c69b55c5f4b5f05b864753ff65bd1e0682
7
- data.tar.gz: 4c8b4e5b1b27975e0348222ff73bf4c85a104ee5d677953a80f928b8ac4be0702eb57368fa0a2a86b10c026147219f4c38a3ae999ec82ee1cbc62438dbf6e258
6
+ metadata.gz: aa26ac041a28dd87d6d7eb079e0f5dcbf2f3905a48358012d923019febe4df73cd9b501a36e9b2a5fc400a275c7ba70996b9107b503c1ded48cda9e1d0b6164b
7
+ data.tar.gz: a319dbe9cbea64193daaae9513689bd2f8d49bb17f8732eb08fad09d106dfb9cdbd214602b9b75341dbf2299d2fd127b8767ea29f5cba298f21b7cd50fa1af9c
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "http://rubygems.org"
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ssn_validation (0.1.7)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activemodel (5.2.6)
10
+ activesupport (= 5.2.6)
11
+ activesupport (5.2.6)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ concurrent-ruby (1.1.9)
17
+ i18n (1.8.11)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.14.4)
20
+ rake (12.3.3)
21
+ thread_safe (0.3.6)
22
+ tzinfo (1.2.9)
23
+ thread_safe (~> 0.1)
24
+
25
+ PLATFORMS
26
+ x86_64-darwin-20
27
+ x86_64-linux
28
+
29
+ DEPENDENCIES
30
+ activemodel (~> 5)
31
+ minitest
32
+ rake (~> 12)
33
+ ssn_validation!
34
+
35
+ BUNDLED WITH
36
+ 2.2.22
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # SsnValidation
2
+
3
+ SsnValidation is a very basic ruby gem that can validate a US Social Security Number (SSN) or ITIN. It returns a hash of error keys/messages that can be
4
+ used within ActiveRecord errors or otherwise to ensure syntactically valid SSNs.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ssn_validation'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ssn_validation
21
+
22
+ ## Usage
23
+
24
+ ```
25
+ ❯ irb
26
+ > require 'ssn_validation'
27
+ > SsnValidation::Ssn.validate('abc')
28
+ => {:nine_digits=>"SSN value is not 9 digits", :non_digits=>"SSN value contains non-digits"}
29
+ > SsnValidation::Ssn.validate(123006789)
30
+ => {:zero_group=>"SSN value contains zeros in group number xxx-00-xxxx"}
31
+ > SsnValidation::Ssn.validate(nil)
32
+ => {:nine_digits=>"SSN value is not 9 digits"}
33
+ > SsnValidation::Ssn.validate('')
34
+ => {:nine_digits=>"SSN value is not 9 digits"}
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/johnsinco/ssn_validation
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'rake/testtask'
2
2
 
3
3
  Rake::TestTask.new(:test) do |t|
4
- t.pattern = 'test/**/*_test.rb'
4
+ t.libs << "test"
5
+ t.libs << "lib"
6
+ t.test_files = FileList['test/**/*_test.rb']
5
7
  t.verbose = true
6
8
  t.warning = true
7
9
  end
@@ -2,10 +2,11 @@ module SsnValidation
2
2
  module Ssn
3
3
  DIGITS = %w[0 1 2 3 4 5 6 7 8 9].freeze
4
4
  DIGITS_EX0 = DIGITS[1..-1]
5
+ VALID_ITIN_GROUPS = [50..65, 70..88, 90..92, 94..99].map(&:to_a).flatten.freeze
5
6
 
6
7
  # returns a hash of 0..n key/value pairs for ssn validation error codes and a default message for each
7
8
  def self.validate(ssn)
8
- ssn = ssn.to_s
9
+ ssn = ssn.to_s.delete('-') # be lenient with incoming dash chars
9
10
  errors = {}
10
11
  return errors if test_ssn?(ssn)
11
12
 
@@ -49,8 +50,11 @@ module SsnValidation
49
50
  false
50
51
  end
51
52
 
53
+ # https://www.irs.gov/irm/part3/irm_03-021-263r
52
54
  def self.invalid_itin?(ssn)
53
- ssn[0] == "9" && !%w[7 8].include?(ssn[3])
55
+ return false unless ssn[0] == "9"
56
+ group = ssn[3..4].to_i
57
+ !VALID_ITIN_GROUPS.include?(group)
54
58
  end
55
59
 
56
60
  def self.test_ssn?(ssn)
@@ -1,2 +1,9 @@
1
1
  require 'ssn_validation/ssn_validation'
2
2
  require 'ssn_validation/ssn'
3
+
4
+ # optional ActiveModel dependency for custom validator
5
+ begin
6
+ require 'validators/social_security_number_validator'
7
+ rescue
8
+ nil
9
+ end
@@ -1,10 +1,16 @@
1
+ require 'active_model'
2
+ require 'ssn_validation/ssn'
3
+
1
4
  module ActiveModel
2
5
  module Validations
3
6
  class SocialSecurityNumberValidator < EachValidator
7
+ def initialize(options)
8
+ super
9
+ end
4
10
  def validate_each(record, attribute, value)
5
- ssn_errors = Ssn.validate(value)
11
+ ssn_errors = SsnValidation::Ssn.validate(value)
6
12
  return if ssn_errors.blank?
7
- ssn_errors.values.each {|error| record.errors[attribute] << error}
13
+ ssn_errors.values.each { |error| record.errors.add(attribute, error, **options) }
8
14
  end
9
15
  end
10
16
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SsnValidation
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -18,5 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.required_ruby_version = '>= 2.3'
19
19
  spec.add_development_dependency "rake", '~> 12'
20
20
  spec.add_development_dependency "activemodel", '~> 5'
21
+ spec.add_development_dependency "minitest"
21
22
  end
22
23
 
@@ -1,5 +1,5 @@
1
1
  require 'minitest/autorun'
2
- require 'ssn_validation/ssn'
2
+ require 'ssn_validation'
3
3
 
4
4
  class SsnTest < Minitest::Test
5
5
  include SsnValidation
@@ -7,59 +7,71 @@ class SsnTest < Minitest::Test
7
7
  describe 'valid formats' do
8
8
  describe 'valid ITIN' do
9
9
  it 'is valid' do
10
- assert_equal({}, Ssn.validate('911781111'))
10
+ _(Ssn.validate('911781111')).must_equal({})
11
+ _(Ssn.validate('911501111')).must_equal({})
12
+ _(Ssn.validate('911651111')).must_equal({})
13
+ _(Ssn.validate('911651111')).must_equal({})
14
+ _(Ssn.validate('911881111')).must_equal({})
15
+ _(Ssn.validate('911901111')).must_equal({})
16
+ _(Ssn.validate('911991111')).must_equal({})
11
17
  end
12
18
  end
13
19
  describe 'valid SSN' do
14
20
  it 'is valid' do
15
- assert_equal({}, Ssn.validate('123432100'))
21
+ _(Ssn.validate('123432100')).must_equal({})
16
22
  end
17
23
  end
18
24
  describe 'valid repeating SSN' do
19
25
  it 'is valid' do
20
- assert_equal({}, Ssn.validate('123444444'))
26
+ _(Ssn.validate('123444444')).must_equal({})
27
+ end
28
+ end
29
+ describe 'valid with dashes' do
30
+ it 'ignores the dashes' do
31
+ _(Ssn.validate('123-44-4444')).must_equal({})
21
32
  end
22
33
  end
23
34
  end
24
35
  describe 'invalid formats' do
25
36
  describe '666 is invalid' do
26
37
  it 'is valid' do
27
- assert_equal({excluded_666: 'SSN value contains excluded area 666-xx-xxxx'}, Ssn.validate('666123210'))
38
+ _(Ssn.validate('666123210')).must_equal({excluded_666: 'SSN value contains excluded area 666-xx-xxxx'})
28
39
  end
29
40
  end
30
41
  describe 'zero area numbers invalid' do
31
42
  it 'is invalid' do
32
- assert_equal({zero_area: 'SSN value contains zeros in area number 000-xx-xxxx'}, Ssn.validate('000567890'))
43
+ _(Ssn.validate('000567890')).must_equal({zero_area: 'SSN value contains zeros in area number 000-xx-xxxx'})
33
44
  end
34
45
  end
35
46
  describe 'zero group numbers invalid' do
36
47
  it 'is invalid' do
37
- assert_equal({zero_group: 'SSN value contains zeros in group number xxx-00-xxxx'}, Ssn.validate('567007890'))
48
+ _(Ssn.validate('567007890')).must_equal({zero_group: 'SSN value contains zeros in group number xxx-00-xxxx'})
38
49
  end
39
50
  end
40
51
  describe 'zero serial numbers invalid' do
41
52
  it 'is invalid' do
42
- assert_equal({zero_serial: 'SSN value contains zeros in serial number xxx-xx-0000'}, Ssn.validate('567890000'))
53
+ _(Ssn.validate('567890000')).must_equal({zero_serial: 'SSN value contains zeros in serial number xxx-xx-0000'})
43
54
  end
44
55
  end
45
56
  describe 'non digits invalid' do
46
57
  it 'is invalid' do
47
- assert_equal({non_digits: 'SSN value contains non-digits'}, Ssn.validate('ABCDEFGHI'))
58
+ _(Ssn.validate('ABCDEFGHI')).must_equal({non_digits: 'SSN value contains non-digits'})
48
59
  end
49
60
  end
50
61
  describe 'not 9 digits invalid' do
51
62
  it 'is invalid' do
52
- assert_equal({nine_digits: 'SSN value is not 9 digits'}, Ssn.validate('303'))
63
+ _(Ssn.validate('303')).must_equal({nine_digits: 'SSN value is not 9 digits'})
53
64
  end
54
65
  end
55
- describe 'repeating digits invalid' do
66
+ describe 'repeating digits invalid' do
56
67
  it 'is invalid' do
57
- assert_equal({repeating: 'SSN value contains repeating digits'}, Ssn.validate('888888888'))
68
+ _(Ssn.validate('888888888')).must_equal({repeating: 'SSN value contains repeating digits'})
58
69
  end
59
70
  end
60
71
  describe 'invalid ITIN' do
61
72
  it 'is invalid' do
62
- assert_equal({invalid_itin: 'SSN value contains invalid ITIN format 9xx-[x]x-xxxx'}, Ssn.validate('900991234'))
73
+ _(Ssn.validate('900121234')).must_equal({invalid_itin: 'SSN value contains invalid ITIN format 9xx-[x]x-xxxx'})
74
+ _(Ssn.validate('900441234')).must_equal({invalid_itin: 'SSN value contains invalid ITIN format 9xx-[x]x-xxxx'})
63
75
  end
64
76
  end
65
77
  end
@@ -69,46 +81,46 @@ class SsnTest < Minitest::Test
69
81
  end
70
82
  describe 'ascending digits invalid' do
71
83
  it 'is invalid' do
72
- assert_equal({ascending: 'SSN value contains all ASCENDING digits'}, Ssn.validate('123456789'))
73
- assert_equal({ascending: 'SSN value contains all ASCENDING digits'}, Ssn.validate('567891234'))
84
+ _(Ssn.validate('123456789')).must_equal({ascending: 'SSN value contains all ASCENDING digits'})
85
+ _(Ssn.validate('567891234')).must_equal({ascending: 'SSN value contains all ASCENDING digits'})
74
86
  end
75
87
  end
76
88
  describe 'ascending digits ex 0 invalid' do
77
89
  it 'is invalid' do
78
- assert_equal({ascending: 'SSN value contains all ASCENDING digits'}, Ssn.validate('678912345'))
79
- assert_equal({ascending: 'SSN value contains all ASCENDING digits'}, Ssn.validate('123456789'))
80
- assert_equal({ascending: 'SSN value contains all ASCENDING digits'}, Ssn.validate('234567891'))
90
+ _(Ssn.validate('678912345')).must_equal({ascending: 'SSN value contains all ASCENDING digits'})
91
+ _(Ssn.validate('123456789')).must_equal({ascending: 'SSN value contains all ASCENDING digits'})
92
+ _(Ssn.validate('234567891')).must_equal({ascending: 'SSN value contains all ASCENDING digits'})
81
93
  end
82
94
  end
83
95
  describe 'descending digits invalid' do
84
96
  it 'is invalid' do
85
- assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('876543210'))
86
- assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('321098765'))
87
- assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('765432109'))
97
+ _(Ssn.validate('876543210')).must_equal({descending: 'SSN value contains all DESCENDING digits'})
98
+ _(Ssn.validate('321098765')).must_equal({descending: 'SSN value contains all DESCENDING digits'})
99
+ _(Ssn.validate('765432109')).must_equal({descending: 'SSN value contains all DESCENDING digits'})
88
100
  end
89
101
  end
90
102
  describe 'descending digits ex 0 invalid' do
91
103
  it 'is invalid' do
92
- assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('321987654'))
93
- assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('765432198'))
104
+ _(Ssn.validate('321987654')).must_equal({descending: 'SSN value contains all DESCENDING digits'})
105
+ _(Ssn.validate('765432198')).must_equal({descending: 'SSN value contains all DESCENDING digits'})
94
106
  end
95
107
  end
96
108
  end
97
109
  describe 'allowing dummy ssns' do
98
110
  it 'allows 666xxxxx' do
99
111
  SsnValidation.config.test_ssns = [/^666/]
100
- assert_equal({}, Ssn.validate('666123456'))
112
+ _(Ssn.validate('666123456')).must_equal({})
101
113
  SsnValidation.config.test_ssns = []
102
114
  end
103
115
  it 'allows random test ssns' do
104
116
  SsnValidation.config.test_ssns = ['509421234']
105
- assert_equal({}, Ssn.validate('509421234'))
117
+ _(Ssn.validate('509421234')).must_equal({})
106
118
  SsnValidation.config.test_ssns = []
107
119
  end
108
120
  it 'allows multiple test ssns' do
109
121
  SsnValidation.config.test_ssns = ['999999999', /^666/]
110
- assert_equal({}, Ssn.validate('666123456'))
111
- assert_equal({}, Ssn.validate('999999999'))
122
+ _(Ssn.validate('666123456')).must_equal({})
123
+ _(Ssn.validate('999999999')).must_equal({})
112
124
  SsnValidation.config.test_ssns = []
113
125
  end
114
126
  end
@@ -1,18 +1,30 @@
1
- # require 'minitest/autorun'
2
- # require 'ssn_validation'
3
- # require 'activemodel'
1
+ require 'minitest/autorun'
2
+ require 'active_model'
3
+ require 'ssn_validation'
4
+ require 'validators/social_security_number_validator'
4
5
 
5
- # class SsnTestModel
6
- # include ActiveModel::Validations
7
- # attr_accessor :ssn
8
- # validates :ssn, social_security_number: true
9
- # end
6
+ class SsnTestModel
7
+ include ActiveModel::Validations
8
+ attr_accessor :ssn
9
+ validates :ssn, social_security_number: true
10
+ end
10
11
 
11
- # class SocialSecurityNumberValidatorTest < Minitest::Test
12
- # describe 'it uses the ssn validation rules' do
13
- # it 'validates' do
14
- # subject = SsnTestModel.new(ssn: '666000000')
15
- # assert_equal({}, subject.errors)
16
- # end
17
- # end
18
- # end
12
+ class SocialSecurityNumberValidatorTest < Minitest::Test
13
+ describe 'it uses the ssn validation rules' do
14
+ it 'validates' do
15
+ subject = SsnTestModel.new
16
+ subject.ssn = '123454321'
17
+ assert subject.valid?
18
+ assert_equal({}, subject.errors.to_h)
19
+ end
20
+
21
+ it 'can use the ascending validation rules' do
22
+ SsnValidation.config.enable_ascending = true
23
+ subject = SsnTestModel.new
24
+ subject.ssn = '123456789'
25
+ subject.valid?
26
+ assert_equal({ssn: 'SSN value contains all ASCENDING digits'}, subject.errors.to_h)
27
+ SsnValidation.config.enable_ascending = false
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssn_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Stewart
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-03 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,19 +38,36 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5'
41
- description:
42
- email:
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
43
57
  executables: []
44
58
  extensions: []
45
59
  extra_rdoc_files: []
46
60
  files:
61
+ - ".github/workflows/ruby.yml"
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README.md
47
65
  - Rakefile
48
66
  - lib/ssn_validation.rb
49
67
  - lib/ssn_validation/ssn.rb
50
68
  - lib/ssn_validation/ssn_validation.rb
51
69
  - lib/validators/social_security_number_validator.rb
52
70
  - lib/version.rb
53
- - ssn_validation-0.1.2.gem
54
71
  - ssn_validation.gemspec
55
72
  - test/lib/ssn_validation/ssn_test.rb
56
73
  - test/lib/ssn_validation_test.rb
@@ -59,7 +76,7 @@ homepage: https://github.com/johnsinco/ssn_validation
59
76
  licenses:
60
77
  - Apache-2.0
61
78
  metadata: {}
62
- post_install_message:
79
+ post_install_message:
63
80
  rdoc_options: []
64
81
  require_paths:
65
82
  - lib
@@ -74,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
91
  - !ruby/object:Gem::Version
75
92
  version: '0'
76
93
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 2.7.6.2
79
- signing_key:
94
+ rubygems_version: 3.2.22
95
+ signing_key:
80
96
  specification_version: 4
81
97
  summary: Social Security Number (SSN) Validation
82
98
  test_files:
Binary file