bonnie_bundler 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +29 -0
  5. data/Gemfile.lock +267 -0
  6. data/README.md +4 -0
  7. data/Rakefile +29 -0
  8. data/bonnie-bundler.gemspec +29 -0
  9. data/config/initializers/mongo.rb +1 -0
  10. data/config/measures/measures_2_4_0.yml +719 -0
  11. data/config/mongoid.yml +6 -0
  12. data/lib/bonnie_bundler.rb +39 -0
  13. data/lib/ext/hash.rb +28 -0
  14. data/lib/ext/railtie.rb +11 -0
  15. data/lib/ext/valueset.rb +11 -0
  16. data/lib/measures/cql_to_elm_helper.rb +90 -0
  17. data/lib/measures/elm_parser.rb +74 -0
  18. data/lib/measures/loading/base_loader_definition.rb +61 -0
  19. data/lib/measures/loading/cql_loader.rb +420 -0
  20. data/lib/measures/loading/exceptions.rb +10 -0
  21. data/lib/measures/loading/loader.rb +178 -0
  22. data/lib/measures/loading/value_set_loader.rb +137 -0
  23. data/lib/measures/logic_extractor.rb +552 -0
  24. data/lib/measures/mongo_hash_key_wrapper.rb +44 -0
  25. data/lib/models/cql_measure.rb +160 -0
  26. data/lib/models/measure.rb +330 -0
  27. data/test/fixtures/BCS_v5_0_Artifacts.zip +0 -0
  28. data/test/fixtures/CMS158_v5_4_Artifacts.zip +0 -0
  29. data/test/fixtures/CMS158_v5_4_Artifacts_Update.zip +0 -0
  30. data/test/fixtures/DRAFT_CMS2_CQL.zip +0 -0
  31. data/test/fixtures/bonnienesting01_fixed.zip +0 -0
  32. data/test/fixtures/vcr_cassettes/mat_5-4_cql_export_vsac_response.yml +4723 -0
  33. data/test/fixtures/vcr_cassettes/multi_library_webcalls.yml +1892 -0
  34. data/test/fixtures/vcr_cassettes/valid_translation_response.yml +1120 -0
  35. data/test/fixtures/vcr_cassettes/valid_vsac_response.yml +1678 -0
  36. data/test/fixtures/vcr_cassettes/valid_vsac_response_158.yml +1670 -0
  37. data/test/fixtures/vcr_cassettes/valid_vsac_response_158_update.yml +1670 -0
  38. data/test/fixtures/vcr_cassettes/valid_vsac_response_includes_draft.yml +3480 -0
  39. data/test/fixtures/vcr_cassettes/vs_loading_draft_no_profile_version.yml +1198 -0
  40. data/test/fixtures/vcr_cassettes/vs_loading_draft_profile.yml +1198 -0
  41. data/test/fixtures/vcr_cassettes/vs_loading_draft_verion.yml +1198 -0
  42. data/test/fixtures/vcr_cassettes/vs_loading_no_profile_version.yml +1198 -0
  43. data/test/fixtures/vcr_cassettes/vs_loading_profile.yml +1196 -0
  44. data/test/fixtures/vcr_cassettes/vs_loading_version.yml +20331 -0
  45. data/test/fixtures/vs_loading/DocofMeds_v5_1_Artifacts.zip +0 -0
  46. data/test/fixtures/vs_loading/DocofMeds_v5_1_Artifacts_Version.zip +0 -0
  47. data/test/fixtures/vs_loading/DocofMeds_v5_1_Artifacts_With_Profiles.zip +0 -0
  48. data/test/simplecov_init.rb +18 -0
  49. data/test/test_helper.rb +44 -0
  50. data/test/unit/load_mat_export_test.rb +181 -0
  51. data/test/unit/measure_complexity_test.rb +32 -0
  52. data/test/unit/measure_diff_test.rb +68 -0
  53. data/test/unit/mongo_hash_key_wrapper_test.rb +247 -0
  54. data/test/unit/storing_mat_export_package_test.rb +45 -0
  55. data/test/unit/value_set_loading_test.rb +109 -0
  56. data/test/vcr_setup.rb +20 -0
  57. metadata +258 -0
