rsmart_toolbox 0.1

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.
@@ -0,0 +1,19 @@
1
+ # rSmart client library and command-line tool to help interact with rSmart's cloud APIs.
2
+ # Copyright (C) 2014 The rSmart Group, Inc.
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Affero General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU Affero General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU Affero General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module RsmartToolbox
18
+ VERSION = "0.1"
19
+ end
@@ -0,0 +1,43 @@
1
+ # rSmart client library and command-line tool to help interact with rSmart's cloud APIs.
2
+ # Copyright (C) 2014 The rSmart Group, Inc.
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Affero General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU Affero General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU Affero General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ # coding: utf-8
18
+ lib = File.expand_path('../lib', __FILE__)
19
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
+ require 'rsmart_toolbox/version'
21
+
22
+ Gem::Specification.new do |spec|
23
+ spec.name = "rsmart_toolbox"
24
+ spec.version = RsmartToolbox::VERSION
25
+ spec.authors = ["Lance Speelmon"]
26
+ spec.email = ["lspeelmon@rsmart.com"]
27
+ spec.summary = %q{Client library and command-line tool to help interact with rSmart's cloud APIs.}
28
+ # spec.description = %q{TODO: Write a longer description. Optional.}
29
+ spec.homepage = "https://github.com/rSmart/rsmart_toolbox"
30
+ spec.metadata = { "issue_tracker" => "https://github.com/rSmart/rsmart_toolbox/issues" }
31
+ spec.license = "AGPL-3.0"
32
+
33
+ spec.files = `git ls-files -z`.split("\x0")
34
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
35
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.required_ruby_version = '>= 1.9'
39
+ spec.add_development_dependency "bundler", "~> 1.6"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "simplecov"
43
+ end
@@ -0,0 +1,620 @@
1
+ # rSmart client library and command-line tool to help interact with rSmart's cloud APIs.
2
+ # Copyright (C) 2014 The rSmart Group, Inc.
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Affero General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU Affero General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU Affero General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'spec_helper'
18
+ require 'rsmart_toolbox/etl/grm'
19
+
20
+ GRM = RsmartToolbox::ETL::GRM
21
+ TextParseError = RsmartToolbox::ETL::TextParseError
22
+
23
+ RSpec.describe "RsmartToolbox::ETL::GRM" do
24
+
25
+ describe "#parse_rolodex_id!" do
26
+ # `ROLODEX_ID` decimal(6,0) NOT NULL DEFAULT '0',
27
+
28
+ it "Modifies the insert_str and values_str based on a CSV::Row match" do
29
+ insert_str = ""; values_str = "";
30
+ row = CSV::Row.new(['rolodex_id'.to_sym], ['123456'], true)
31
+ GRM.parse_rolodex_id!(row, insert_str, values_str)
32
+ expect(insert_str).to eq("ROLODEX_ID,")
33
+ expect(values_str).to eq("123456,")
34
+
35
+ insert_str = ""; values_str = "";
36
+ row = CSV::Row.new(['rolodex_id'.to_sym], ['000001'], true)
37
+ GRM.parse_rolodex_id!(row, insert_str, values_str)
38
+ expect(insert_str).to eq("ROLODEX_ID,")
39
+ expect(values_str).to eq("1,")
40
+ end
41
+
42
+ it "Raises an TextParseError if nil or empty" do
43
+ insert_str = ""; values_str = "";
44
+ row = CSV::Row.new(['rolodex_id'.to_sym], [nil], true)
45
+ expect { GRM.parse_rolodex_id!(row, insert_str, values_str) }.to raise_error(TextParseError)
46
+ row = CSV::Row.new(['rolodex_id'.to_sym], [''], true)
47
+ expect { GRM.parse_rolodex_id!(row, insert_str, values_str) }.to raise_error(TextParseError)
48
+ end
49
+
50
+ it "Raises an TextParseError if length exceeds 6 characters" do
51
+ insert_str = ""; values_str = "";
52
+ row = CSV::Row.new(['rolodex_id'.to_sym], ['1234567'], true)
53
+ expect { GRM.parse_rolodex_id!(row, insert_str, values_str) }.to raise_error(TextParseError)
54
+ end
55
+ end
56
+
57
+ describe "#parse_country_code!" do
58
+ it "Modifies the insert_str and values_str based on a CSV::Row match" do
59
+ insert_str = ""; values_str = "";
60
+ row = CSV::Row.new(['country_code'.to_sym], ['USA'], true)
61
+ GRM.parse_country_code!(row, insert_str, values_str)
62
+ expect(insert_str).to eq("COUNTRY_CODE,")
63
+ expect(values_str).to eq("'USA',")
64
+ end
65
+
66
+ it "Does not raise an TextParseError if nil or empty" do
67
+ insert_str = ""; values_str = "";
68
+ row = CSV::Row.new(['country_code'.to_sym], [nil], true)
69
+ expect { GRM.parse_country_code!(row, insert_str, values_str) }.not_to raise_error
70
+ row = CSV::Row.new(['country_code'.to_sym], [''], true)
71
+ expect { GRM.parse_country_code!(row, insert_str, values_str) }.not_to raise_error
72
+ end
73
+
74
+ it "Raises an TextParseError if length exceeds 4 characters" do
75
+ insert_str = ""; values_str = "";
76
+ row = CSV::Row.new(['country_code'.to_sym], ['FOUR'], true)
77
+ expect { GRM.parse_country_code!(row, insert_str, values_str) }.to raise_error(TextParseError)
78
+ end
79
+ end
80
+
81
+ describe "#parse_state!" do
82
+ it "Modifies the insert_str and values_str based on a CSV::Row match" do
83
+ insert_str = ""; values_str = "";
84
+ row = CSV::Row.new(['state'.to_sym], ['Arizona'], true)
85
+ GRM.parse_state!(row, insert_str, values_str)
86
+ expect(insert_str).to eq("STATE,")
87
+ expect(values_str).to eq("'Arizona',")
88
+ end
89
+
90
+ it "Does not raise an TextParseError if nil or empty" do
91
+ insert_str = ""; values_str = "";
92
+ row = CSV::Row.new(['state'.to_sym], [nil], true)
93
+ expect { GRM.parse_state!(row, insert_str, values_str) }.not_to raise_error
94
+ row = CSV::Row.new(['state'.to_sym], [''], true)
95
+ expect { GRM.parse_state!(row, insert_str, values_str) }.not_to raise_error
96
+ end
97
+
98
+ it "Raises an TextParseError if length exceeds 30 characters" do
99
+ insert_str = ""; values_str = "";
100
+ row = CSV::Row.new(['state'.to_sym], ["x" * 31], true)
101
+ expect { GRM.parse_state!(row, insert_str, values_str) }.to raise_error(TextParseError)
102
+ end
103
+ end
104
+
105
+ describe "#parse_sponsor_code!" do
106
+ it "Modifies the insert_str and values_str based on a CSV::Row match" do
107
+ insert_str = ""; values_str = "";
108
+ row = CSV::Row.new(['sponsor_code'.to_sym], ['000001'], true)
109
+ GRM.parse_sponsor_code!(row, insert_str, values_str)
110
+ expect(insert_str).to eq("SPONSOR_CODE,")
111
+ expect(values_str).to eq("'000001',")
112
+ end
113
+
114
+ it "Raises an TextParseError if nil or empty" do
115
+ insert_str = ""; values_str = "";
116
+ row = CSV::Row.new(['sponsor_code'.to_sym], [nil], true)
117
+ expect { GRM.parse_sponsor_code!(row, insert_str, values_str) }.to raise_error(TextParseError)
118
+ row = CSV::Row.new(['sponsor_code'.to_sym], [""], true)
119
+ expect { GRM.parse_sponsor_code!(row, insert_str, values_str) }.to raise_error(TextParseError)
120
+ end
121
+
122
+ it "Raises an TextParseError if length exceeds 6 characters" do
123
+ insert_str = ""; values_str = "";
124
+ row = CSV::Row.new(['sponsor_code'.to_sym], ["x" * 7], true)
125
+ expect { GRM.parse_sponsor_code!(row, insert_str, values_str) }.to raise_error(TextParseError)
126
+ end
127
+ end
128
+
129
+ describe "#parse_postal_code!" do
130
+ it "Modifies the insert_str and values_str based on a CSV::Row match" do
131
+ insert_str = ""; values_str = "";
132
+ row = CSV::Row.new(['postal_code'.to_sym], ['12345-7890'], true)
133
+ GRM.parse_postal_code!(row, insert_str, values_str)
134
+ expect(insert_str).to eq("POSTAL_CODE,")
135
+ expect(values_str).to eq("'12345-7890',")
136
+ end
137
+
138
+ it "Does not raise an TextParseError if nil or empty" do
139
+ insert_str = ""; values_str = "";
140
+ row = CSV::Row.new(['postal_code'.to_sym], [nil], true)
141
+ expect { GRM.parse_postal_code!(row, insert_str, values_str) }.not_to raise_error
142
+ row = CSV::Row.new(['postal_code'.to_sym], [''], true)
143
+ expect { GRM.parse_postal_code!(row, insert_str, values_str) }.not_to raise_error
144
+ end
145
+
146
+ it "Raises an TextParseError if length exceeds 15 characters" do
147
+ insert_str = ""; values_str = "";
148
+ row = CSV::Row.new(['postal_code'.to_sym], ["x" * 16], true)
149
+ expect { GRM.parse_postal_code!(row, insert_str, values_str) }.to raise_error(TextParseError)
150
+ end
151
+ end
152
+
153
+ describe "#parse_owned_by_unit!" do
154
+ it "Modifies the insert_str and values_str based on a CSV::Row match" do
155
+ insert_str = ""; values_str = "";
156
+ row = CSV::Row.new(['owned_by_unit'.to_sym], ['000001'], true)
157
+ GRM.parse_owned_by_unit!(row, insert_str, values_str)
158
+ expect(insert_str).to eq("OWNED_BY_UNIT,")
159
+ expect(values_str).to eq("'000001',")
160
+ end
161
+
162
+ it "Raises an TextParseError if nil or empty" do
163
+ insert_str = ""; values_str = "";
164
+ row = CSV::Row.new(['owned_by_unit'.to_sym], [nil], true)
165
+ expect { GRM.parse_owned_by_unit!(row, insert_str, values_str) }.to raise_error(TextParseError)
166
+ row = CSV::Row.new(['owned_by_unit'.to_sym], [''], true)
167
+ expect { GRM.parse_owned_by_unit!(row, insert_str, values_str) }.to raise_error(TextParseError)
168
+ end
169
+
170
+ it "Raises an TextParseError if length exceeds 8 characters" do
171
+ insert_str = ""; values_str = "";
172
+ row = CSV::Row.new(['owned_by_unit'.to_sym], ["x" * 9], true)
173
+ expect { GRM.parse_owned_by_unit!(row, insert_str, values_str) }.to raise_error(TextParseError)
174
+ end
175
+ end
176
+
177
+ describe "#parse_email_address!" do
178
+ it "Modifies the insert_str and values_str based on a CSV::Row match" do
179
+ insert_str = ""; values_str = "";
180
+ row = CSV::Row.new(['email_address'.to_sym], ['lance@rsmart.com'], true)
181
+ GRM.parse_email_address!(row, insert_str, values_str)
182
+ expect(insert_str).to eq("EMAIL_ADDRESS,")
183
+ expect(values_str).to eq("'lance@rsmart.com',")
184
+ end
185
+
186
+ it "Does not raise an TextParseError if nil or empty" do
187
+ insert_str = ""; values_str = "";
188
+ row = CSV::Row.new(['email_address'.to_sym], [nil], true)
189
+ expect { GRM.parse_email_address!(row, insert_str, values_str) }.not_to raise_error
190
+ row = CSV::Row.new(['email_address'.to_sym], [''], true)
191
+ expect { GRM.parse_email_address!(row, insert_str, values_str) }.not_to raise_error
192
+ end
193
+
194
+ it "Raises an TextParseError if length exceeds 60 characters" do
195
+ insert_str = ""; values_str = "";
196
+ valid_sixty_one_char_email_address = "abcedefghijksdhfksjfdsdfsdfsdfsdhsjkhdf@abcdesfsdfsdfsdff.com"
197
+ row = CSV::Row.new(['email_address'.to_sym], [valid_sixty_one_char_email_address], true)
198
+ expect { GRM.parse_email_address!(row, insert_str, values_str) }.to raise_error(TextParseError)
199
+ end
200
+
201
+ it "Raises an TextParseError if it does not match the official RFC email address specifications" do
202
+ insert_str = ""; values_str = "";
203
+ row = CSV::Row.new(['email_address'.to_sym], ["foo"], true)
204
+ expect { GRM.parse_email_address!(row, insert_str, values_str) }.to raise_error(TextParseError)
205
+ row = CSV::Row.new(['email_address'.to_sym], ["foo@bar"], true)
206
+ expect { GRM.parse_email_address!(row, insert_str, values_str) }.to raise_error(TextParseError)
207
+ row = CSV::Row.new(['email_address'.to_sym], ["foo@bar."], true)
208
+ expect { GRM.parse_email_address!(row, insert_str, values_str) }.to raise_error(TextParseError)
209
+ end
210
+ end
211
+
212
+ describe "#parse_principal_id" do
213
+ it "parses a principal_id from a String" do
214
+ expect(GRM.parse_principal_id("ABCD1234")).to eq("ABCD1234")
215
+ end
216
+
217
+ it "raises an TextParseError if the principal_id is nil or empty" do
218
+ expect { GRM.parse_principal_id(nil) }.to raise_error(TextParseError)
219
+ expect { GRM.parse_principal_id("") }.to raise_error(TextParseError)
220
+ end
221
+
222
+ it "raises an TextParseError if length exceeds 40 characters" do
223
+ expect { GRM.parse_principal_id("x" * 41) }.to raise_error(TextParseError)
224
+ end
225
+ end
226
+
227
+ describe "#parse_principal_name" do
228
+ it "parses a principal_nm from a String" do
229
+ expect(GRM.parse_principal_name("lspeelmon")).to eq("lspeelmon")
230
+ end
231
+
232
+ it "raises an TextParseError if the principal_nm is nil or empty" do
233
+ expect { GRM.parse_principal_name(nil) }.to raise_error(TextParseError)
234
+ expect { GRM.parse_principal_name("") }.to raise_error(TextParseError)
235
+ end
236
+
237
+ it "raises an TextParseError if the principal_nm contains illegal characters" do
238
+ expect { GRM.parse_principal_name("~!#$%^&*()+=") }.to raise_error(TextParseError)
239
+ expect { GRM.parse_principal_name("LANCE@UPPERCASE.COM") }.to raise_error(TextParseError)
240
+ end
241
+
242
+ it "raises an TextParseError if length exceeds 100 characters" do
243
+ expect { GRM.parse_principal_name("x" * 101) }.to raise_error(TextParseError)
244
+ end
245
+ end
246
+
247
+ describe "#parse_emp_stat_cd" do
248
+ # <xs:maxLength value="1"/>
249
+ # <xs:pattern value="A|D|L|N|P|R|S|T"/>
250
+ valid_values = ['A', 'D', 'L', 'N', 'P', 'R', 'S', 'T']
251
+
252
+ it "parses a emp_stat_cd from a String" do
253
+ valid_values.each do |valid_value|
254
+ expect(GRM.parse_emp_stat_cd(valid_value)).to eq(valid_value)
255
+ end
256
+ end
257
+
258
+ it "allows for lowercase input Strings" do
259
+ valid_values.each do |valid_value|
260
+ expect(GRM.parse_emp_stat_cd(valid_value.downcase)).to eq(valid_value)
261
+ end
262
+ end
263
+
264
+ it "allows for mixed case input Strings" do
265
+ valid_values.each do |valid_value|
266
+ expect(GRM.parse_emp_stat_cd(valid_value.capitalize)).to eq(valid_value)
267
+ end
268
+ end
269
+
270
+ it "raises an TextParseError if the emp_typ_cd is not a valid value" do
271
+ expect { GRM.parse_emp_stat_cd("Z") }.to raise_error(TextParseError)
272
+ end
273
+
274
+ it "raises an TextParseError if the emp_stat_cd is nil or empty" do
275
+ expect { GRM.parse_emp_stat_cd(nil) }.to raise_error(TextParseError)
276
+ expect { GRM.parse_emp_stat_cd("") }.to raise_error(TextParseError)
277
+ end
278
+
279
+ it "raises an TextParseError if length exceeds 40 characters" do
280
+ expect { GRM.parse_emp_stat_cd("A" * 41) }.to raise_error(TextParseError)
281
+ end
282
+ end
283
+
284
+ describe "#parse_emp_typ_cd" do
285
+ # <xs:pattern value="N|O|P"/>
286
+ valid_values = ['N', 'O', 'P']
287
+
288
+ it "parses a emp_typ_cd from a String" do
289
+ valid_values.each do |valid_value|
290
+ expect(GRM.parse_emp_typ_cd(valid_value)).to eq(valid_value)
291
+ end
292
+ end
293
+
294
+ it "allows for lowercase input Strings" do
295
+ valid_values.each do |valid_value|
296
+ expect(GRM.parse_emp_typ_cd(valid_value.downcase)).to eq(valid_value)
297
+ end
298
+ end
299
+
300
+ it "allows for mixed case input Strings" do
301
+ valid_values.each do |valid_value|
302
+ expect(GRM.parse_emp_typ_cd(valid_value.capitalize)).to eq(valid_value)
303
+ end
304
+ end
305
+
306
+ it "raises an TextParseError if the emp_typ_cd is not a valid value" do
307
+ expect { GRM.parse_emp_typ_cd("Z") }.to raise_error(TextParseError)
308
+ end
309
+
310
+ it "raises an TextParseError if the emp_typ_cd is nil or empty" do
311
+ expect { GRM.parse_emp_typ_cd(nil) }.to raise_error(TextParseError)
312
+ expect { GRM.parse_emp_typ_cd("") }.to raise_error(TextParseError)
313
+ end
314
+
315
+ # <xs:maxLength value="1"/>
316
+ it "raises an TextParseError if length exceeds 1 character" do
317
+ expect { GRM.parse_emp_typ_cd("NN") }.to raise_error(TextParseError)
318
+ end
319
+ end
320
+
321
+ describe "#parse_address_type_code" do
322
+ # <xs:pattern value="HM|OTH|WRK"/>
323
+ valid_values = ['HM', 'OTH', 'WRK']
324
+
325
+ it "parses all valid address_type_code from a String" do
326
+ valid_values.each do |valid_value|
327
+ expect(GRM.parse_address_type_code(valid_value)).to eq(valid_value)
328
+ end
329
+ end
330
+
331
+ it "allows for lowercase input Strings" do
332
+ valid_values.each do |valid_value|
333
+ expect(GRM.parse_address_type_code(valid_value.downcase)).to eq(valid_value)
334
+ end
335
+ end
336
+
337
+ it "allows for mixed case input Strings" do
338
+ valid_values.each do |valid_value|
339
+ expect(GRM.parse_address_type_code(valid_value.capitalize)).to eq(valid_value)
340
+ end
341
+ end
342
+
343
+ it "raises an TextParseError if the address_type_code is not a valid value" do
344
+ expect { GRM.parse_address_type_code("Z") }.to raise_error(TextParseError)
345
+ end
346
+
347
+ it "raises an TextParseError if the address_type_code is nil or empty" do
348
+ expect { GRM.parse_address_type_code(nil) }.to raise_error(TextParseError)
349
+ expect { GRM.parse_address_type_code("") }.to raise_error(TextParseError)
350
+ end
351
+
352
+ # <xs:maxLength value="3"/>
353
+ it "raises an TextParseError if length exceeds 3 characters" do
354
+ expect { GRM.parse_address_type_code("HOME") }.to raise_error(TextParseError)
355
+ end
356
+ end
357
+
358
+ describe "#parse_name_code" do
359
+ # <xs:pattern value="OTH|PRFR|PRM"/>
360
+ valid_values = ['OTH', 'PRFR', 'PRM']
361
+
362
+ it "parses a name_code from a String" do
363
+ valid_values.each do |valid_value|
364
+ expect(GRM.parse_name_code(valid_value)).to eq(valid_value)
365
+ end
366
+ end
367
+
368
+ it "allows for lowercase input Strings" do
369
+ valid_values.each do |valid_value|
370
+ expect(GRM.parse_name_code(valid_value.downcase)).to eq(valid_value)
371
+ end
372
+ end
373
+
374
+ it "allows for mixed case input Strings" do
375
+ valid_values.each do |valid_value|
376
+ expect(GRM.parse_name_code(valid_value.capitalize)).to eq(valid_value)
377
+ end
378
+ end
379
+
380
+ it "raises an TextParseError if the name_code is not a valid value" do
381
+ expect { GRM.parse_name_code("Z") }.to raise_error(TextParseError)
382
+ end
383
+
384
+ it "raises an TextParseError if the name_code is nil or empty" do
385
+ expect { GRM.parse_name_code(nil) }.to raise_error(TextParseError)
386
+ expect { GRM.parse_name_code("") }.to raise_error(TextParseError)
387
+ end
388
+
389
+ # <xs:maxLength value="4"/>
390
+ it "raises an TextParseError if length exceeds 4 characters" do
391
+ expect { GRM.parse_name_code("OTHER") }.to raise_error(TextParseError)
392
+ end
393
+ end
394
+
395
+ describe "#parse_prefix" do
396
+ # <xs:pattern value="(Ms|Mrs|Mr|Dr)?"/>
397
+ valid_values = ['Ms', 'Mrs', 'Mr', 'Dr']
398
+
399
+ it "parses all valid prefix from a String" do
400
+ valid_values.each do |valid_value|
401
+ expect(GRM.parse_prefix(valid_value)).to eq(valid_value)
402
+ end
403
+ end
404
+
405
+ it "does NOT raise an TextParseError if the prefix is nil or empty" do
406
+ expect { GRM.parse_prefix(nil) }.not_to raise_error
407
+ expect { GRM.parse_prefix("") }.not_to raise_error
408
+ expect(GRM.parse_prefix("")).to eq("")
409
+ end
410
+
411
+ it "raises an TextParseError if the prefix is not a valid value" do
412
+ expect { GRM.parse_prefix("Z") }.to raise_error(TextParseError)
413
+ end
414
+
415
+ # <xs:maxLength value="3"/>
416
+ it "raises an TextParseError if length exceeds 3 characters" do
417
+ expect { GRM.parse_prefix("Miss") }.to raise_error(TextParseError)
418
+ end
419
+ end
420
+
421
+ describe "#parse_suffix" do
422
+ # <xs:pattern value="(Jr|Sr|Mr|Md)?"/>
423
+ valid_values = ['Jr', 'Sr', 'Mr', 'Md']
424
+
425
+ it "parses a suffix from a String" do
426
+ valid_values.each do |valid_value|
427
+ expect(GRM.parse_suffix(valid_value)).to eq(valid_value)
428
+ end
429
+ end
430
+
431
+ it "does NOT raise an TextParseError if the suffix is nil or empty" do
432
+ expect { GRM.parse_suffix(nil) }.not_to raise_error
433
+ expect { GRM.parse_suffix("") }.not_to raise_error
434
+ expect(GRM.parse_suffix("")).to eq("")
435
+ end
436
+
437
+ it "raises an TextParseError if the suffix is not a valid value" do
438
+ expect { GRM.parse_suffix("Z") }.to raise_error(TextParseError)
439
+ end
440
+
441
+ # <xs:maxLength value="2"/>
442
+ it "raises an TextParseError if length exceeds 2 characters" do
443
+ expect { GRM.parse_suffix("Jrr") }.to raise_error(TextParseError)
444
+ end
445
+ end
446
+
447
+ describe "#parse_phone_type" do
448
+ # <xs:pattern value="FAX|HM|MBL|OTH|WRK"/>
449
+ valid_values = ['FAX', 'HM', 'MBL', 'OTH', 'WRK']
450
+
451
+ it "parses a phone_type from a String" do
452
+ valid_values.each do |valid_value|
453
+ expect(GRM.parse_phone_type(valid_value)).to eq(valid_value)
454
+ end
455
+ end
456
+
457
+ it "allows for lowercase input Strings" do
458
+ valid_values.each do |valid_value|
459
+ expect(GRM.parse_phone_type(valid_value.downcase)).to eq(valid_value)
460
+ end
461
+ end
462
+
463
+ it "allows for mixed case input Strings" do
464
+ valid_values.each do |valid_value|
465
+ expect(GRM.parse_phone_type(valid_value.capitalize)).to eq(valid_value)
466
+ end
467
+ end
468
+
469
+ it "raises an TextParseError if the phone_type is not a valid value" do
470
+ expect { GRM.parse_phone_type("Z") }.to raise_error(TextParseError)
471
+ end
472
+
473
+ it "raises an TextParseError if the phone_type is nil or empty" do
474
+ expect { GRM.parse_phone_type(nil) }.to raise_error(TextParseError)
475
+ expect { GRM.parse_phone_type("") }.to raise_error(TextParseError)
476
+ end
477
+
478
+ # <xs:maxLength value="3"/>
479
+ it "raises an TextParseError if length exceeds 3 characters" do
480
+ expect { GRM.parse_phone_type("HOME") }.to raise_error(TextParseError)
481
+ end
482
+ end
483
+
484
+ describe "#parse_phone_number" do
485
+ it "parses a phone_number from a String" do
486
+ # <xs:pattern value="\d{3}-\d{3}-\d{4}"/>
487
+ expect(GRM.parse_phone_number("800-555-1212")).to eq("800-555-1212")
488
+ expect(GRM.parse_phone_number("480-123-4567")).to eq("480-123-4567")
489
+ end
490
+
491
+ it "raises an TextParseError if the phone_number is not a valid value" do
492
+ expect { GRM.parse_phone_number("80-555-1212") }.to raise_error(TextParseError)
493
+ expect { GRM.parse_phone_number("800-55-1212") }.to raise_error(TextParseError)
494
+ expect { GRM.parse_phone_number("800-555-121") }.to raise_error(TextParseError)
495
+ expect { GRM.parse_phone_number("800-555-121") }.to raise_error(TextParseError)
496
+ expect { GRM.parse_phone_number("800") }.to raise_error(TextParseError)
497
+ expect { GRM.parse_phone_number("555-121") }.to raise_error(TextParseError)
498
+ expect { GRM.parse_phone_number("Z") }.to raise_error(TextParseError)
499
+ end
500
+
501
+ it "does NOT raise an TextParseError if the suffix is nil or empty" do
502
+ expect { GRM.parse_phone_number(nil) }.not_to raise_error
503
+ expect { GRM.parse_phone_number("") }.not_to raise_error
504
+ expect(GRM.parse_phone_number("")).to eq("")
505
+ end
506
+
507
+ it "raises an TextParseError if length exceeds 12 characters" do
508
+ expect { GRM.parse_suffix("123-456-78901") }.to raise_error(TextParseError)
509
+ end
510
+ end
511
+
512
+ describe "#parse_email_type" do
513
+ # <xs:pattern value="HM|OTH|WRK"/>
514
+ valid_values = ['HM', 'OTH', 'WRK']
515
+
516
+ it "parses a email_type from a String" do
517
+ valid_values.each do |valid_value|
518
+ expect(GRM.parse_email_type(valid_value)).to eq(valid_value)
519
+ end
520
+ end
521
+
522
+ it "allows for lowercase input Strings" do
523
+ valid_values.each do |valid_value|
524
+ expect(GRM.parse_email_type(valid_value.downcase)).to eq(valid_value)
525
+ end
526
+ end
527
+
528
+ it "allows for mixed case input Strings" do
529
+ valid_values.each do |valid_value|
530
+ expect(GRM.parse_email_type(valid_value.capitalize)).to eq(valid_value)
531
+ end
532
+ end
533
+
534
+ it "raises an TextParseError if the email_type is not a valid value" do
535
+ expect { GRM.parse_email_type("Z") }.to raise_error(TextParseError)
536
+ end
537
+
538
+ it "raises an TextParseError if the email_type is nil or empty" do
539
+ expect { GRM.parse_email_type(nil) }.to raise_error(TextParseError)
540
+ expect { GRM.parse_email_type("") }.to raise_error(TextParseError)
541
+ end
542
+
543
+ # <xs:maxLength value="3"/>
544
+ it "raises an TextParseError if length exceeds 3 characters" do
545
+ expect { GRM.parse_email_type("HOME") }.to raise_error(TextParseError)
546
+ end
547
+ end
548
+
549
+ describe "#parse_year" do
550
+ it "parses a year from a String" do
551
+ expect(GRM.parse_year("1999")).to eq("1999")
552
+ expect(GRM.parse_year("2000")).to eq("2000")
553
+ expect(GRM.parse_year("9999")).to eq("9999")
554
+ end
555
+
556
+ it "does NOT raise an TextParseError if the year is nil or empty" do
557
+ expect { GRM.parse_year(nil) }.not_to raise_error
558
+ expect { GRM.parse_year("") }.not_to raise_error
559
+ expect(GRM.parse_year("")).to eq("")
560
+ end
561
+
562
+ it "raises an TextParseError if year begins before 1000 CE" do
563
+ expect { GRM.parse_year("0") }.to raise_error(TextParseError)
564
+ expect { GRM.parse_year("1") }.to raise_error(TextParseError)
565
+ expect { GRM.parse_year("99") }.to raise_error(TextParseError)
566
+ expect { GRM.parse_year("999") }.to raise_error(TextParseError)
567
+ end
568
+
569
+ it "raises an TextParseError if length exceeds 4 characters" do
570
+ expect { GRM.parse_year("10000") }.to raise_error(TextParseError)
571
+ end
572
+ end
573
+
574
+ describe "#parse_citizenship_type" do
575
+ valid_values = ['1', '2', '3', '4']
576
+
577
+ it "parses a citizenship_type from a String" do
578
+ valid_values.each do |valid_value|
579
+ expect(GRM.parse_citizenship_type(valid_value)).to eq(valid_value)
580
+ end
581
+ end
582
+
583
+ it "raises an TextParseError if the citizenship_type is not a valid value" do
584
+ expect { GRM.parse_citizenship_type("0") }.to raise_error(TextParseError)
585
+ expect { GRM.parse_citizenship_type("5") }.to raise_error(TextParseError)
586
+ expect { GRM.parse_citizenship_type("Z") }.to raise_error(TextParseError)
587
+ end
588
+
589
+ it "raises an TextParseError if the citizenship_type is nil or empty" do
590
+ expect { GRM.parse_citizenship_type(nil) }.to raise_error(TextParseError)
591
+ expect { GRM.parse_citizenship_type("") }.to raise_error(TextParseError)
592
+ end
593
+
594
+ it "raises an TextParseError if length exceeds 1 character" do
595
+ expect { GRM.parse_citizenship_type("22") }.to raise_error(TextParseError)
596
+ end
597
+ end
598
+
599
+ describe "#parse_degree" do
600
+ # <xs:pattern value="AS|BA|BComm|BEd|BS|DA|DC|DD|DDS|DEng|DFA|DH|DHA|DMin|DPA|DSN|DVM|DVS|HS|JD|LLD|LLM|MA|MAEd|
601
+ # MArch|MBA|MD|MDS|MDiv|MEE|MEd|MEng|MFA|MIS|MLS|MPA|MPE|MPH|MPd|MPhil|MS|MSEd|MST|MSW|MTh|PhD|PharD|ScD|ThD|UKNW"/>
602
+ it "parses all valid degree_code Strings" do
603
+ valid_values = ['AS','BA','BComm','BEd','BS','DA','DC','DD','DDS','DEng','DFA','DH','DHA','DMin','DPA','DSN','DVM','DVS','HS','JD','LLD','LLM','MA','MAEd','MArch','MBA','MD','MDS','MDiv','MEE','MEd','MEng','MFA','MIS','MLS','MPA','MPE','MPH','MPd','MPhil','MS','MSEd','MST','MSW','MTh','PhD','PharD','ScD','ThD','UKNW']
604
+ valid_values.each do |valid_value|
605
+ expect(GRM.parse_degree(valid_value)).to eq(valid_value)
606
+ end
607
+ end
608
+
609
+ it "does NOT raise an TextParseError if the degree_code is nil or empty" do
610
+ expect { GRM.parse_degree(nil) }.not_to raise_error
611
+ expect { GRM.parse_degree("") }.not_to raise_error
612
+ expect(GRM.parse_degree("")).to eq("")
613
+ end
614
+
615
+ it "raises an TextParseError if the degree_code is not a valid value" do
616
+ expect { GRM.parse_degree("Foo") }.to raise_error(TextParseError)
617
+ end
618
+ end
619
+
620
+ end