ssn_validation 0.1.3 → 0.1.4

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: cff944596627e765443786de2ce3ed67c257a348eb516ba002ade8d0adffc5cf
4
+ data.tar.gz: 636d1c1ce54b93c06a6d4d6ed3a66f09c067f856a216700df4a20ecda869f705
5
5
  SHA512:
6
- metadata.gz: f851627f3d715d7df181ce92c1039296ae1ab535fca5459632d4b584f317fcb2c79bc18b634993caa56d1508e5d353c69b55c5f4b5f05b864753ff65bd1e0682
7
- data.tar.gz: 4c8b4e5b1b27975e0348222ff73bf4c85a104ee5d677953a80f928b8ac4be0702eb57368fa0a2a86b10c026147219f4c38a3ae999ec82ee1cbc62438dbf6e258
6
+ metadata.gz: 73e9389c9c5e3b812019084d4dd1a4523712b0684a4c85cc2d59895046d6b24eaa99fb9f43fb36881fee827ec594e36af87b0e131a7eb7ca306fdbdfdd9461b1
7
+ data.tar.gz: 66ed232ac6c6dc0c1ff3b45b43a6f8c3fa204d8880279a7daeb3d12fb29e1c4af9d7d9fa68376fc1229e04d16df2840e48b9b7956dfec1a7da35588bcd56fe6d
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,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ssn_validation (0.1.3)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activemodel (5.2.3)
10
+ activesupport (= 5.2.3)
11
+ activesupport (5.2.3)
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.5)
17
+ i18n (1.7.0)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.12.2)
20
+ rake (12.3.3)
21
+ thread_safe (0.3.6)
22
+ tzinfo (1.2.5)
23
+ thread_safe (~> 0.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ activemodel (~> 5)
30
+ rake (~> 12)
31
+ ssn_validation!
32
+
33
+ BUNDLED WITH
34
+ 2.0.2
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).
@@ -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,8 +1,11 @@
1
+ require 'active_model'
2
+ require 'ssn_validation/ssn'
3
+
1
4
  module ActiveModel
2
5
  module Validations
3
6
  class SocialSecurityNumberValidator < EachValidator
4
7
  def validate_each(record, attribute, value)
5
- ssn_errors = Ssn.validate(value)
8
+ ssn_errors = SsnValidation::Ssn.validate(value)
6
9
  return if ssn_errors.blank?
7
10
  ssn_errors.values.each {|error| record.errors[attribute] << error}
8
11
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SsnValidation
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-03 00:00:00.000000000 Z
11
+ date: 2019-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,13 +44,15 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - README.md
47
50
  - Rakefile
48
51
  - lib/ssn_validation.rb
49
52
  - lib/ssn_validation/ssn.rb
50
53
  - lib/ssn_validation/ssn_validation.rb
51
54
  - lib/validators/social_security_number_validator.rb
52
55
  - lib/version.rb
53
- - ssn_validation-0.1.2.gem
54
56
  - ssn_validation.gemspec
55
57
  - test/lib/ssn_validation/ssn_test.rb
56
58
  - test/lib/ssn_validation_test.rb
Binary file