@@ -0,0 +1,18 @@
1
+ require 'simplecov'
2
+ SimpleCov.command_name 'Unit Tests'
3
+ SimpleCov.start do
4
+ add_filter "test/"
5
+ add_group "measures", "lib/measures"
6
+ add_group "models", "lib/models"
7
+ end
8
+
9
+ class SimpleCov::Formatter::QualityFormatter
10
+ def format(result)
11
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
12
+ File.open("coverage/covered_percent", "w") do |f|
13
+ f.puts result.source_files.covered_percent.to_f
14
+ end
15
+ end
16
+ end
17
+
18
+ SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
@@ -0,0 +1,44 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require_relative "./simplecov_init"
3
+ require 'minitest/autorun'
4
+ require 'rails'
5
+ require 'rails/test_help'
6
+ require 'hquery-patient-api'
7
+ require 'diffy'
8
+ APP_CONFIG = {'nlm'=> {'ticket_url'=> 'https://vsac.nlm.nih.gov/vsac/ws/Ticket',
9
+ 'api_url' => 'https://vsac.nlm.nih.gov/vsac/svs/RetrieveMultipleValueSets',
10
+ 'profiles_url' => 'https://vsac.nlm.nih.gov/vsac/profiles',
11
+ 'profile' => 'MU2 Update 2016-04-01'}}
12
+
13
+ PROJECT_ROOT = File.expand_path("../../", __FILE__)
14
+ require File.join(PROJECT_ROOT, 'lib', 'bonnie_bundler')
15
+ BonnieBundler.logger = Log4r::Logger.new("Bonnie Bundler")
16
+ BonnieBundler.logger.outputters = Log4r::Outputter.stdout
17
+
18
+ def dump_db
19
+ Mongoid.default_client.collections.each do |c|
20
+ c.drop()
21
+ end
22
+ FileUtils.rm_r 'db' if File.exists? 'db'
23
+ end
24
+
25
+ Mongoid.logger.level = Logger::INFO
26
+ Mongo::Logger.logger.level = Logger::INFO
27
+ dump_db
28
+
29
+ # Supplied from bonnie, needed for expected_values testing
30
+ class Record
31
+ field :type, type: String
32
+ field :measure_ids, type: Array
33
+ field :source_data_criteria, type: Array
34
+ field :expected_values, type: Array
35
+
36
+ belongs_to :user
37
+ scope :by_user, ->(user) { where({'user_id'=>user.id}) }
38
+ end
39
+
40
+
41
+ class User
42
+ include Mongoid::Document
43
+ include Mongoid::Timestamps
44
+ end
@@ -0,0 +1,181 @@
1
+ require 'test_helper'
2
+ require 'vcr_setup.rb'
3
+
4
+ class LoadMATExportTest < ActiveSupport::TestCase
5
+
6
+ setup do
7
+ @cql_mat_export = File.new File.join('test', 'fixtures', 'BCS_v5_0_Artifacts.zip')
8
+ @cql_mat_5_4_export = File.new File.join('test', 'fixtures', 'CMS158_v5_4_Artifacts.zip')
9
+ @cql_multi_library_mat_export = File.new File.join('test', 'fixtures', 'bonnienesting01_fixed.zip')
10
+ @cql_draft_measure_mat_export = File.new File.join('test', 'fixtures', 'DRAFT_CMS2_CQL.zip')
11
+ end
12
+
13
+ test "Loading a CQL Mat export zip file including draft, with VSAC credentials" do
14
+ VCR.use_cassette("valid_vsac_response_includes_draft") do
15
+ dump_db
16
+ user = User.new
17
+ user.save
18
+ measure_details = { 'episode_of_care'=> false }
19
+ overwrite_valuesets=false
20
+ cache=false
21
+ includeDraft=true
22
+ ticket_granting_ticket=nil
23
+ Measures::CqlLoader.load(@cql_draft_measure_mat_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD'], overwrite_valuesets, cache, includeDraft, ticket_granting_ticket).save
24
+ assert_equal 1, CqlMeasure.all.count
25
+ measure = CqlMeasure.all.first
26
+ assert_equal "Screening for Depression", measure.title
27
+ assert_equal "40280582-5B4D-EE92-015B-827458050128", measure.hqmf_id
28
+ assert_equal 1, measure.populations.size
29
+ assert_equal 5, measure.population_criteria.keys.count
30
+ assert_equal "C1EA44B5-B922-49C5-B41C-6509A6A86158", measure.hqmf_set_id
31
+ # Assert value_set versions are all "Draft-"
32
+ for value_set in measure.value_sets
33
+ assert_equal ("Draft-" + measure.hqmf_set_id), value_set["version"]
34
+ end
35
+ end
36
+ end
37
+
38
+ test "Using the cql-to-elm helper translation service" do
39
+ dump_db
40
+ user = User.new
41
+ user.save
42
+
43
+ VCR.use_cassette("valid_vsac_response") do
44
+ measure_details = { 'episode_of_care'=> false }
45
+ Measures::CqlLoader.load(@cql_mat_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
46
+ assert_equal 1, CqlMeasure.all.count
47
+ end
48
+
49
+ VCR.use_cassette("valid_translation_response") do
50
+ measure = CqlMeasure.first
51
+ elm_json, elm_xml = CqlElm::CqlToElmHelper.translate_cql_to_elm(measure[:cql])
52
+ assert_equal 1, elm_json.count
53
+ assert_equal 1, elm_xml.count
54
+ end
55
+ end
56
+
57
+ test "Loading a CQL Mat export zip file, with VSAC credentials" do
58
+ VCR.use_cassette("valid_vsac_response") do
59
+ dump_db
60
+ user = User.new
61
+ user.save
62
+ measure_details = { 'episode_of_care'=> false }
63
+ Measures::CqlLoader.load(@cql_mat_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
64
+ assert_equal 1, CqlMeasure.all.count
65
+ measure = CqlMeasure.all.first
66
+ assert_equal "BCSTest", measure.title
67
+ assert_equal "40280582-57B5-1CC0-0157-B53816CC0046", measure.hqmf_id
68
+ assert_equal 1, measure.populations.size
69
+ assert_equal 4, measure.population_criteria.keys.count
70
+ end
71
+ end
72
+
73
+ test "Loading a MAT 5.4 CQL export zip file with VSAC credentials" do
74
+ VCR.use_cassette("valid_vsac_response_158") do
75
+ dump_db
76
+ user = User.new
77
+ user.save
78
+
79
+ measure_details = { 'episode_of_care'=> false }
80
+ Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
81
+ assert_equal 1, CqlMeasure.all.count
82
+ measure = CqlMeasure.all.first
83
+ assert_equal "Test 158", measure.title
84
+ assert_equal "40280582-5801-9EE4-0158-310E539D0327", measure.hqmf_id
85
+ assert_equal "8F010DBB-CB52-47CD-8FE8-03A4F223D87F", measure.hqmf_set_id
86
+ assert_equal 1, measure.populations.size
87
+ assert_equal 4, measure.population_criteria.keys.count
88
+ assert_equal 1, measure.elm.size
89
+ end
90
+ end
91
+
92
+ test "Loading a MAT 5.4 CQL export zip file with VSAC credentials, confirming cql measure package is stored" do
93
+ VCR.use_cassette("valid_vsac_response_158") do
94
+ dump_db
95
+ user = User.new
96
+ user.save
97
+
98
+ measure_details = { 'episode_of_care'=> false }
99
+ Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
100
+ assert_equal 1, CqlMeasure.all.count
101
+ measure = CqlMeasure.all.first
102
+ assert_equal "Test 158", measure.title
103
+
104
+ assert_equal 1, CqlMeasurePackage.all.count
105
+ measure_package = CqlMeasurePackage.all.first
106
+ assert_equal measure.id, measure_package.measure_id
107
+ end
108
+ end
109
+
110
+ test "Loading a MAT 5.4 CQL export zip file with VSAC credentials, deleting measure and confirming measure package is also deleted" do
111
+ VCR.use_cassette("valid_vsac_response_158") do
112
+ dump_db
113
+ user = User.new
114
+ user.save
115
+
116
+ measure_details = { 'episode_of_care'=> false }
117
+ Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
118
+ assert_equal 1, CqlMeasure.all.count
119
+ measure = CqlMeasure.all.first
120
+ assert_equal 1, CqlMeasurePackage.all.count
121
+
122
+ measure.delete
123
+ assert_equal 0, CqlMeasure.all.count
124
+ assert_equal 0, CqlMeasurePackage.all.count
125
+ end
126
+ end
127
+
128
+ test "Loading a CQL Mat export with multiple libraries, with VSAC credentials" do
129
+ VCR.use_cassette("multi_library_webcalls") do
130
+ dump_db
131
+ user = User.new
132
+ user.save
133
+
134
+ measure_details = { 'episode_of_care'=> false }
135
+ Measures::CqlLoader.load(@cql_multi_library_mat_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
136
+ assert_equal 1, CqlMeasure.all.count
137
+ measure = CqlMeasure.all.first
138
+ assert_equal (measure.elm.instance_of? Array), true
139
+ assert_equal 4, measure.elm.size
140
+ measure.elm.each do |elm|
141
+ assert !(elm["library"].nil?)
142
+ end
143
+ assert_equal "BonnieLib100", measure.elm[0]["library"]["identifier"]["id"]
144
+ assert_equal "BonnieLib110", measure.elm[1]["library"]["identifier"]["id"]
145
+ assert_equal "BonnieLib200", measure.elm[2]["library"]["identifier"]["id"]
146
+ assert_equal "BonnieNesting01", measure.elm[3]["library"]["identifier"]["id"]
147
+ end
148
+ end
149
+
150
+ test "Scoping by user" do
151
+ dump_db
152
+ cql_mat_export = File.new File.join('test','fixtures','CMS158_v5_4_Artifacts.zip')
153
+ user = User.new
154
+ user2 = User.new
155
+ user2.save
156
+ VCR.use_cassette("valid_vsac_response_158") do
157
+ Measures::CqlLoader.load(cql_mat_export, user, {}).save
158
+ end
159
+
160
+ measure = CqlMeasure.all.by_user(user).first
161
+ # make sure that we can load a package and that the meause and valuesets are scoped to the user
162
+ assert_equal 1, CqlMeasure.all.by_user(user).count
163
+ vs_count = HealthDataStandards::SVS::ValueSet.count()
164
+ assert_equal vs_count, HealthDataStandards::SVS::ValueSet.by_user(user).count()
165
+ vs = HealthDataStandards::SVS::ValueSet.by_user(user).first
166
+ vsets = HealthDataStandards::SVS::ValueSet.by_user(user).to_a
167
+
168
+ # Add the same measure not associated with a user, there should be 2 measures and
169
+ # and twice as many value sets in the db after loading
170
+ VCR.use_cassette("valid_vsac_response_158") do
171
+ Measures::CqlLoader.load(cql_mat_export, user2, {}).save
172
+ end
173
+ measure2 = CqlMeasure.all.by_user(user2).first
174
+ assert_equal 1, CqlMeasure.by_user(user).count
175
+ assert_equal 2, CqlMeasure.count
176
+ assert_equal vs_count, HealthDataStandards::SVS::ValueSet.by_user(user).count()
177
+ assert_equal vs_count * 2, HealthDataStandards::SVS::ValueSet.count
178
+ u_count = Measures::ValueSetLoader.get_value_set_models(measure.value_set_oids, user).count()
179
+ assert_equal u_count, Measures::ValueSetLoader.get_value_set_models(measure2.value_set_oids, user2).count
180
+ end
181
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class MeasureComplexityTest < ActiveSupport::TestCase
4
+
5
+ setup do
6
+ @cql_mat_export = File.new File.join('test', 'fixtures', 'BCS_v5_0_Artifacts.zip')
7
+ end
8
+
9
+ test "Loading a CQL Mat export zip file, with VSAC credentials" do
10
+ VCR.use_cassette("valid_vsac_response") do
11
+ dump_db
12
+ user = User.new
13
+ user.save
14
+ measure_details = { 'episode_of_care'=> false }
15
+ Measures::CqlLoader.load(@cql_mat_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
16
+ assert_equal 1, CqlMeasure.all.count
17
+ measure = CqlMeasure.all.first
18
+ assert_equal 10, measure.complexity["variables"].length
19
+ assert_equal [{"name"=>"Patient", "complexity"=>1},
20
+ {"name"=>"SDE Ethnicity", "complexity"=>1},
21
+ {"name"=>"SDE Payer", "complexity"=>1},
22
+ {"name"=>"SDE Race", "complexity"=>1},
23
+ {"name"=>"SDE Sex", "complexity"=>1},
24
+ {"name"=>"Initial Pop", "complexity"=>2},
25
+ {"name"=>"Num", "complexity"=>1},
26
+ {"name"=>"Double Unilateral Mastectomy", "complexity"=>1},
27
+ {"name"=>"Denom", "complexity"=>3},
28
+ {"name"=>"Denom Excl", "complexity"=>2}], measure.complexity["variables"]
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+ require 'vcr_setup.rb'
3
+
4
+ class MeasureDiffTest < ActiveSupport::TestCase
5
+
6
+ test "loading previous measure" do
7
+ VCR.use_cassette("valid_vsac_response_158") do
8
+ @previous_measure = File.new File.join('test','fixtures','CMS158_v5_4_Artifacts.zip')
9
+ dump_db
10
+ user = User.new
11
+ user.save
12
+ measure_details = { 'episode_of_care'=> false }
13
+ Measures::CqlLoader.load(@previous_measure, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
14
+ end
15
+ assert_equal 1, CqlMeasure.all.count
16
+ measure = CqlMeasure.all.first
17
+ assert_equal "Test 158", measure.title
18
+ assert_equal "40280582-5801-9EE4-0158-310E539D0327", measure.hqmf_id
19
+ assert_equal 1, measure.populations.size
20
+ assert_equal 4, measure.population_criteria.keys.count
21
+ end
22
+
23
+ test "loading updated measure" do
24
+ VCR.use_cassette("valid_vsac_response_158_update") do
25
+ @updated_measure = File.new File.join('test','fixtures','CMS158_v5_4_Artifacts_Update.zip')
26
+ dump_db
27
+ user = User.new
28
+ user.save
29
+ measure_details = { 'episode_of_care'=> false }
30
+ Measures::CqlLoader.load(@updated_measure, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
31
+ end
32
+ assert_equal 1, CqlMeasure.all.count
33
+ measure = CqlMeasure.all.first
34
+ assert_equal "Test 158 Update", measure.title
35
+ assert_equal "40280582-5801-9EE4-0158-310E539D0327", measure.hqmf_id
36
+ assert_equal 1, measure.populations.size
37
+ assert_equal 4, measure.population_criteria.keys.count
38
+ end
39
+
40
+ test "loading previous against updated" do
41
+ VCR.use_cassette("valid_vsac_response_158") do
42
+ @previous_measure = File.new File.join('test','fixtures','CMS158_v5_4_Artifacts.zip')
43
+ dump_db
44
+ user = User.new
45
+ user.save
46
+ measure_details = { 'episode_of_care'=> false }
47
+ Measures::CqlLoader.load(@previous_measure, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
48
+ end
49
+ assert_equal 1, CqlMeasure.all.count
50
+ assert_equal 1, CqlMeasurePackage.all.count
51
+ previous = CqlMeasure.all.first
52
+ previous_package = CqlMeasurePackage.all.first
53
+ VCR.use_cassette("valid_vsac_response_158_update") do
54
+ @updated_measure = File.new File.join('test','fixtures','CMS158_v5_4_Artifacts_Update.zip')
55
+ user = User.new
56
+ user.save
57
+ measure_details = { 'episode_of_care'=> false }
58
+ Measures::CqlLoader.load(@updated_measure, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD']).save
59
+ end
60
+ assert_equal 2, CqlMeasure.all.count
61
+ assert_equal 2, CqlMeasurePackage.all.count
62
+ updated = CqlMeasure.order_by(created_at: :asc).last
63
+ updated_package = CqlMeasurePackage.order_by(created_at: :asc).last
64
+ assert_not_equal previous.title, updated.title
65
+ assert_not_equal previous_package.measure_id, updated_package.measure_id
66
+ end
67
+
68
+ end
@@ -0,0 +1,247 @@
1
+ require 'test_helper'
2
+
3
+ class MongoHashKeyWrapperTest < ActiveSupport::TestCase
4
+
5
+ test "wrap does not modify key without dot or caret" do
6
+ inputHash = Hash.new
7
+ inputHash['foo'] = 'bar'
8
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
9
+ assert( inputHash.key?('foo'))
10
+ end
11
+
12
+ test "wrap modifies key with dot" do
13
+ inputHash = Hash.new
14
+ inputHash['foo.baz'] = 'bar'
15
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
16
+ assert( !inputHash.key?('foo.baz'))
17
+ assert( inputHash.key?('foo^pbaz'))
18
+ end
19
+
20
+ test "wrap does not modify value of key with dot" do
21
+ inputHash = Hash.new
22
+ inputHash['foo.baz'] = 'okay.text'
23
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
24
+ assert_equal( 'okay.text', inputHash['foo^pbaz'])
25
+ end
26
+
27
+ test "wrap modifies key with caret" do
28
+ inputHash = Hash.new
29
+ inputHash['foo^baz'] = 'bar'
30
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
31
+ assert( !inputHash.key?('foo^baz'))
32
+ assert( inputHash.key?('foo^cbaz'))
33
+ end
34
+
35
+ test "wrap does not modify value of key with caret" do
36
+ inputHash = Hash.new
37
+ inputHash['foo^baz'] = 'okay.text'
38
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
39
+ assert_equal( 'okay.text', inputHash['foo^cbaz'])
40
+ end
41
+
42
+ test "wrap does not modify value without dot" do
43
+ inputHash = Hash.new
44
+ inputHash['foo'] = 'okay text'
45
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
46
+ assert_equal( 'okay text', inputHash['foo'])
47
+ end
48
+
49
+ test "wrap does not modify value with dot" do
50
+ inputHash = Hash.new
51
+ inputHash['foo'] = 'okay.text'
52
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
53
+ assert_equal( 'okay.text', inputHash['foo'])
54
+ end
55
+
56
+ test "wrap modifies all dots and carets in key" do
57
+ inputHash = Hash.new
58
+ inputHash['foo^baz.1.2^3^^^4..5bletch'] = 'bar'
59
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
60
+ assert( !inputHash.key?('foo^baz.1.2^3^^^4..5bletch'))
61
+ assert( inputHash.key?('foo^cbaz^p1^p2^c3^c^c^c4^p^p5bletch'))
62
+ end
63
+
64
+ test "wrap modifies all keys in hash with dots or carets" do
65
+ inputHash = Hash.new
66
+ inputHash['one.foo'] = 'bar1'
67
+ inputHash['bletch'] = 'bar2'
68
+ inputHash['three.baz'] = 'bar3'
69
+ inputHash['four^zippo'] = 'bar4'
70
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
71
+ assert( !inputHash.key?('one.foo'))
72
+ assert( !inputHash.key?('three.baz'))
73
+ assert( !inputHash.key?('four^zippo'))
74
+ assert( inputHash.key?('bletch'))
75
+ assert_equal( 'bar1', inputHash['one^pfoo'])
76
+ assert_equal( 'bar2', inputHash['bletch'])
77
+ assert_equal( 'bar3', inputHash['three^pbaz'])
78
+ assert_equal( 'bar4', inputHash['four^czippo'])
79
+ end
80
+
81
+ test "wrap modifies hash inside hash" do
82
+ inputHash = Hash.new
83
+ inputHash['foo'] = Hash.new
84
+ inputHash['foo']['fubar.baz'] = 'bar1'
85
+ inputHash['foo']['dos^tres'] = 'bar2'
86
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
87
+ assert( !inputHash['foo'].key?('fubar.baz'))
88
+ assert( inputHash['foo'].key?('fubar^pbaz'))
89
+ assert( !inputHash['foo'].key?('dos^tres'))
90
+ assert( inputHash['foo'].key?('dos^ctres'))
91
+ assert_equal( 'bar1', inputHash['foo']['fubar^pbaz'])
92
+ assert_equal( 'bar2', inputHash['foo']['dos^ctres'])
93
+ end
94
+
95
+ test "wrap modifies hash inside modified hash" do
96
+ inputHash = Hash.new
97
+ inputHash['one.two'] = Hash.new
98
+ inputHash['one.two']['tres^quatro'] = 'bar'
99
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
100
+ assert( !inputHash.key?('one.two'))
101
+ assert( inputHash.key?('one^ptwo'))
102
+ assert( !inputHash['one^ptwo'].key?('tres^quatro'))
103
+ assert( inputHash['one^ptwo'].key?('tres^cquatro'))
104
+ assert_equal( 'bar', inputHash['one^ptwo']['tres^cquatro'])
105
+ end
106
+
107
+ test "wrap modifies deeper hash" do
108
+ inputHash = Hash.new
109
+ inputHash['one'] = Hash.new
110
+ inputHash['one']['two'] = Hash.new
111
+ inputHash['one']['two']['three'] = Hash.new
112
+ inputHash['one']['two']['three']['four'] = Hash.new
113
+ inputHash['one']['two']['three']['four']['foo.bar^baz'] = 'bletch'
114
+ Measures::MongoHashKeyWrapper.wrapKeys(inputHash)
115
+ assert_equal( 'bletch', inputHash['one']['two']['three']['four']['foo^pbar^cbaz'])
116
+ end
117
+
118
+ ## wrap ---------------------------------------------------------------------------------
119
+
120
+ test "unwrap does not modify key without caret" do
121
+ inputHash = Hash.new
122
+ inputHash['foo'] = 'bar'
123
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
124
+ assert( inputHash.key?('foo'))
125
+ end
126
+
127
+ test "unwrap modifies key with caret p" do
128
+ inputHash = Hash.new
129
+ inputHash['foo^pbaz'] = 'bar'
130
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
131
+ assert( !inputHash.key?('foo^pbaz'))
132
+ assert( inputHash.key?('foo.baz'))
133
+ end
134
+
135
+ test "unwrap does not modify value of key with caret p" do
136
+ inputHash = Hash.new
137
+ inputHash['foo^pbaz'] = 'okay^ptext'
138
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
139
+ assert_equal( 'okay^ptext', inputHash['foo.baz'])
140
+ end
141
+
142
+ test "unwrap modifies key with caret c" do
143
+ inputHash = Hash.new
144
+ inputHash['foo^cbaz'] = 'bar'
145
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
146
+ assert( !inputHash.key?('foo^cbaz'))
147
+ assert( inputHash.key?('foo^baz'))
148
+ end
149
+
150
+ test "unwrap does not modify value of key with caret c" do
151
+ inputHash = Hash.new
152
+ inputHash['foo^cbaz'] = 'okay^ctext'
153
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
154
+ assert_equal( 'okay^ctext', inputHash['foo^baz'])
155
+ end
156
+
157
+ test "unwrap does not modify value without caret" do
158
+ inputHash = Hash.new
159
+ inputHash['foo'] = 'okay text'
160
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
161
+ assert_equal( 'okay text', inputHash['foo'])
162
+ end
163
+
164
+ test "unwrap does not modify value with caret p" do
165
+ inputHash = Hash.new
166
+ inputHash['foo'] = 'okay^ptext'
167
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
168
+ assert_equal( 'okay^ptext', inputHash['foo'])
169
+ end
170
+
171
+ test "unwrap does not modify value with caret c" do
172
+ inputHash = Hash.new
173
+ inputHash['foo'] = 'okay^ctext'
174
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
175
+ assert_equal( 'okay^ctext', inputHash['foo'])
176
+ end
177
+
178
+ test "unwrap does not modify value with caret (other than p/c following)" do
179
+ inputHash = Hash.new
180
+ inputHash['foo'] = 'okay^text'
181
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
182
+ assert_equal( 'okay^text', inputHash['foo'])
183
+ end
184
+
185
+ test "unwrap modifies all carets p's and c's in key" do
186
+ inputHash = Hash.new
187
+ inputHash['foo^cbaz^p1^p2^c3^c^c^c4^p^p5bletch'] = 'bar'
188
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
189
+ assert( !inputHash.key?('foo^cbaz^p1^p2^c3^c^c^c4^p^p5bletch'))
190
+ assert( inputHash.key?('foo^baz.1.2^3^^^4..5bletch'))
191
+ end
192
+
193
+ test "unwrap modifies all keys in hash with all carets p's and c's" do
194
+ inputHash = Hash.new
195
+ inputHash['one^pfoo'] = 'bar1'
196
+ inputHash['bletch'] = 'bar2'
197
+ inputHash['three^pbaz'] = 'bar3'
198
+ inputHash['four^czippo'] = 'bar4'
199
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
200
+ assert( !inputHash.key?('one^pfoo'))
201
+ assert( !inputHash.key?('three^pbaz'))
202
+ assert( !inputHash.key?('four^czippo'))
203
+ assert( inputHash.key?('bletch'))
204
+ assert_equal( 'bar1', inputHash['one.foo'])
205
+ assert_equal( 'bar2', inputHash['bletch'])
206
+ assert_equal( 'bar3', inputHash['three.baz'])
207
+ assert_equal( 'bar4', inputHash['four^zippo'])
208
+ end
209
+
210
+ test "unwrap modifies hash inside hash" do
211
+ inputHash = Hash.new
212
+ inputHash['foo'] = Hash.new
213
+ inputHash['foo']['fubar^pbaz'] = 'bar1'
214
+ inputHash['foo']['dos^ctres'] = 'bar2'
215
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
216
+ assert( !inputHash['foo'].key?('fubar^pbaz'))
217
+ assert( inputHash['foo'].key?('fubar.baz'))
218
+ assert( !inputHash['foo'].key?('dos^ctres'))
219
+ assert( inputHash['foo'].key?('dos^tres'))
220
+ assert_equal( 'bar1', inputHash['foo']['fubar.baz'])
221
+ assert_equal( 'bar2', inputHash['foo']['dos^tres'])
222
+ end
223
+
224
+ test "unwrap modifies hash inside modified hash" do
225
+ inputHash = Hash.new
226
+ inputHash['one^ptwo'] = Hash.new
227
+ inputHash['one^ptwo']['tres^cquatro'] = 'bar'
228
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
229
+ assert( !inputHash.key?('one^ptwo'))
230
+ assert( inputHash.key?('one.two'))
231
+ assert( !inputHash['one.two'].key?('tres^cquatro'))
232
+ assert( inputHash['one.two'].key?('tres^quatro'))
233
+ assert_equal( 'bar', inputHash['one.two']['tres^quatro'])
234
+ end
235
+
236
+ test "unwrap modifies deeper hash" do
237
+ inputHash = Hash.new
238
+ inputHash['one'] = Hash.new
239
+ inputHash['one']['two'] = Hash.new
240
+ inputHash['one']['two']['three'] = Hash.new
241
+ inputHash['one']['two']['three']['four'] = Hash.new
242
+ inputHash['one']['two']['three']['four']['foo^pbar^cbaz'] = 'bletch'
243
+ Measures::MongoHashKeyWrapper.unwrapKeys(inputHash)
244
+ assert_equal( 'bletch', inputHash['one']['two']['three']['four']['foo.bar^baz'])
245
+ end
246
+
247
+ end