ssn_validator 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/History.txt +41 -0
- data/LICENSE +20 -0
- data/PostInstall.txt +29 -0
- data/README.rdoc +98 -0
- data/Rakefile +60 -0
- data/VERSION.yml +5 -0
- data/generators/death_master_file_migration/death_master_file_migration_generator.rb +12 -0
- data/generators/death_master_file_migration/templates/migration.rb +26 -0
- data/generators/ssn_validator_migration/ssn_validator_migration_generator.rb +12 -0
- data/generators/ssn_validator_migration/templates/migration.rb +18 -0
- data/lib/ssn_validator.rb +12 -0
- data/lib/ssn_validator/models/death_master_file.rb +5 -0
- data/lib/ssn_validator/models/death_master_file_loader.rb +235 -0
- data/lib/ssn_validator/models/ssn_high_group_code.rb +5 -0
- data/lib/ssn_validator/models/ssn_high_group_code_loader.rb +87 -0
- data/lib/ssn_validator/models/ssn_validator.rb +94 -0
- data/lib/ssn_validator/ntis.rb +9 -0
- data/lib/tasks/ssn_validator.rake +24 -0
- data/rdoc/classes/DeathMasterFile.html +111 -0
- data/rdoc/classes/DeathMasterFileLoader.html +298 -0
- data/rdoc/classes/SsnHighGroupCode.html +111 -0
- data/rdoc/classes/SsnHighGroupCodeLoader.html +202 -0
- data/rdoc/classes/SsnValidator.html +116 -0
- data/rdoc/classes/SsnValidator/Ntis.html +111 -0
- data/rdoc/classes/SsnValidator/Ssn.html +315 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/LICENSE.html +129 -0
- data/rdoc/files/README_rdoc.html +262 -0
- data/rdoc/files/lib/ssn_validator/models/death_master_file_loader_rb.html +112 -0
- data/rdoc/files/lib/ssn_validator/models/death_master_file_rb.html +108 -0
- data/rdoc/files/lib/ssn_validator/models/ssn_high_group_code_loader_rb.html +108 -0
- data/rdoc/files/lib/ssn_validator/models/ssn_high_group_code_rb.html +108 -0
- data/rdoc/files/lib/ssn_validator/models/ssn_validator_rb.html +101 -0
- data/rdoc/files/lib/ssn_validator/ntis_rb.html +101 -0
- data/rdoc/files/lib/ssn_validator_rb.html +113 -0
- data/rdoc/fr_class_index.html +33 -0
- data/rdoc/fr_file_index.html +35 -0
- data/rdoc/fr_method_index.html +37 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/ssn_validator.gemspec +130 -0
- data/test/files/test_dmf_funky_data_load.txt +6 -0
- data/test/files/test_dmf_initial_load.txt +5 -0
- data/test/files/test_dmf_update_load.txt +5 -0
- data/test/files/valid_csv_from_funky_data_file.txt +6 -0
- data/test/mocks/test/death_master_file_loader.rb +40 -0
- data/test/test_death_master_file_loader.rb +113 -0
- data/test/test_helper.rb +62 -0
- data/test/test_ssn_high_group_code_loader.rb +22 -0
- data/test/test_ssn_validator.rb +85 -0
- metadata +145 -0
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/ssn_validator.rb'}"
|
9
|
+
puts "Loading ssn_validator gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ssn_validator}
|
8
|
+
s.version = "1.0.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kevin Tyll"]
|
12
|
+
s.date = %q{2010-02-05}
|
13
|
+
s.description = %q{Validates whether an SSN has likely been issued or not.}
|
14
|
+
s.email = %q{kevintyll@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"History.txt",
|
22
|
+
"LICENSE",
|
23
|
+
"PostInstall.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION.yml",
|
27
|
+
"generators/death_master_file_migration/death_master_file_migration_generator.rb",
|
28
|
+
"generators/death_master_file_migration/templates/migration.rb",
|
29
|
+
"generators/ssn_validator_migration/.DS_Store",
|
30
|
+
"generators/ssn_validator_migration/ssn_validator_migration_generator.rb",
|
31
|
+
"generators/ssn_validator_migration/templates/.DS_Store",
|
32
|
+
"generators/ssn_validator_migration/templates/migration.rb",
|
33
|
+
"lib/ssn_validator.rb",
|
34
|
+
"lib/ssn_validator/models/death_master_file.rb",
|
35
|
+
"lib/ssn_validator/models/death_master_file_loader.rb",
|
36
|
+
"lib/ssn_validator/models/ssn_high_group_code.rb",
|
37
|
+
"lib/ssn_validator/models/ssn_high_group_code_loader.rb",
|
38
|
+
"lib/ssn_validator/models/ssn_validator.rb",
|
39
|
+
"lib/ssn_validator/ntis.rb",
|
40
|
+
"lib/tasks/ssn_validator.rake",
|
41
|
+
"rdoc/classes/DeathMasterFile.html",
|
42
|
+
"rdoc/classes/DeathMasterFileLoader.html",
|
43
|
+
"rdoc/classes/SsnHighGroupCode.html",
|
44
|
+
"rdoc/classes/SsnHighGroupCodeLoader.html",
|
45
|
+
"rdoc/classes/SsnValidator.html",
|
46
|
+
"rdoc/classes/SsnValidator/Ntis.html",
|
47
|
+
"rdoc/classes/SsnValidator/Ssn.html",
|
48
|
+
"rdoc/created.rid",
|
49
|
+
"rdoc/files/LICENSE.html",
|
50
|
+
"rdoc/files/README_rdoc.html",
|
51
|
+
"rdoc/files/lib/ssn_validator/models/death_master_file_loader_rb.html",
|
52
|
+
"rdoc/files/lib/ssn_validator/models/death_master_file_rb.html",
|
53
|
+
"rdoc/files/lib/ssn_validator/models/ssn_high_group_code_loader_rb.html",
|
54
|
+
"rdoc/files/lib/ssn_validator/models/ssn_high_group_code_rb.html",
|
55
|
+
"rdoc/files/lib/ssn_validator/models/ssn_validator_rb.html",
|
56
|
+
"rdoc/files/lib/ssn_validator/ntis_rb.html",
|
57
|
+
"rdoc/files/lib/ssn_validator_rb.html",
|
58
|
+
"rdoc/fr_class_index.html",
|
59
|
+
"rdoc/fr_file_index.html",
|
60
|
+
"rdoc/fr_method_index.html",
|
61
|
+
"rdoc/index.html",
|
62
|
+
"rdoc/rdoc-style.css",
|
63
|
+
"script/console",
|
64
|
+
"script/destroy",
|
65
|
+
"script/generate",
|
66
|
+
"ssn_validator.gemspec",
|
67
|
+
"test/files/test_dmf_funky_data_load.txt",
|
68
|
+
"test/files/test_dmf_initial_load.txt",
|
69
|
+
"test/files/test_dmf_update_load.txt",
|
70
|
+
"test/files/valid_csv_from_funky_data_file.txt",
|
71
|
+
"test/mocks/test/death_master_file_loader.rb",
|
72
|
+
"test/test_death_master_file_loader.rb",
|
73
|
+
"test/test_helper.rb",
|
74
|
+
"test/test_ssn_high_group_code_loader.rb",
|
75
|
+
"test/test_ssn_validator.rb"
|
76
|
+
]
|
77
|
+
s.homepage = %q{http://kevintyll.git.com/ssn_validator}
|
78
|
+
s.post_install_message = %q{
|
79
|
+
For more information on ssn_validator, see http://kevintyll.github.com/ssn_validator/
|
80
|
+
|
81
|
+
* To create the necessary db migration, from the command line, run:
|
82
|
+
script/generate ssn_validator_migration
|
83
|
+
* Require the gem in your environment.rb file in the Rails::Initializer block:
|
84
|
+
config.gem 'kevintyll-ssn_validator', :lib => 'ssn_validator'
|
85
|
+
* To load your table with the current SSN data, from the command line, run:
|
86
|
+
rake ssn_validator:update_data
|
87
|
+
* The SSN data is updated monthly, so you'll want to run this rake task monthly to keep your validations accurate.
|
88
|
+
* If you've purchased the death master file data, create the death_master_files migration:
|
89
|
+
script/generate death_master_file_migration
|
90
|
+
* To load the dmf files you receive from ntis:
|
91
|
+
rake ssn_validator:death_master_file:load_file PATH='path/to/file' AS_OF='2009-03-01'
|
92
|
+
* You'll need to pass in the full path to where the file is on disk. You'll also need
|
93
|
+
to pass in the date this file's data are as of in the format yyyy-mm-dd.
|
94
|
+
* This task must be used to load the initial file you receive from ntis on CD. It can optionally be used
|
95
|
+
to load the monthly update files you download from the website. If you manually download the update files,
|
96
|
+
you do not need to add your user name and password to the environment.rb file. For a more automated approach
|
97
|
+
to loading the update files, add your user name and password to the environment.rb file and use the 2nd rake task.
|
98
|
+
* To load the monthly updates from the ntis website:
|
99
|
+
* Add your user_name and password to the environment.rb file
|
100
|
+
SsnValidator::Ntis.user_name = 'REPLACE WITH YOUR dmf.ntis.gov USER NAME'
|
101
|
+
SsnValidator::Ntis.password = 'REPLACE WITH YOUR dmf.ntis.gov PASSWORD'
|
102
|
+
* Run the rake task:
|
103
|
+
rake ssn_validator:death_master_file:update_data
|
104
|
+
* This rake task will determine the most recent file that has been loaded, and loads all subsequent files in order
|
105
|
+
from the dmf.ntis.gov website.
|
106
|
+
* The death master file data is updated monthly, so you'll want to run this rake task monthly to keep your validations accurate.
|
107
|
+
}
|
108
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
109
|
+
s.require_paths = ["lib"]
|
110
|
+
s.rubygems_version = %q{1.3.5}
|
111
|
+
s.summary = %q{Validates whether an SSN has likely been issued or not.}
|
112
|
+
s.test_files = [
|
113
|
+
"test/mocks/test/death_master_file_loader.rb",
|
114
|
+
"test/test_death_master_file_loader.rb",
|
115
|
+
"test/test_helper.rb",
|
116
|
+
"test/test_ssn_high_group_code_loader.rb",
|
117
|
+
"test/test_ssn_validator.rb"
|
118
|
+
]
|
119
|
+
|
120
|
+
if s.respond_to? :specification_version then
|
121
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
122
|
+
s.specification_version = 3
|
123
|
+
|
124
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
125
|
+
else
|
126
|
+
end
|
127
|
+
else
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
A772781978BAD DEATH DAY ANTHONY GABRIEL P031020090130200910
|
2
|
+
A772783025BAD DEATH MONTH JUAN P000220091101191010
|
3
|
+
A772786197BAD BIRTH YEAR ISAIAH P0202200901100009FO
|
4
|
+
A772786123QUOTED MIDDLE NAME ISAIAH ' P0202200901102009FO
|
5
|
+
A342786123QUOTED'NAME ISAIAH P0202200901102009FO
|
6
|
+
A344566123QUOTED NAME' ISAIAH P0202200901102009FO
|
@@ -0,0 +1,6 @@
|
|
1
|
+
``,`772781978`,`BAD DEATH DAY`,``,`ANTHONY`,`GABRIEL`,`P`,`2009-03-10`,`2009-01-30`,`10`,``,``,`2009-04-23 13:59:45`,`2009-04-23 13:59:45`,`2009-11-30`
|
2
|
+
``,`772783025`,`BAD DEATH MONTH`,``,`JUAN`,``,`P`,``,`1910-11-01`,`10`,``,``,`2009-04-23 13:59:45`,`2009-04-23 13:59:45`,`2009-11-30`
|
3
|
+
``,`772786197`,`BAD BIRTH YEAR`,``,`ISAIAH`,``,`P`,`2009-02-02`,`0009-01-10`,``,``,``,`2009-04-23 13:59:45`,`2009-04-23 13:59:45`,`2009-11-30`
|
4
|
+
``,`772786123`,`QUOTED MIDDLE NAME`,``,`ISAIAH`,`'`,`P`,`2009-02-02`,`2009-01-10`,``,``,``,`2009-04-23 13:59:45`,`2009-04-23 13:59:45`,`2009-11-30`
|
5
|
+
``,`342786123`,`QUOTED'NAME`,``,`ISAIAH`,``,`P`,`2009-02-02`,`2009-01-10`,``,``,``,`2009-04-23 13:59:45`,`2009-04-23 13:59:45`,`2009-11-30`
|
6
|
+
``,`344566123`,`QUOTED NAME'`,``,`ISAIAH`,``,`P`,`2009-02-02`,`2009-01-10`,``,``,``,`2009-04-23 13:59:45`,`2009-04-23 13:59:45`,`2009-11-30`
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ssn_validator/models/death_master_file_loader'
|
2
|
+
|
3
|
+
class DeathMasterFileLoader
|
4
|
+
|
5
|
+
#Gives access to the private convert_file_to_csv method
|
6
|
+
def create_csv_file
|
7
|
+
convert_file_to_csv
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_file_from_web
|
11
|
+
case @file_path_or_url
|
12
|
+
when /MA\d\d\d\d\d\d/ #these are the valid urls I want to mock a response to.
|
13
|
+
first_upload = Date.today.beginning_of_month - 2.months #based on the test, we know we are loading the last 3 months
|
14
|
+
if @file_path_or_url =~ /MA#{first_upload.strftime("%y%m%d")}/
|
15
|
+
return ['A772783123UPDATED JUAN P030220091101191010']
|
16
|
+
elsif @file_path_or_url =~ /MA#{(first_upload + 1.month).strftime("%y%m%d")}/
|
17
|
+
return ['A772783456UPDATED JUAN P030220091101191010']
|
18
|
+
elsif @file_path_or_url =~ /MA#{(first_upload + 2.months).strftime("%y%m%d")}/
|
19
|
+
return ['A772783789UPDATED JUAN P030220091101191010']
|
20
|
+
end
|
21
|
+
else
|
22
|
+
uri = URI.parse(@file_path_or_url)
|
23
|
+
|
24
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
25
|
+
request.basic_auth(SsnValidator::Ntis.user_name,SsnValidator::Ntis.password)
|
26
|
+
|
27
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
+
http.use_ssl = (uri.port == 443)
|
29
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
|
+
|
31
|
+
response = http.request(request)
|
32
|
+
|
33
|
+
raise(ArgumentError, "Invalid URL: #{@file_path_or_url}") if response.kind_of?(Net::HTTPNotFound)
|
34
|
+
raise(ArgumentError, "Authorization Required: Invalid username or password. Set the variables SsnValidator::Ntis.user_name and SsnValidator::Ntis.password in your environment.rb file.") if response.kind_of?(Net::HTTPUnauthorized)
|
35
|
+
|
36
|
+
return response.body
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestDeathMasterFileLoader < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_death_master_file_table
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_validations_for_load_file
|
10
|
+
exception = assert_raise ArgumentError do
|
11
|
+
DeathMasterFileLoader.new(nil,nil)
|
12
|
+
end
|
13
|
+
assert_equal "path_or_url not specified", exception.message
|
14
|
+
|
15
|
+
exception = assert_raise ArgumentError do
|
16
|
+
DeathMasterFileLoader.new('some/path.txt',nil)
|
17
|
+
end
|
18
|
+
assert_equal "as_of not specified", exception.message
|
19
|
+
|
20
|
+
exception = assert_raise Errno::ENOENT do
|
21
|
+
DeathMasterFileLoader.new('some/path.txt','2009-01-01')
|
22
|
+
end
|
23
|
+
assert_equal "No such file or directory - some/path.txt", exception.message
|
24
|
+
|
25
|
+
exception = assert_raise URI::InvalidURIError do
|
26
|
+
DeathMasterFileLoader.new('https://dmf.bad_url.gov/dmldata/monthly/bad_url','2009-01-01')
|
27
|
+
end
|
28
|
+
assert_equal "the scheme https does not accept registry part: dmf.bad_url.gov (or bad hostname?)", exception.message
|
29
|
+
|
30
|
+
exception = assert_raise ArgumentError do
|
31
|
+
DeathMasterFileLoader.new('https://dmf.ntis.gov/bad_url','2009-01-01')
|
32
|
+
end
|
33
|
+
assert_equal "Invalid URL: https://dmf.ntis.gov/bad_url", exception.message
|
34
|
+
|
35
|
+
exception = assert_raise ArgumentError do
|
36
|
+
DeathMasterFileLoader.new('https://dmf.ntis.gov/dmldata/monthly/bad_url','2009-01-01')
|
37
|
+
end
|
38
|
+
assert_equal "Authorization Required: Invalid username or password. Set the variables SsnValidator::Ntis.user_name and SsnValidator::Ntis.password in your environment.rb file.", exception.message
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_load_table_from_file
|
42
|
+
assert_equal(0,DeathMasterFile.count)
|
43
|
+
DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_initial_load.txt','2009-01-01').load_file
|
44
|
+
assert DeathMasterFile.count == 5
|
45
|
+
|
46
|
+
#load update file
|
47
|
+
#update file adds 1 record, deletes 2 records, and changes 2 records
|
48
|
+
DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_update_load.txt','2009-02-01').load_file
|
49
|
+
assert DeathMasterFile.count == 4
|
50
|
+
assert 1, DeathMasterFile.count(:conditions => {:last_name => 'NEW'})
|
51
|
+
assert 2, DeathMasterFile.count(:conditions => {:last_name => 'CHANGED'})
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_not_load_table_if_as_of_already_in_table_for_load_file
|
55
|
+
DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_initial_load.txt','2009-01-01').load_file
|
56
|
+
assert DeathMasterFile.count > 0
|
57
|
+
record_count = DeathMasterFile.count
|
58
|
+
|
59
|
+
exception = assert_raise ArgumentError do
|
60
|
+
DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_update_load.txt','2008-01-01').load_file
|
61
|
+
end
|
62
|
+
assert_equal "A more recent file has already been processed. DB as_of date 2009-01-01", exception.message
|
63
|
+
|
64
|
+
assert_equal(record_count, DeathMasterFile.count)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_should_load_all_unloaded_updates
|
68
|
+
#initial load was 3 months ago
|
69
|
+
initial_run = Date.today.beginning_of_month - 3.months
|
70
|
+
DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_initial_load.txt',initial_run.strftime('%Y-%m-%d')).load_file
|
71
|
+
assert DeathMasterFile.count == 5
|
72
|
+
|
73
|
+
#this will load the last 3 months of files
|
74
|
+
#this has been mocked, not really hitting the web site for this
|
75
|
+
DeathMasterFileLoader.load_update_files_from_web
|
76
|
+
assert DeathMasterFile.count == 8
|
77
|
+
assert DeathMasterFile.find_by_as_of(initial_run.to_s(:db))
|
78
|
+
assert DeathMasterFile.find_by_as_of((initial_run += 1.month).to_s(:db))
|
79
|
+
assert DeathMasterFile.find_by_as_of((initial_run += 1.month).to_s(:db))
|
80
|
+
assert DeathMasterFile.find_by_as_of((initial_run += 1.month).to_s(:db))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_should_load_file_with_funky_data
|
84
|
+
DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_funky_data_load.txt','2009-04-01').load_file
|
85
|
+
assert DeathMasterFile.count == 6
|
86
|
+
DeathMasterFile.find(:all).each do |dmf|
|
87
|
+
# this is more of an issue with the bulk mysql load, but since, I'm using
|
88
|
+
#sqlight3 for it's in memory db, I can't test the mysql load.
|
89
|
+
assert_not_nil dmf.as_of
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_should_create_csv_file_for_mysql_import
|
94
|
+
#since, I'm using sqlight3 for it's in memory db, I can't test the mysql load
|
95
|
+
#but I can test the csv file creation.
|
96
|
+
loader = DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_funky_data_load.txt','2009-11-30')
|
97
|
+
csv = loader.create_csv_file #this method was created in the mock only to call the private convert_file_to_csv method
|
98
|
+
correctly_formatted_csv = File.open(File.dirname(__FILE__) + '/files/valid_csv_from_funky_data_file.txt')
|
99
|
+
#csv is open and at the end of the file, so we need to reopen it so we can read the lines.
|
100
|
+
generated_file = File.open(csv.path).readlines
|
101
|
+
#compare the values of each csv line, with the correctly formated "control file"
|
102
|
+
correctly_formatted_csv.each_with_index do |line,i|
|
103
|
+
csv_line = generated_file[i]
|
104
|
+
correctly_formatted_record_array = line.split(',')
|
105
|
+
csv_record_array = csv_line.split(',')
|
106
|
+
comparable_value_indices = (0..11).to_a << 14 #skip indices 12 and 13, they are the created_at and updated_at fields, they will never match.
|
107
|
+
comparable_value_indices.each do |i|
|
108
|
+
assert_equal correctly_formatted_record_array[i], csv_record_array[i]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'mocks/test/death_master_file_loader'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'ssn_validator'
|
8
|
+
|
9
|
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
10
|
+
|
11
|
+
|
12
|
+
def setup_high_group_codes_table
|
13
|
+
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
|
14
|
+
create_ssn_high_group_codes_table
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup_death_master_file_table
|
18
|
+
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
|
19
|
+
create_death_master_file_table
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def create_ssn_high_group_codes_table
|
25
|
+
silence_stream(STDOUT) do
|
26
|
+
ActiveRecord::Schema.define(:version => 1) do
|
27
|
+
create_table :ssn_high_group_codes do |t|
|
28
|
+
t.date :as_of
|
29
|
+
t.string :area
|
30
|
+
t.string :group
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
|
34
|
+
add_index :ssn_high_group_codes, [:area]
|
35
|
+
add_index :ssn_high_group_codes, [:area, :as_of]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_death_master_file_table
|
41
|
+
silence_stream(STDOUT) do
|
42
|
+
ActiveRecord::Schema.define(:version => 1) do
|
43
|
+
create_table :death_master_files do |t|
|
44
|
+
t.string :social_security_number
|
45
|
+
t.string :last_name
|
46
|
+
t.string :name_suffix
|
47
|
+
t.string :first_name
|
48
|
+
t.string :middle_name
|
49
|
+
t.string :verify_proof_code
|
50
|
+
t.date :date_of_death
|
51
|
+
t.date :date_of_birth
|
52
|
+
t.string :state_of_residence
|
53
|
+
t.string :last_known_zip_residence
|
54
|
+
t.string :last_known_zip_payment
|
55
|
+
t.timestamps
|
56
|
+
t.date :as_of
|
57
|
+
end
|
58
|
+
add_index :death_master_files, :social_security_number, :unique => true
|
59
|
+
add_index :death_master_files, :as_of
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestSsnHighGroupCodeLoader < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_high_group_codes_table
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_load_table_with_current_file
|
10
|
+
assert_equal(0,SsnHighGroupCode.count)
|
11
|
+
SsnHighGroupCodeLoader.load_current_high_group_codes_file
|
12
|
+
assert SsnHighGroupCode.count > 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_not_load_table_if_as_of_already_in_table
|
16
|
+
SsnHighGroupCodeLoader.load_current_high_group_codes_file
|
17
|
+
assert SsnHighGroupCode.count > 0
|
18
|
+
record_count = SsnHighGroupCode.count
|
19
|
+
SsnHighGroupCodeLoader.load_current_high_group_codes_file
|
20
|
+
assert_equal(record_count, SsnHighGroupCode.count)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestSsnValidator < Test::Unit::TestCase
|
4
|
+
|
5
|
+
KNOWN_DUMMY_SSNS = %w(078051120 111111111 123456789 219099999 999999999)
|
6
|
+
MISSPLACED_HYPHEN_SSNS = %w(1-2-3456789 12-345678-9 123-4-56789 123-456789 1234567-89 12-345-6789 12345-6789 1234-5-6789)
|
7
|
+
INVALID_LENGTH_SSNS = %w(1 12 123 1234 12345 123456 1234567 13245678 1234567890)
|
8
|
+
NONDIGIT_SSNS = %w(078051a20 078F51120 78051#20 051,20 078051m20)
|
9
|
+
INVALID_ZEROS_SSNS = %w(166-00-1234 073-96-0000)
|
10
|
+
GROUPS_NOT_ASSIGNED_TO_AREA_SSNS = %w(752991234 755971234 762991254)
|
11
|
+
AREA_NOT_ASSIGNED_SSNS = %w(666991234)
|
12
|
+
|
13
|
+
VALID_SSNS = %w(001021234 161-84-9876 223981111)
|
14
|
+
VALID_INTEGER_SSNS = [115941234, 161849876, 223981111]
|
15
|
+
|
16
|
+
def setup
|
17
|
+
setup_high_group_codes_table
|
18
|
+
SsnHighGroupCodeLoader.load_current_high_group_codes_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_ssn_validations
|
22
|
+
KNOWN_DUMMY_SSNS.each do |ssn|
|
23
|
+
validator = SsnValidator::Ssn.new(ssn)
|
24
|
+
assert !validator.valid?
|
25
|
+
assert validator.errors.include?('Known dummy SSN.'), "Errors: #{validator.errors}"
|
26
|
+
end
|
27
|
+
|
28
|
+
MISSPLACED_HYPHEN_SSNS.each do |ssn|
|
29
|
+
validator = SsnValidator::Ssn.new(ssn)
|
30
|
+
assert !validator.valid?
|
31
|
+
assert validator.errors.include?('Hyphen misplaced.'), "Errors: #{validator.errors}"
|
32
|
+
end
|
33
|
+
|
34
|
+
INVALID_LENGTH_SSNS.each do |ssn|
|
35
|
+
validator = SsnValidator::Ssn.new(ssn)
|
36
|
+
assert !validator.valid?
|
37
|
+
assert validator.errors.include?('SSN not 9 digits long.'), "Errors: #{validator.errors}"
|
38
|
+
end
|
39
|
+
|
40
|
+
NONDIGIT_SSNS.each do |ssn|
|
41
|
+
validator = SsnValidator::Ssn.new(ssn)
|
42
|
+
assert !validator.valid?
|
43
|
+
assert validator.errors.include?('Non-digit found.'), "Errors: #{validator.errors}"
|
44
|
+
end
|
45
|
+
|
46
|
+
INVALID_ZEROS_SSNS.each do |ssn|
|
47
|
+
validator = SsnValidator::Ssn.new(ssn)
|
48
|
+
assert !validator.valid?
|
49
|
+
assert validator.errors.include?('Invalid group or serial number.'), "Errors: #{validator.errors}"
|
50
|
+
end
|
51
|
+
|
52
|
+
AREA_NOT_ASSIGNED_SSNS.each do |ssn|
|
53
|
+
validator = SsnValidator::Ssn.new(ssn)
|
54
|
+
assert !validator.valid?
|
55
|
+
assert validator.errors.include?("Area '#{validator.area}' has not been assigned."), "Errors: #{validator.errors}"
|
56
|
+
end
|
57
|
+
|
58
|
+
GROUPS_NOT_ASSIGNED_TO_AREA_SSNS.each do |ssn|
|
59
|
+
validator = SsnValidator::Ssn.new(ssn)
|
60
|
+
assert !validator.valid?
|
61
|
+
assert validator.errors.include?("Group '#{validator.group}' has not been assigned yet for area '#{validator.area}'"), "Errors: #{validator.errors}"
|
62
|
+
end
|
63
|
+
|
64
|
+
(VALID_SSNS + VALID_INTEGER_SSNS).each do |ssn|
|
65
|
+
validator = SsnValidator::Ssn.new(ssn)
|
66
|
+
assert validator.valid?, "Errors: #{validator.errors}"
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_death_master_file_hit
|
73
|
+
create_death_master_file_table
|
74
|
+
DeathMasterFileLoader.new(File.dirname(__FILE__) + '/files/test_dmf_initial_load.txt','2009-01-01').load_file
|
75
|
+
|
76
|
+
validator = SsnValidator::Ssn.new('772781978')#ssn from file
|
77
|
+
assert DeathMasterFile, validator.death_master_file_record.class
|
78
|
+
assert validator.death_master_file_hit?
|
79
|
+
|
80
|
+
validator = SsnValidator::Ssn.new('666781978')#ssn not in file
|
81
|
+
assert_nil validator.death_master_file_record
|
82
|
+
assert !validator.death_master_file_hit?
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|