marty 2.5.2 → 2.5.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.
Files changed (181) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +7 -0
  4. data/.rubocop_todo.yml +11 -589
  5. data/Gemfile +9 -9
  6. data/Gemfile.lock +1 -1
  7. data/Rakefile +1 -3
  8. data/app/components/marty/api_auth_view.rb +3 -3
  9. data/app/components/marty/api_config_view.rb +8 -8
  10. data/app/components/marty/api_log_view.rb +16 -20
  11. data/app/components/marty/auth_app.rb +6 -6
  12. data/app/components/marty/base_rule_view.rb +27 -19
  13. data/app/components/marty/config_view.rb +12 -9
  14. data/app/components/marty/data_grid_view.rb +26 -26
  15. data/app/components/marty/delorean_rule_view.rb +0 -1
  16. data/app/components/marty/event_view.rb +27 -27
  17. data/app/components/marty/extras/layout.rb +26 -26
  18. data/app/components/marty/extras/misc.rb +2 -2
  19. data/app/components/marty/grid.rb +13 -13
  20. data/app/components/marty/grid_append_only.rb +0 -1
  21. data/app/components/marty/import_type_view.rb +13 -13
  22. data/app/components/marty/import_view.rb +17 -16
  23. data/app/components/marty/log_view.rb +16 -14
  24. data/app/components/marty/main_auth_app.rb +59 -59
  25. data/app/components/marty/main_auth_app/client/main_auth_app.js +3 -3
  26. data/app/components/marty/mcfly_grid_panel.rb +10 -10
  27. data/app/components/marty/new_posting_form.rb +11 -11
  28. data/app/components/marty/new_posting_window.rb +0 -1
  29. data/app/components/marty/posting_grid.rb +12 -13
  30. data/app/components/marty/promise_view.rb +6 -6
  31. data/app/components/marty/report_form.rb +50 -53
  32. data/app/components/marty/report_select.rb +27 -27
  33. data/app/components/marty/reporting.rb +4 -4
  34. data/app/components/marty/script_form.rb +40 -42
  35. data/app/components/marty/script_grid.rb +24 -24
  36. data/app/components/marty/script_tester.rb +40 -42
  37. data/app/components/marty/scripting.rb +25 -27
  38. data/app/components/marty/simple_app.rb +24 -9
  39. data/app/components/marty/tag_grid.rb +12 -13
  40. data/app/components/marty/user_view.rb +35 -35
  41. data/app/controllers/marty/application_controller.rb +3 -4
  42. data/app/controllers/marty/components_controller.rb +1 -1
  43. data/app/controllers/marty/delayed_job_controller.rb +1 -0
  44. data/app/controllers/marty/diagnostic/controller.rb +4 -6
  45. data/app/controllers/marty/job_controller.rb +6 -6
  46. data/app/controllers/marty/report_controller.rb +11 -11
  47. data/app/controllers/marty/rpc_controller.rb +15 -16
  48. data/app/helpers/marty/script_set.rb +4 -4
  49. data/app/models/marty/api_auth.rb +4 -5
  50. data/app/models/marty/api_config.rb +1 -1
  51. data/app/models/marty/base.rb +9 -8
  52. data/app/models/marty/base_rule.rb +18 -13
  53. data/app/models/marty/config.rb +4 -5
  54. data/app/models/marty/data_grid.rb +157 -181
  55. data/app/models/marty/delorean_rule.rb +63 -62
  56. data/app/models/marty/enum.rb +1 -1
  57. data/app/models/marty/event.rb +56 -59
  58. data/app/models/marty/helper.rb +38 -6
  59. data/app/models/marty/import_type.rb +6 -6
  60. data/app/models/marty/log.rb +3 -2
  61. data/app/models/marty/name_validator.rb +3 -2
  62. data/app/models/marty/pg_enum.rb +3 -4
  63. data/app/models/marty/posting.rb +20 -24
  64. data/app/models/marty/promise.rb +28 -30
  65. data/app/models/marty/script.rb +30 -28
  66. data/app/models/marty/tag.rb +8 -8
  67. data/app/models/marty/token.rb +2 -2
  68. data/app/models/marty/user.rb +24 -23
  69. data/app/models/marty/vw_promise.rb +10 -11
  70. data/config/routes.rb +2 -2
  71. data/delorean/blame_report.dl +268 -0
  72. data/{spec/dummy/delorean/fields.dl → delorean/marty_fields.dl} +8 -0
  73. data/delorean/table_report.dl +34 -0
  74. data/docker-compose.dummy.yml +2 -3
  75. data/lib/marty/aws/base.rb +8 -8
  76. data/lib/marty/aws/request.rb +4 -4
  77. data/lib/marty/cache_adapters/mcfly_ruby_cache.rb +1 -0
  78. data/lib/marty/content_handler.rb +25 -25
  79. data/lib/marty/data_change.rb +49 -71
  80. data/lib/marty/data_conversion.rb +20 -28
  81. data/lib/marty/data_exporter.rb +25 -28
  82. data/lib/marty/data_importer.rb +25 -27
  83. data/lib/marty/engine.rb +1 -2
  84. data/lib/marty/json_schema.rb +22 -24
  85. data/lib/marty/logger.rb +6 -9
  86. data/lib/marty/mcfly_model.rb +20 -24
  87. data/lib/marty/migrations.rb +37 -35
  88. data/lib/marty/monkey.rb +33 -33
  89. data/lib/marty/permissions.rb +18 -18
  90. data/lib/marty/promise_job.rb +17 -17
  91. data/lib/marty/promise_proxy.rb +6 -6
  92. data/lib/marty/relation.rb +6 -7
  93. data/lib/marty/rpc_call.rb +13 -12
  94. data/lib/marty/rule_script_set.rb +32 -28
  95. data/lib/marty/schema_helper.rb +37 -51
  96. data/lib/marty/util.rb +25 -24
  97. data/lib/marty/version.rb +1 -1
  98. data/lib/marty/xl.rb +121 -115
  99. data/make-dummy.mk +3 -0
  100. data/marty.gemspec +21 -21
  101. data/other/marty/api/base.rb +34 -35
  102. data/other/marty/diagnostic/aws/ec2_instance.rb +8 -8
  103. data/other/marty/diagnostic/base.rb +13 -14
  104. data/other/marty/diagnostic/collection.rb +2 -1
  105. data/other/marty/diagnostic/connections.rb +8 -6
  106. data/other/marty/diagnostic/database.rb +1 -0
  107. data/other/marty/diagnostic/delayed_job_version.rb +7 -9
  108. data/other/marty/diagnostic/delayed_job_worker_total_count.rb +1 -1
  109. data/other/marty/diagnostic/delayed_job_workers.rb +1 -1
  110. data/other/marty/diagnostic/environment_variables.rb +17 -15
  111. data/other/marty/diagnostic/fatal.rb +1 -1
  112. data/other/marty/diagnostic/node.rb +5 -9
  113. data/other/marty/diagnostic/nodes.rb +7 -5
  114. data/other/marty/diagnostic/packer.rb +7 -7
  115. data/other/marty/diagnostic/reporter.rb +24 -27
  116. data/other/marty/diagnostic/version.rb +3 -5
  117. data/script/rails +2 -1
  118. data/spec/controllers/application_controller_spec.rb +6 -6
  119. data/spec/controllers/delayed_job_controller_spec.rb +4 -4
  120. data/spec/controllers/diagnostic/controller_spec.rb +59 -60
  121. data/spec/controllers/job_controller_spec.rb +68 -69
  122. data/spec/controllers/rpc_controller_spec.rb +353 -359
  123. data/spec/controllers/rpc_import_spec.rb +15 -16
  124. data/spec/dummy/delorean/blame_report.dl +110 -15
  125. data/spec/dummy/delorean/data_report.dl +4 -4
  126. data/spec/dummy/delorean/marty_fields.dl +63 -0
  127. data/spec/dummy/delorean/table_report.dl +34 -0
  128. data/spec/features/auth_app_spec.rb +1 -2
  129. data/spec/features/data_import_spec.rb +2 -3
  130. data/spec/features/enum_spec.rb +42 -46
  131. data/spec/features/jobs_dashboard_spec.rb +14 -8
  132. data/spec/features/log_view_spec.rb +40 -43
  133. data/spec/features/reporting_spec.rb +15 -15
  134. data/spec/features/rule_spec.rb +195 -190
  135. data/spec/features/scripting_spec.rb +17 -20
  136. data/spec/features/scripting_test_spec.rb +32 -33
  137. data/spec/features/user_view_spec.rb +15 -17
  138. data/spec/job_helper.rb +11 -11
  139. data/spec/lib/data_blame_spec.rb +82 -0
  140. data/spec/lib/data_exporter_spec.rb +31 -32
  141. data/spec/lib/data_importer_spec.rb +382 -395
  142. data/spec/lib/delorean_query_spec.rb +117 -119
  143. data/spec/lib/json_schema_spec.rb +382 -392
  144. data/spec/lib/logger_spec.rb +23 -24
  145. data/spec/lib/mcfly_model_spec.rb +112 -109
  146. data/spec/lib/migrations_spec.rb +10 -10
  147. data/spec/lib/struct_compare_spec.rb +6 -6
  148. data/spec/lib/table_report_spec.rb +90 -0
  149. data/spec/lib/xl_spec.rb +63 -65
  150. data/spec/lib/xl_styles_spec.rb +16 -19
  151. data/spec/models/api_auth_spec.rb +30 -30
  152. data/spec/models/config_spec.rb +32 -32
  153. data/spec/models/data_grid_spec.rb +642 -655
  154. data/spec/models/event_spec.rb +96 -88
  155. data/spec/models/import_type_spec.rb +20 -20
  156. data/spec/models/posting_spec.rb +35 -35
  157. data/spec/models/promise_spec.rb +5 -5
  158. data/spec/models/rule_spec.rb +280 -269
  159. data/spec/models/script_spec.rb +27 -18
  160. data/spec/models/user_spec.rb +9 -9
  161. data/spec/other/diagnostic/base_spec.rb +20 -19
  162. data/spec/other/diagnostic/collection_spec.rb +6 -5
  163. data/spec/other/diagnostic/delayed_job_version_spec.rb +1 -1
  164. data/spec/other/diagnostic/delayed_job_workers_spec.rb +8 -8
  165. data/spec/other/diagnostic/reporter_spec.rb +31 -33
  166. data/spec/spec_helper.rb +5 -5
  167. data/spec/support/chromedriver.rb +3 -5
  168. data/spec/support/components/netzke_combobox.rb +1 -1
  169. data/spec/support/components/netzke_grid.rb +17 -17
  170. data/spec/support/custom_matchers.rb +2 -2
  171. data/spec/support/download_helper.rb +1 -1
  172. data/spec/support/helper.rb +1 -2
  173. data/spec/support/netzke.rb +31 -31
  174. data/spec/support/performance_helper.rb +8 -8
  175. data/spec/support/post_run_logger.rb +1 -2
  176. data/spec/support/setup.rb +1 -4
  177. data/spec/support/shared_connection.rb +2 -2
  178. data/spec/support/structure_compare.rb +21 -22
  179. data/spec/support/suite.rb +1 -2
  180. data/spec/support/users.rb +5 -6
  181. metadata +32 -26
@@ -1,14 +1,13 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module Marty
4
-
5
- bud_cats =<<EOF
4
+ bud_cats = <<EOF
6
5
  name
7
6
  Conv Fixed 30
8
7
  Conv Fixed 20
9
8
  EOF
10
9
 
11
- fannie_bup =<<EOF
10
+ fannie_bup = <<EOF
12
11
  bud_category note_rate buy_up buy_down settlement_mm settlement_yy
13
12
  Conv Fixed 30 2.250 4.42000 7.24000 12 2012
14
13
  Conv Fixed 30 2.375 4.42000 7.24000 12 2012
@@ -19,7 +18,7 @@ Conv Fixed 20 2.875 4.24800 6.95900 12 2012
19
18
  Conv Fixed 20 2.875 4.24800 6.95900 11 2012
20
19
  EOF
21
20
 
22
- script =<<EOF
21
+ script = <<EOF
23
22
  A:
24
23
  c = Gemini::FannieBup.
25
24
  joins("bud_category").
@@ -75,119 +74,118 @@ A:
75
74
  mcfly_pt('01-01-2003').count
76
75
  EOF
77
76
 
78
- describe 'DeloreanQuery' do
79
- before(:all) do
80
- @clean_file = "/tmp/clean_#{Process.pid}.psql"
81
- save_clean_db(@clean_file)
82
- end
83
-
84
- before(:each) do
85
- marty_whodunnit
86
- Marty::DataImporter.do_import_summary(Gemini::BudCategory, bud_cats)
87
- Marty::DataImporter.do_import_summary(Gemini::FannieBup, fannie_bup)
88
-
89
- Marty::Script.load_script_bodies(
90
- {
91
- "A" => script,
92
- }, Date.today)
93
-
94
- @engine = Marty::ScriptSet.new.get_engine("A")
95
- end
96
-
97
- after(:all) do
98
- restore_clean_db(@clean_file)
99
- Marty::ScriptSet.clear_cache
100
- end
101
-
102
- it "perfroms join+count" do
103
- res = @engine.evaluate("A", "c", {})
104
-
105
- expect(res).to eq Gemini::FannieBup.
106
- joins("bud_category").
107
- where("name LIKE '%30'").
108
- count
109
-
110
- end
111
-
112
- it "perfroms select+distinct" do
113
- res = @engine.evaluate("A", "s", {})
114
-
115
- expect(res).to eq Gemini::FannieBup.
116
- joins("bud_category").
117
- select("name").
118
- distinct("name").
119
- pluck("name")
120
- end
121
-
122
- it "perfroms mcfly_pt" do
123
- res = @engine.evaluate("A", ["m", "mm"], {})
124
-
125
- expect(res).to eq [
126
- Gemini::FannieBup.
127
- joins("bud_category").
128
- mcfly_pt('infinity').
129
- select("name").
130
- pluck("name"),
131
- Gemini::FannieBup.
132
- mcfly_pt('01-01-2003').count,
133
- ]
134
- end
135
-
136
- it "perfroms order+first" do
137
- res = @engine.evaluate("A", "o", {})
138
-
139
- expect(res).to eq Gemini::FannieBup.
140
- order("note_rate DESC", "buy_down ASC").
141
- select("note_rate").
142
- first.note_rate
143
- end
144
-
145
- it "perfroms order+find_by" do
146
- res = @engine.evaluate("A", "oo", {})
147
-
148
- expect(res).to eq Gemini::FannieBup.
149
- order("note_rate", "buy_down ASC").
150
- select("note_rate").
151
- find_by("obsoleted_dt = 'infinity'").
152
- note_rate
153
- end
154
-
155
- it "perfroms find_by on class" do
156
- res = @engine.evaluate("A", "ooo", {})
157
-
158
- expect(res).to eq Gemini::FannieBup.find_by(id: -1)
159
- end
160
-
161
- it "perfroms group+count" do
162
- res = @engine.evaluate("A", "gg", {})
163
-
164
- expect(res).
165
- to eq Gemini::FannieBup.
166
- select("settlement_yy*settlement_mm AS x, count(*) AS c").
167
- group("settlement_mm", "settlement_yy").
168
- order("settlement_mm").
169
- map(&:attributes)
170
- end
171
-
172
- it "perfroms where+not" do
173
- res = @engine.evaluate("A", "n", {})
174
-
175
- expect(res).to eq Gemini::FannieBup.where.not("settlement_mm < 12").count
176
- end
177
-
178
- it "perfroms query+query" do
179
- res = @engine.evaluate("A", ["q1", "q2"], {})
180
-
181
- expect(res).to eq [
182
- [2.25, 2.375, 2.5, 2.625, 2.75, 2.875],
183
- [2.875, 2.75, 2.625, 2.5, 2.375, 2.25],
184
- ]
185
- end
186
-
187
- it "handle query params" do
188
- res = @engine.evaluate("A", "pq",
189
- {"settlement_mm" => 12, "note_rate" => 2.5})
190
- expect(res).to eq [2.625, 2.75, 2.875]
191
- end
77
+ describe 'DeloreanQuery' do
78
+ before(:all) do
79
+ @clean_file = "/tmp/clean_#{Process.pid}.psql"
80
+ save_clean_db(@clean_file)
81
+ end
82
+
83
+ before(:each) do
84
+ marty_whodunnit
85
+ Marty::DataImporter.do_import_summary(Gemini::BudCategory, bud_cats)
86
+ Marty::DataImporter.do_import_summary(Gemini::FannieBup, fannie_bup)
87
+
88
+ Marty::Script.load_script_bodies(
89
+ {
90
+ 'A' => script,
91
+ }, Date.today)
92
+
93
+ @engine = Marty::ScriptSet.new.get_engine('A')
94
+ end
95
+
96
+ after(:all) do
97
+ restore_clean_db(@clean_file)
98
+ Marty::ScriptSet.clear_cache
99
+ end
100
+
101
+ it 'perfroms join+count' do
102
+ res = @engine.evaluate('A', 'c', {})
103
+
104
+ expect(res).to eq Gemini::FannieBup.
105
+ joins('bud_category').
106
+ where("name LIKE '%30'").
107
+ count
108
+ end
109
+
110
+ it 'perfroms select+distinct' do
111
+ res = @engine.evaluate('A', 's', {})
112
+
113
+ expect(res).to eq Gemini::FannieBup.
114
+ joins('bud_category').
115
+ select('name').
116
+ distinct('name').
117
+ pluck('name')
118
+ end
119
+
120
+ it 'perfroms mcfly_pt' do
121
+ res = @engine.evaluate('A', ['m', 'mm'], {})
122
+
123
+ expect(res).to eq [
124
+ Gemini::FannieBup.
125
+ joins('bud_category').
126
+ mcfly_pt('infinity').
127
+ select('name').
128
+ pluck('name'),
129
+ Gemini::FannieBup.
130
+ mcfly_pt('01-01-2003').count,
131
+ ]
132
+ end
133
+
134
+ it 'perfroms order+first' do
135
+ res = @engine.evaluate('A', 'o', {})
136
+
137
+ expect(res).to eq Gemini::FannieBup.
138
+ order('note_rate DESC', 'buy_down ASC').
139
+ select('note_rate').
140
+ first.note_rate
192
141
  end
142
+
143
+ it 'perfroms order+find_by' do
144
+ res = @engine.evaluate('A', 'oo', {})
145
+
146
+ expect(res).to eq Gemini::FannieBup.
147
+ order('note_rate', 'buy_down ASC').
148
+ select('note_rate').
149
+ find_by("obsoleted_dt = 'infinity'").
150
+ note_rate
151
+ end
152
+
153
+ it 'perfroms find_by on class' do
154
+ res = @engine.evaluate('A', 'ooo', {})
155
+
156
+ expect(res).to eq Gemini::FannieBup.find_by(id: -1)
157
+ end
158
+
159
+ it 'perfroms group+count' do
160
+ res = @engine.evaluate('A', 'gg', {})
161
+
162
+ expect(res).
163
+ to eq Gemini::FannieBup.
164
+ select('settlement_yy*settlement_mm AS x, count(*) AS c').
165
+ group('settlement_mm', 'settlement_yy').
166
+ order('settlement_mm').
167
+ map(&:attributes)
168
+ end
169
+
170
+ it 'perfroms where+not' do
171
+ res = @engine.evaluate('A', 'n', {})
172
+
173
+ expect(res).to eq Gemini::FannieBup.where.not('settlement_mm < 12').count
174
+ end
175
+
176
+ it 'perfroms query+query' do
177
+ res = @engine.evaluate('A', ['q1', 'q2'], {})
178
+
179
+ expect(res).to eq [
180
+ [2.25, 2.375, 2.5, 2.625, 2.75, 2.875],
181
+ [2.875, 2.75, 2.625, 2.5, 2.375, 2.25],
182
+ ]
183
+ end
184
+
185
+ it 'handle query params' do
186
+ res = @engine.evaluate('A', 'pq',
187
+ 'settlement_mm' => 12, 'note_rate' => 2.5)
188
+ expect(res).to eq [2.625, 2.75, 2.875]
189
+ end
190
+ end
193
191
  end
@@ -1,55 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class MammalEnum
4
- VALUES=Set['Dog','Cat','Human','Cow','Bear']
4
+ VALUES = Set['Dog', 'Cat', 'Human', 'Cow', 'Bear']
5
5
  end
6
6
 
7
7
  class ElectronicsEnum
8
- VALUES=Set['Phone','Keyboard','Terminator']
8
+ VALUES = Set['Phone', 'Keyboard', 'Terminator']
9
9
  end
10
10
 
11
11
  class NotAnEnum
12
- HI = "MOM"
12
+ HI = 'MOM'
13
13
  end
14
14
 
15
15
  module Marty
16
-
17
16
  describe JsonSchema do
18
-
19
17
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
20
18
  ### Generic, simple data ###
21
19
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
22
20
 
23
21
  simple_schema = {
24
- "$schema" => "http://json-schema.org/marty-draft/schema#",
25
- "properties" => {
26
- "a" => {
27
- "type" => "integer"
22
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
23
+ 'properties' => {
24
+ 'a' => {
25
+ 'type' => 'integer'
28
26
  },
29
27
  }
30
28
  }
31
- opt = { :validate_schema => true,
29
+ opt = { :validate_schema => true,
32
30
  :errors_as_objects => false,
33
31
  :version => Marty::JsonSchema::RAW_URI }
34
32
 
35
- it "returns no error on correct simple data" do
36
- data = {"a" => 5}
33
+ it 'returns no error on correct simple data' do
34
+ data = { 'a' => 5 }
37
35
  expect(JSON::Validator.fully_validate(simple_schema, data, opt)).to eq([])
38
36
  end
39
37
 
40
- it "returns error on incorrect simple data -- 1" do
41
- data = {"a" => 5.2}
38
+ it 'returns error on incorrect simple data -- 1' do
39
+ data = { 'a' => 5.2 }
42
40
  expect(JSON::Validator.
43
41
  fully_validate(simple_schema, data, opt)[0]).to include(
44
- "property '#/a' of type number did not match the following type: integer")
42
+ "property '#/a' of type number did not match the following type: integer")
45
43
  end
46
44
 
47
- it "returns error on incorrect simple data -- 2" do
48
- data = {"a" => "Kangaroo"}
45
+ it 'returns error on incorrect simple data -- 2' do
46
+ data = { 'a' => 'Kangaroo' }
49
47
  expect(JSON::Validator.
50
48
  fully_validate(simple_schema, data, opt)[0]).to include(
51
- "property '#/a' of type string did not match the following type: integer")
52
-
49
+ "property '#/a' of type string did not match the following type: integer")
53
50
  end
54
51
 
55
52
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
@@ -57,99 +54,99 @@ module Marty
57
54
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
58
55
 
59
56
  pg_schema_opt = {
60
- "$schema" => "http://json-schema.org/marty-draft/schema#",
61
- "properties" => {
62
- "a" => {
63
- "pg_enum" => "MammalEnum"
57
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
58
+ 'properties' => {
59
+ 'a' => {
60
+ 'pg_enum' => 'MammalEnum'
64
61
  },
65
62
  }
66
63
  }
67
64
 
68
- it "returns no error on correct existing enums" do
69
- data = {"a" => 'Dog'}
65
+ it 'returns no error on correct existing enums' do
66
+ data = { 'a' => 'Dog' }
70
67
  expect(JSON::Validator.fully_validate(pg_schema_opt, data, opt)).to eq([])
71
68
  end
72
69
 
73
- it "vacuously returns no error on a field not validated" do
74
- data = {"b" => 'Dawg'}
70
+ it 'vacuously returns no error on a field not validated' do
71
+ data = { 'b' => 'Dawg' }
75
72
  expect(JSON::Validator.fully_validate(pg_schema_opt, data, opt)).to eq([])
76
73
  end
77
74
 
78
- it "returns error on non-existant enums" do
79
- data = {"a" => 'Beer'}
75
+ it 'returns error on non-existant enums' do
76
+ data = { 'a' => 'Beer' }
80
77
  expect(JSON::Validator.
81
78
  fully_validate(pg_schema_opt, data, opt)[0]).to include(
82
- "property '#/a' value 'Beer' not contained in MammalEnum")
79
+ "property '#/a' value 'Beer' not contained in MammalEnum")
83
80
  end
84
81
 
85
- it "returns no error when a optional field is not suppplied" do
82
+ it 'returns no error when a optional field is not suppplied' do
86
83
  data = {}
87
84
  expect(JSON::Validator.fully_validate(pg_schema_opt, data, opt)).to eq([])
88
85
  end
89
86
 
90
- it "returns error when a nil enum is passed even when enum is optional" do
91
- data = {"a" => nil}
87
+ it 'returns error when a nil enum is passed even when enum is optional' do
88
+ data = { 'a' => nil }
92
89
  expect(JSON::Validator.
93
90
  fully_validate(pg_schema_opt, data, opt)[0]).to include(
94
- "property '#/a' value '' not contained in MammalEnum")
91
+ "property '#/a' value '' not contained in MammalEnum")
95
92
  end
96
93
 
97
94
  pg_schema_req = {
98
- "$schema" => "http://json-schema.org/marty-draft/schema#",
99
- "required" => ["a"],
100
- "properties" => {
101
- "a" => {
102
- "pg_enum" => "MammalEnum"
95
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
96
+ 'required' => ['a'],
97
+ 'properties' => {
98
+ 'a' => {
99
+ 'pg_enum' => 'MammalEnum'
103
100
  },
104
101
  }
105
102
  }
106
103
 
107
- it "returns error when a required field is not supplied" do
104
+ it 'returns error when a required field is not supplied' do
108
105
  data = {}
109
106
  expect(JSON::Validator.
110
107
  fully_validate(pg_schema_req, data, opt)[0]).to include(
111
- "property '#/' did not contain a required property of 'a'")
108
+ "property '#/' did not contain a required property of 'a'")
112
109
  end
113
110
 
114
- it "returns error when a nil enum is passed when enum is required" do
115
- data = {"a" => nil}
111
+ it 'returns error when a nil enum is passed when enum is required' do
112
+ data = { 'a' => nil }
116
113
  expect(JSON::Validator.
117
114
  fully_validate(pg_schema_req, data, opt)[0]).to include(
118
- "property '#/a' value '' not contained in MammalEnum")
115
+ "property '#/a' value '' not contained in MammalEnum")
119
116
  end
120
117
 
121
118
  pg_schema_req_bad = {
122
- "$schema" => "http://json-schema.org/marty-draft/schema#",
123
- "required" => ["a"],
124
- "properties" => {
125
- "a" => {
126
- "pg_enum" => "NotAnEnum"
119
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
120
+ 'required' => ['a'],
121
+ 'properties' => {
122
+ 'a' => {
123
+ 'pg_enum' => 'NotAnEnum'
127
124
  },
128
125
  }
129
126
  }
130
127
 
131
- it "returns raises meaningful error on schema enum error" do
132
- data = {"a" => nil}
128
+ it 'returns raises meaningful error on schema enum error' do
129
+ data = { 'a' => nil }
133
130
  expect(JSON::Validator.
134
131
  fully_validate(pg_schema_req_bad, data, opt)[0]).to include(
135
- "property '#/a': 'NotAnEnum' is not a pg_enum class")
132
+ "property '#/a': 'NotAnEnum' is not a pg_enum class")
136
133
  end
137
134
 
138
135
  pg_schema_req_bad2 = {
139
- "$schema" => "http://json-schema.org/marty-draft/schema#",
140
- "required" => ["a"],
141
- "properties" => {
142
- "a" => {
143
- "pg_enum" => "NotEvenAClass"
136
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
137
+ 'required' => ['a'],
138
+ 'properties' => {
139
+ 'a' => {
140
+ 'pg_enum' => 'NotEvenAClass'
144
141
  },
145
142
  }
146
143
  }
147
144
 
148
- it "returns raises meaningful error on schema enum error" do
149
- data = {"a" => nil}
145
+ it 'returns raises meaningful error on schema enum error' do
146
+ data = { 'a' => nil }
150
147
  expect(JSON::Validator.
151
148
  fully_validate(pg_schema_req_bad2, data, opt)[0]).to include(
152
- "property '#/a': 'NotEvenAClass' is not a pg_enum class")
149
+ "property '#/a': 'NotEvenAClass' is not a pg_enum class")
153
150
  end
154
151
 
155
152
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
@@ -157,74 +154,74 @@ module Marty
157
154
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
158
155
 
159
156
  date_schema_opt = {
160
- "$schema" => "http://json-schema.org/marty-draft/schema#",
161
- "properties" => {
162
- "a" => {
163
- "type" => "string",
164
- "format" => "date"
157
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
158
+ 'properties' => {
159
+ 'a' => {
160
+ 'type' => 'string',
161
+ 'format' => 'date'
165
162
  }
166
163
  }
167
164
  }
168
165
 
169
- it "returns true on a properly formatted date" do
170
- data = {"a" => '2017-05-22'}
166
+ it 'returns true on a properly formatted date' do
167
+ data = { 'a' => '2017-05-22' }
171
168
  expect(JSON::Validator.validate(date_schema_opt, data)).to be true
172
169
  end
173
170
 
174
- it "vacuously returns true on a field not validated" do
175
- data = {"b" => 'Today is May 22nd'}
171
+ it 'vacuously returns true on a field not validated' do
172
+ data = { 'b' => 'Today is May 22nd' }
176
173
  expect(JSON::Validator.validate(date_schema_opt, data)).to be true
177
174
  end
178
175
 
179
- it "returns error on an improperly formatted date" do
180
- data = {"a" => '2017-05-32'}
176
+ it 'returns error on an improperly formatted date' do
177
+ data = { 'a' => '2017-05-32' }
181
178
  expect(JSON::Validator.
182
179
  fully_validate(date_schema_opt, data, opt)[0]).to include(
183
- "property '#/a' must be a date in the format of YYYY-MM-DD")
180
+ "property '#/a' must be a date in the format of YYYY-MM-DD")
184
181
  end
185
182
 
186
- it "returns error on an properly formatted datetime" do
187
- data = {"a" => '2017-05-22T14:51:44Z'}
183
+ it 'returns error on an properly formatted datetime' do
184
+ data = { 'a' => '2017-05-22T14:51:44Z' }
188
185
  expect(JSON::Validator.
189
186
  fully_validate(date_schema_opt, data, opt)[0]).to include(
190
- "property '#/a' must be a date in the format of YYYY-MM-DD")
187
+ "property '#/a' must be a date in the format of YYYY-MM-DD")
191
188
  end
192
189
 
193
- it "returns true when an optional date is not supplied" do
190
+ it 'returns true when an optional date is not supplied' do
194
191
  data = {}
195
192
  expect(JSON::Validator.validate(date_schema_opt, data)).to be true
196
193
  end
197
194
 
198
- it "returns error when a nil date is passed even when date is optional" do
199
- data = {"a" => nil}
195
+ it 'returns error when a nil date is passed even when date is optional' do
196
+ data = { 'a' => nil }
200
197
  expect(JSON::Validator.
201
198
  fully_validate(date_schema_opt, data, opt)[0]).to include(
202
- "property '#/a' of type null did not match the following type: string")
199
+ "property '#/a' of type null did not match the following type: string")
203
200
  end
204
201
 
205
202
  date_schema_req = {
206
- "$schema" => "http://json-schema.org/marty-draft/schema#",
207
- "required" => ["a"],
208
- "properties" => {
209
- "a" => {
210
- "type" => "string",
211
- "format" => "date"
203
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
204
+ 'required' => ['a'],
205
+ 'properties' => {
206
+ 'a' => {
207
+ 'type' => 'string',
208
+ 'format' => 'date'
212
209
  }
213
210
  }
214
211
  }
215
212
 
216
- it "returns error when a required date field is not supplied" do
213
+ it 'returns error when a required date field is not supplied' do
217
214
  data = {}
218
215
  expect(JSON::Validator.
219
216
  fully_validate(date_schema_req, data, opt)[0]).to include(
220
- "property '#/' did not contain a required property of 'a'")
217
+ "property '#/' did not contain a required property of 'a'")
221
218
  end
222
219
 
223
- it "returns error when a nil date is passed when date is required" do
224
- data = {"a" => nil}
220
+ it 'returns error when a nil date is passed when date is required' do
221
+ data = { 'a' => nil }
225
222
  expect(JSON::Validator.
226
223
  fully_validate(date_schema_req, data, opt)[0]).to include(
227
- "property '#/a' of type null did not match the following type: string")
224
+ "property '#/a' of type null did not match the following type: string")
228
225
  end
229
226
 
230
227
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
@@ -232,67 +229,67 @@ module Marty
232
229
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
233
230
 
234
231
  datetime_schema_opt = {
235
- "$schema" => "http://json-schema.org/marty-draft/schema#",
236
- "properties" => {
237
- "a" => {
238
- "type" => "string",
239
- "format" => "date-time"
232
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
233
+ 'properties' => {
234
+ 'a' => {
235
+ 'type' => 'string',
236
+ 'format' => 'date-time'
240
237
  }
241
238
  }
242
239
  }
243
240
 
244
- it "returns true on a properly formatted datetime" do
245
- data = {"a" => '2017-05-22T14:51:44Z'}
241
+ it 'returns true on a properly formatted datetime' do
242
+ data = { 'a' => '2017-05-22T14:51:44Z' }
246
243
  expect(JSON::Validator.validate(datetime_schema_opt, data)).to be true
247
244
  end
248
245
 
249
- it "vacuously returns true on a field not validated" do
250
- data = {"b" => 'Today is May 22nd'}
246
+ it 'vacuously returns true on a field not validated' do
247
+ data = { 'b' => 'Today is May 22nd' }
251
248
  expect(JSON::Validator.validate(datetime_schema_opt, data)).to be true
252
249
  end
253
250
 
254
- it "returns error on an improperly formatted datetime" do
255
- data = {"a" => '2017-30-22T14:51:44Z'}
251
+ it 'returns error on an improperly formatted datetime' do
252
+ data = { 'a' => '2017-30-22T14:51:44Z' }
256
253
  expect(JSON::Validator.
257
254
  fully_validate(datetime_schema_opt, data, opt)[0]).to include(
258
- "property '#/a' must be a date/time in the ISO-8601 format")
255
+ "property '#/a' must be a date/time in the ISO-8601 format")
259
256
  end
260
257
 
261
- it "returns true when an opt field is not supplied" do
258
+ it 'returns true when an opt field is not supplied' do
262
259
  data = {}
263
260
  expect(JSON::Validator.validate(datetime_schema_opt, data)).to be true
264
261
  end
265
262
 
266
- it "returns error when a nil dt is passed even when dt is opt" do
267
- data = {"a" => nil}
263
+ it 'returns error when a nil dt is passed even when dt is opt' do
264
+ data = { 'a' => nil }
268
265
  expect(JSON::Validator.
269
266
  fully_validate(datetime_schema_opt, data, opt)[0]).to include(
270
- "property '#/a' of type null did not match the following type: string")
267
+ "property '#/a' of type null did not match the following type: string")
271
268
  end
272
269
 
273
270
  datetime_schema_req = {
274
- "$schema" => "http://json-schema.org/marty-draft/schema#",
275
- "required" => ["a"],
276
- "properties" => {
277
- "a" => {
278
- "type" => "string",
279
- "format" => "date-time"
271
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
272
+ 'required' => ['a'],
273
+ 'properties' => {
274
+ 'a' => {
275
+ 'type' => 'string',
276
+ 'format' => 'date-time'
280
277
  }
281
278
  }
282
279
  }
283
280
 
284
- it "returns error when a required field is not supplied" do
281
+ it 'returns error when a required field is not supplied' do
285
282
  data = {}
286
283
  expect(JSON::Validator.
287
284
  fully_validate(datetime_schema_req, data, opt)[0]).to include(
288
- "property '#/' did not contain a required property of 'a'")
285
+ "property '#/' did not contain a required property of 'a'")
289
286
  end
290
287
 
291
- it "returns error when a nil dt is passed when dt is required" do
292
- data = {"a" => nil}
288
+ it 'returns error when a nil dt is passed when dt is required' do
289
+ data = { 'a' => nil }
293
290
  expect(JSON::Validator.
294
291
  fully_validate(datetime_schema_req, data, opt)[0]).to include(
295
- "property '#/a' of type null did not match the following type: string")
292
+ "property '#/a' of type null did not match the following type: string")
296
293
  end
297
294
 
298
295
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
@@ -300,119 +297,119 @@ module Marty
300
297
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
301
298
 
302
299
  pg_dt_schema = {
303
- "$schema" => "http://json-schema.org/marty-draft/schema#",
304
- "properties" => {
305
- "a" => {
306
- "pg_enum" => "MammalEnum"
300
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
301
+ 'properties' => {
302
+ 'a' => {
303
+ 'pg_enum' => 'MammalEnum'
307
304
  },
308
- "b" => {
309
- "type" => "string",
310
- "format" => "date-time"
305
+ 'b' => {
306
+ 'type' => 'string',
307
+ 'format' => 'date-time'
311
308
  },
312
309
  }
313
310
  }
314
311
 
315
- it "validates both pg_enum and dt format when both are correct" do
316
- data = {"a" => 'Dog', "b" => '2017-05-22T14:51:44Z'}
312
+ it 'validates both pg_enum and dt format when both are correct' do
313
+ data = { 'a' => 'Dog', 'b' => '2017-05-22T14:51:44Z' }
317
314
  expect(JSON::Validator.validate(pg_dt_schema, data)).to be true
318
315
  end
319
316
 
320
- it "validates both pg_enum and dt format when only enum is correct" do
321
- data = {"a" => 'Dog', "b" => '2017-55-22T14:51:44Z'}
317
+ it 'validates both pg_enum and dt format when only enum is correct' do
318
+ data = { 'a' => 'Dog', 'b' => '2017-55-22T14:51:44Z' }
322
319
  expect(JSON::Validator.validate(pg_dt_schema, data)).to be false
323
320
  end
324
321
 
325
- it "validates both pg_enum and dt format when only dt is correct" do
326
- data = {"a" => 'Dogg', "b" => '2017-05-22T14:51:44Z'}
322
+ it 'validates both pg_enum and dt format when only dt is correct' do
323
+ data = { 'a' => 'Dogg', 'b' => '2017-05-22T14:51:44Z' }
327
324
  expect(JSON::Validator.validate(pg_dt_schema, data)).to be false
328
325
  end
329
326
 
330
- it "validates both pg_enum and dt format when neither is correct" do
331
- data = {"a" => 'Dogg', "b" => '2017-55-22T14:51:44Z'}
327
+ it 'validates both pg_enum and dt format when neither is correct' do
328
+ data = { 'a' => 'Dogg', 'b' => '2017-55-22T14:51:44Z' }
332
329
  expect(JSON::Validator.validate(pg_dt_schema, data)).to be false
333
330
  end
334
331
 
335
332
  pg_dt_int_schema = {
336
- "$schema" => "http://json-schema.org/marty-draft/schema#",
337
- "properties" => {
338
- "a" => {
339
- "pg_enum" => "MammalEnum"
333
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
334
+ 'properties' => {
335
+ 'a' => {
336
+ 'pg_enum' => 'MammalEnum'
340
337
  },
341
- "b" => {
342
- "type" => "string",
343
- "format" => "date-time"
338
+ 'b' => {
339
+ 'type' => 'string',
340
+ 'format' => 'date-time'
344
341
  },
345
- "c" => {
346
- "type" => "integer"
342
+ 'c' => {
343
+ 'type' => 'integer'
347
344
  },
348
345
  }
349
346
  }
350
347
 
351
- it "validates pg_enum, dt format and int when they are correct" do
352
- data = {"a" => 'Dog', "b" => '2017-05-22T14:51:44Z', "c" => 5}
348
+ it 'validates pg_enum, dt format and int when they are correct' do
349
+ data = { 'a' => 'Dog', 'b' => '2017-05-22T14:51:44Z', 'c' => 5 }
353
350
  expect(JSON::Validator.validate(pg_dt_int_schema, data)).to be true
354
351
  end
355
352
 
356
- it "validates pg_enum, dt format and int when one is incorrect" do
357
- data = {"a" => 'Chair', "b" => '2017-05-22T14:51:44Z', "c" => 5}
353
+ it 'validates pg_enum, dt format and int when one is incorrect' do
354
+ data = { 'a' => 'Chair', 'b' => '2017-05-22T14:51:44Z', 'c' => 5 }
358
355
  expect(JSON::Validator.validate(pg_dt_int_schema, data)).to be false
359
356
  end
360
357
 
361
358
  pg_dt_int_schema_req = {
362
- "$schema" => "http://json-schema.org/marty-draft/schema#",
363
- "required" => ["b"],
364
- "properties" => {
365
- "a" => {
366
- "pg_enum" => "MammalEnum"
359
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
360
+ 'required' => ['b'],
361
+ 'properties' => {
362
+ 'a' => {
363
+ 'pg_enum' => 'MammalEnum'
367
364
  },
368
- "b" => {
369
- "type" => "string",
370
- "format" => "date-time"
365
+ 'b' => {
366
+ 'type' => 'string',
367
+ 'format' => 'date-time'
371
368
  },
372
- "c" => {
373
- "type" => "integer"
369
+ 'c' => {
370
+ 'type' => 'integer'
374
371
  },
375
372
  }
376
373
  }
377
374
 
378
- it "validates pg_enum, dt format and int when dt is required" do
379
- data = {"a" => 'Dog', "d" => '2017-05-22T14:51:44Z', "c" => 5}
375
+ it 'validates pg_enum, dt format and int when dt is required' do
376
+ data = { 'a' => 'Dog', 'd' => '2017-05-22T14:51:44Z', 'c' => 5 }
380
377
  expect(JSON::Validator.validate(pg_dt_int_schema_req, data)).to be false
381
378
  end
382
379
 
383
380
  pg_dt_pg_int_schema = {
384
- "$schema" => "http://json-schema.org/marty-draft/schema#",
385
- "required" => ["c"],
386
- "properties" => {
387
- "a" => {
388
- "pg_enum" => "MammalEnum"
381
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
382
+ 'required' => ['c'],
383
+ 'properties' => {
384
+ 'a' => {
385
+ 'pg_enum' => 'MammalEnum'
389
386
  },
390
- "b" => {
391
- "type" => "string",
392
- "format" => "date-time"
387
+ 'b' => {
388
+ 'type' => 'string',
389
+ 'format' => 'date-time'
393
390
  },
394
- "c" => {
395
- "pg_enum" => "ElectronicsEnum"
391
+ 'c' => {
392
+ 'pg_enum' => 'ElectronicsEnum'
396
393
  },
397
- "d" => {
398
- "type" => "integer"
394
+ 'd' => {
395
+ 'type' => 'integer'
399
396
  },
400
397
  }
401
398
  }
402
399
 
403
- it "validates a schema containing 2 pg_enums, one that is required" do
404
- data = { "a" => 'Dog',
405
- "b" => '2017-05-22T14:51:44Z',
406
- "c" => 'Phone',
407
- "d" => 5 }
400
+ it 'validates a schema containing 2 pg_enums, one that is required' do
401
+ data = { 'a' => 'Dog',
402
+ 'b' => '2017-05-22T14:51:44Z',
403
+ 'c' => 'Phone',
404
+ 'd' => 5 }
408
405
  expect(JSON::Validator.validate(pg_dt_pg_int_schema, data)).to be true
409
406
  end
410
407
 
411
- it "validates a schema containing 2 pg_enums, one that is required" do
412
- data = { "a" => 'Dog',
413
- "b" => '2017-05-22T14:51:44Z',
414
- "e" => 'Phone',
415
- "d" => 5 }
408
+ it 'validates a schema containing 2 pg_enums, one that is required' do
409
+ data = { 'a' => 'Dog',
410
+ 'b' => '2017-05-22T14:51:44Z',
411
+ 'e' => 'Phone',
412
+ 'd' => 5 }
416
413
  expect(JSON::Validator.validate(pg_dt_pg_int_schema, data)).to be false
417
414
  end
418
415
 
@@ -421,207 +418,206 @@ module Marty
421
418
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
422
419
 
423
420
  nested_schema = {
424
- "$schema" => "http://json-schema.org/marty-draft/schema#",
425
- "required" => ["a", "b", "c", "d", "root1", "root2"],
426
- "properties" => {
427
- "a" => {
428
- "pg_enum" => "MammalEnum"
421
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
422
+ 'required' => ['a', 'b', 'c', 'd', 'root1', 'root2'],
423
+ 'properties' => {
424
+ 'a' => {
425
+ 'pg_enum' => 'MammalEnum'
429
426
  },
430
- "b" => {
431
- "type" => "string",
432
- "format" => "date-time"
427
+ 'b' => {
428
+ 'type' => 'string',
429
+ 'format' => 'date-time'
433
430
  },
434
- "c" => {
435
- "pg_enum" => "ElectronicsEnum"
431
+ 'c' => {
432
+ 'pg_enum' => 'ElectronicsEnum'
436
433
  },
437
- "d" => {
438
- "type" => "integer"
434
+ 'd' => {
435
+ 'type' => 'integer'
439
436
  },
440
- "root1" => {
441
- "type" => "array",
442
- "minItems" => 3,
443
- "items" => {
444
- "required" => ["x", "y"],
445
- "properties" => {
446
- "x" => { "type" => "object",
447
- "required" => ["w", "t", "f"],
448
- "properties" => { "w" => { "type" => "integer",
449
- "minimum" => 0,
450
- "maximum" => 3 },
451
- "t" => { "pg_enum" => "MammalEnum"},
452
- "f" => { "type" => ["number"],
453
- "minimum" => 0,
454
- "maximum" => 100,
455
- "multipleOf"=> 5.0 }}
437
+ 'root1' => {
438
+ 'type' => 'array',
439
+ 'minItems' => 3,
440
+ 'items' => {
441
+ 'required' => ['x', 'y'],
442
+ 'properties' => {
443
+ 'x' => { 'type' => 'object',
444
+ 'required' => ['w', 't', 'f'],
445
+ 'properties' => { 'w' => { 'type' => 'integer',
446
+ 'minimum' => 0,
447
+ 'maximum' => 3 },
448
+ 't' => { 'pg_enum' => 'MammalEnum' },
449
+ 'f' => { 'type' => ['number'],
450
+ 'minimum' => 0,
451
+ 'maximum' => 100,
452
+ 'multipleOf' => 5.0 } }
456
453
  },
457
- "y" => { "pg_enum" => "ElectronicsEnum" }
454
+ 'y' => { 'pg_enum' => 'ElectronicsEnum' }
458
455
  }
459
456
  }
460
457
  },
461
- "root2" => {
462
- "type" => "array",
463
- "minItems" => 2,
464
- "items" => {
465
- "required" => ["m1", "e", "m2"],
466
- "properties" => {
467
- "m1" => { "pg_enum" => "MammalEnum" },
468
- "e" => { "pg_enum" => "ElectronicsEnum" },
469
- "m2" => { "pg_enum" => "MammalEnum" },
458
+ 'root2' => {
459
+ 'type' => 'array',
460
+ 'minItems' => 2,
461
+ 'items' => {
462
+ 'required' => ['m1', 'e', 'm2'],
463
+ 'properties' => {
464
+ 'm1' => { 'pg_enum' => 'MammalEnum' },
465
+ 'e' => { 'pg_enum' => 'ElectronicsEnum' },
466
+ 'm2' => { 'pg_enum' => 'MammalEnum' },
470
467
  }
471
468
  },
472
469
  },
473
470
  }
474
471
  }
475
472
 
476
- it "validates a complex nested schema when correct" do
477
- data = { "a" => 'Dog',
478
- "b" => '2017-05-22T14:51:44Z',
479
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
480
- "y" => 'Phone' },
481
- { "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
482
- "y" => 'Terminator' },
483
- { "x" => {"w" => 2, "t" => 'Dog', "f" => 65.0},
484
- "y" => 'Phone' } ],
485
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
486
- {"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
487
- "c" => 'Terminator',
488
- "d" => 5
473
+ it 'validates a complex nested schema when correct' do
474
+ data = { 'a' => 'Dog',
475
+ 'b' => '2017-05-22T14:51:44Z',
476
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bear', 'f' => 0.0 },
477
+ 'y' => 'Phone' },
478
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 5.0 },
479
+ 'y' => 'Terminator' },
480
+ { 'x' => { 'w' => 2, 't' => 'Dog', 'f' => 65.0 },
481
+ 'y' => 'Phone' }],
482
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
483
+ { 'm1' => 'Dog', 'e' => 'Phone', 'm2' => 'Cow' }],
484
+ 'c' => 'Terminator',
485
+ 'd' => 5
489
486
  }
490
487
  expect(JSON::Validator.validate(nested_schema, data)).to be true
491
488
  end
492
489
 
493
- it "validates a complex nested schema when incorrect -- 1" do
494
- data = { "a" => 'Dog',
495
- "b" => '2017-05-32T14:51:44Z', # note DD
496
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
497
- "y" => 'Phone' },
498
- { "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
499
- "y" => 'Terminator' },
500
- { "x" => {"w" => 2, "t" => 'Dog', "f" => 65.0},
501
- "y" => 'Phone' } ],
502
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
503
- {"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
504
- "c" => 'Terminator',
505
- "d" => 5
490
+ it 'validates a complex nested schema when incorrect -- 1' do
491
+ data = { 'a' => 'Dog',
492
+ 'b' => '2017-05-32T14:51:44Z', # note DD
493
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bear', 'f' => 0.0 },
494
+ 'y' => 'Phone' },
495
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 5.0 },
496
+ 'y' => 'Terminator' },
497
+ { 'x' => { 'w' => 2, 't' => 'Dog', 'f' => 65.0 },
498
+ 'y' => 'Phone' }],
499
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
500
+ { 'm1' => 'Dog', 'e' => 'Phone', 'm2' => 'Cow' }],
501
+ 'c' => 'Terminator',
502
+ 'd' => 5
506
503
  }
507
504
  expect(JSON::Validator.validate(nested_schema, data)).to be false
508
505
  end
509
506
 
510
- it "validates a complex nested schema when incorrect -- 2" do
511
- data = { "a" => 'Dog',
512
- "b" => '2017-05-22T14:51:44Z',
513
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bar', "f" => 0.0}, #
514
- "y" => 'Phone' },
515
- { "x" => {"w" => 1, "t" => 'Human', "f" => 5},
516
- "y" => 'Terminator' },
517
- { "x" => {"w" => 2, "t" => 'Dog', "f" => 65.0},
518
- "y" => 'Phone' } ],
519
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
520
- {"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
521
- "c" => 'Terminator',
522
- "d" => 5
507
+ it 'validates a complex nested schema when incorrect -- 2' do
508
+ data = { 'a' => 'Dog',
509
+ 'b' => '2017-05-22T14:51:44Z',
510
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bar', 'f' => 0.0 },
511
+ 'y' => 'Phone' },
512
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 5 },
513
+ 'y' => 'Terminator' },
514
+ { 'x' => { 'w' => 2, 't' => 'Dog', 'f' => 65.0 },
515
+ 'y' => 'Phone' }],
516
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
517
+ { 'm1' => 'Dog', 'e' => 'Phone', 'm2' => 'Cow' }],
518
+ 'c' => 'Terminator',
519
+ 'd' => 5
523
520
  }
524
521
  expect(JSON::Validator.
525
522
  fully_validate(nested_schema, data, opt)[0]).to include(
526
- "property '#/root1/0/x/t' value 'Bar' not contained in MammalEnum")
527
- end
528
-
529
- it "validates a complex nested schema when incorrect -- 3" do
530
- data = { "a" => 'Dog',
531
- "b" => '2017-05-22T14:51:44Z',
532
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
533
- "y" => 'Phone' },
534
- { "x" => {"w" => 1, "t" => 'Human', "f" => 6.0}, #
535
- "y" => 'Terminator' },
536
- { "x" => {"w" => 2, "t" => 'Dog', "f" => 65.0},
537
- "y" => 'Phone' } ],
538
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
539
- {"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
540
- "c" => 'Terminator',
541
- "d" => 5
523
+ "property '#/root1/0/x/t' value 'Bar' not contained in MammalEnum")
524
+ end
525
+
526
+ it 'validates a complex nested schema when incorrect -- 3' do
527
+ data = { 'a' => 'Dog',
528
+ 'b' => '2017-05-22T14:51:44Z',
529
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bear', 'f' => 0.0 },
530
+ 'y' => 'Phone' },
531
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 6.0 },
532
+ 'y' => 'Terminator' },
533
+ { 'x' => { 'w' => 2, 't' => 'Dog', 'f' => 65.0 },
534
+ 'y' => 'Phone' }],
535
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
536
+ { 'm1' => 'Dog', 'e' => 'Phone', 'm2' => 'Cow' }],
537
+ 'c' => 'Terminator',
538
+ 'd' => 5
542
539
  }
543
540
  expect(JSON::Validator.
544
541
  fully_validate(nested_schema, data, opt)[0]).to include(
545
- "property '#/root1/1/x/f' was not divisible by 5.0")
546
- end
547
-
548
- it "validates a complex nested schema when incorrect -- 4" do
549
- data = { "a" => 'Dog',
550
- "b" => '2017-05-22T14:51:44Z',
551
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
552
- "y" => 'Phone' },
553
- { "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
554
- "y" => 'Trminator' }, #
555
- { "x" => {"w" => 2, "t" => 'Dog', "f" => 65.0},
556
- "y" => 'Phone' } ],
557
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
558
- {"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
559
- "c" => 'Terminator',
560
- "d" => 5
542
+ "property '#/root1/1/x/f' was not divisible by 5.0")
543
+ end
544
+
545
+ it 'validates a complex nested schema when incorrect -- 4' do
546
+ data = { 'a' => 'Dog',
547
+ 'b' => '2017-05-22T14:51:44Z',
548
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bear', 'f' => 0.0 },
549
+ 'y' => 'Phone' },
550
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 5.0 },
551
+ 'y' => 'Trminator' },
552
+ { 'x' => { 'w' => 2, 't' => 'Dog', 'f' => 65.0 },
553
+ 'y' => 'Phone' }],
554
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
555
+ { 'm1' => 'Dog', 'e' => 'Phone', 'm2' => 'Cow' }],
556
+ 'c' => 'Terminator',
557
+ 'd' => 5
561
558
  }
562
559
  expect(JSON::Validator.
563
560
  fully_validate(nested_schema, data, opt)[0]).to include(
564
- "property '#/root1/1/y' value 'Trminator' not contained "\
565
- "in ElectronicsEnum")
566
- end
567
-
568
- it "validates a complex nested schema when incorrect -- 5" do
569
- data = { "a" => 'Dog',
570
- "b" => '2017-05-22T14:51:44Z',
571
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
572
- "y" => 'Phone' },
573
- { "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
574
- "y" => 'Terminator' },
575
- { "x" => {"w" => 5, "t" => 'Dog', "f" => 65.0}, #
576
- "y" => 'Phone' } ],
577
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
578
- {"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
579
- "c" => 'Terminator',
580
- "d" => 5
561
+ "property '#/root1/1/y' value 'Trminator' not contained "\
562
+ 'in ElectronicsEnum')
563
+ end
564
+
565
+ it 'validates a complex nested schema when incorrect -- 5' do
566
+ data = { 'a' => 'Dog',
567
+ 'b' => '2017-05-22T14:51:44Z',
568
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bear', 'f' => 0.0 },
569
+ 'y' => 'Phone' },
570
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 5.0 },
571
+ 'y' => 'Terminator' },
572
+ { 'x' => { 'w' => 5, 't' => 'Dog', 'f' => 65.0 },
573
+ 'y' => 'Phone' }],
574
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
575
+ { 'm1' => 'Dog', 'e' => 'Phone', 'm2' => 'Cow' }],
576
+ 'c' => 'Terminator',
577
+ 'd' => 5
581
578
  }
582
579
  expect(JSON::Validator.
583
580
  fully_validate(nested_schema, data, opt)[0]).to include(
584
- "property '#/root1/2/x/w' did not have a maximum value of 3, inclusively")
585
- end
586
-
587
- it "validates a complex nested schema when incorrect -- 6" do
588
- data = { "a" => 'Dog',
589
- "b" => '2017-05-22T14:51:44Z',
590
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
591
- "y" => 'Phone' },
592
- { "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
593
- "y" => 'Terminator' },
594
- { "x" => {"w" => -5, "t" => 'Dog', "f" => 65.0}, #
595
- "y" => 'Phone' } ],
596
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
597
- {"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
598
- "c" => 'Terminator',
599
- "d" => 5
581
+ "property '#/root1/2/x/w' did not have a maximum value of 3, inclusively")
582
+ end
583
+
584
+ it 'validates a complex nested schema when incorrect -- 6' do
585
+ data = { 'a' => 'Dog',
586
+ 'b' => '2017-05-22T14:51:44Z',
587
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bear', 'f' => 0.0 },
588
+ 'y' => 'Phone' },
589
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 5.0 },
590
+ 'y' => 'Terminator' },
591
+ { 'x' => { 'w' => -5, 't' => 'Dog', 'f' => 65.0 },
592
+ 'y' => 'Phone' }],
593
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
594
+ { 'm1' => 'Dog', 'e' => 'Phone', 'm2' => 'Cow' }],
595
+ 'c' => 'Terminator',
596
+ 'd' => 5
600
597
  }
601
598
  expect(JSON::Validator.
602
599
  fully_validate(nested_schema, data, opt)[0]).to include(
603
- "property '#/root1/2/x/w' did not have a minimum value of 0, inclusively")
604
- end
605
-
606
- it "validates a complex nested schema when incorrect -- 7" do
607
- data = { "a" => 'Dog',
608
- "b" => '2017-05-22T14:51:44Z',
609
- "root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
610
- "y" => 'Phone' },
611
- { "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
612
- "y" => 'Terminator' },
613
- { "x" => {"w" => 2, "t" => 'Dog', "f" => 65.0},
614
- "y" => 'Phone' } ],
615
- "root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
616
- {"m1" => 'Dog', "e" => 'Dog', "m2" => 'Cow' }], #
617
- "c" => 'Terminator',
618
- "d" => 5
600
+ "property '#/root1/2/x/w' did not have a minimum value of 0, inclusively")
601
+ end
602
+
603
+ it 'validates a complex nested schema when incorrect -- 7' do
604
+ data = { 'a' => 'Dog',
605
+ 'b' => '2017-05-22T14:51:44Z',
606
+ 'root1' => [{ 'x' => { 'w' => 0, 't' => 'Bear', 'f' => 0.0 },
607
+ 'y' => 'Phone' },
608
+ { 'x' => { 'w' => 1, 't' => 'Human', 'f' => 5.0 },
609
+ 'y' => 'Terminator' },
610
+ { 'x' => { 'w' => 2, 't' => 'Dog', 'f' => 65.0 },
611
+ 'y' => 'Phone' }],
612
+ 'root2' => [{ 'm1' => 'Cat', 'e' => 'Keyboard', 'm2' => 'Dog' },
613
+ { 'm1' => 'Dog', 'e' => 'Dog', 'm2' => 'Cow' }],
614
+ 'c' => 'Terminator',
615
+ 'd' => 5
619
616
  }
620
617
  expect(JSON::Validator.
621
618
  fully_validate(nested_schema, data, opt)[0]).to include(
622
- "property '#/root2/1/e' value 'Dog' not contained in ElectronicsEnum")
619
+ "property '#/root2/1/e' value 'Dog' not contained in ElectronicsEnum")
623
620
  end
624
-
625
621
  end
626
622
 
627
623
  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
@@ -631,7 +627,7 @@ module Marty
631
627
  class FloorOf8 < JSON::Schema::Attribute
632
628
  def self.validate(curr_schema, data, frag, processor, validator, opt)
633
629
  if data < 8
634
- msg = "Error at FloorOf8: Value is below 8"
630
+ msg = 'Error at FloorOf8: Value is below 8'
635
631
  validation_error(processor,
636
632
  msg,
637
633
  frag,
@@ -645,7 +641,7 @@ module Marty
645
641
  class CeilingOf20 < JSON::Schema::Attribute
646
642
  def self.validate(curr_schema, data, frag, processor, validator, opt)
647
643
  if data > 20
648
- msg = "Error at CeilingOf20: Value exceeds 20"
644
+ msg = 'Error at CeilingOf20: Value exceeds 20'
649
645
  validation_error(processor,
650
646
  msg,
651
647
  frag,
@@ -656,121 +652,115 @@ module Marty
656
652
  end
657
653
  end
658
654
 
659
-
660
- describe "how @uri behaves as a key to a set of attributes" do
661
-
655
+ describe 'how @uri behaves as a key to a set of attributes' do
662
656
  class BoundSchema < JSON::Schema::Draft4
663
657
  def initialize
664
658
  super
665
- @attributes["bound"] = CeilingOf20
666
- uri = "http://json-schema.org/bound-draft/schema#"
659
+ @attributes['bound'] = CeilingOf20
660
+ uri = 'http://json-schema.org/bound-draft/schema#'
667
661
  @uri = JSON::Util::URI.parse(uri)
668
662
  end
669
663
 
670
- JSON::Validator.register_validator(self.new)
664
+ JSON::Validator.register_validator(new)
671
665
  end
672
666
 
673
667
  marty_uri = {
674
- "$schema" => "http://json-schema.org/marty-draft/schema#",
675
- "required" => ["a"],
676
- "properties" => {
677
- "a" => {
678
- "pg_enum" => "MammalEnum",
668
+ '$schema' => 'http://json-schema.org/marty-draft/schema#',
669
+ 'required' => ['a'],
670
+ 'properties' => {
671
+ 'a' => {
672
+ 'pg_enum' => 'MammalEnum',
679
673
  },
680
674
  }
681
675
  }
682
676
 
683
677
  bound_uri = {
684
- "$schema" => "http://json-schema.org/bound-draft/schema#",
685
- "required" => ["a"],
686
- "properties" => {
687
- "a" => {
688
- "pg_enum" => "MammalEnum",
678
+ '$schema' => 'http://json-schema.org/bound-draft/schema#',
679
+ 'required' => ['a'],
680
+ 'properties' => {
681
+ 'a' => {
682
+ 'pg_enum' => 'MammalEnum',
689
683
  },
690
684
  }
691
685
  }
692
686
 
693
- it "validates an attribute dictated by its uri (Positive)" do
694
- data = {"a" => 'Dog'}
687
+ it 'validates an attribute dictated by its uri (Positive)' do
688
+ data = { 'a' => 'Dog' }
695
689
  expect(JSON::Validator.validate(marty_uri, data)).to be true
696
690
  end
697
691
 
698
- it "validates an attribute dictated by its uri (Negative)" do
699
- data = {"a" => 'Table'}
692
+ it 'validates an attribute dictated by its uri (Negative)' do
693
+ data = { 'a' => 'Table' }
700
694
  expect(JSON::Validator.validate(marty_uri, data)).to be false
701
695
  end
702
696
 
703
- it "incorrectly validates an attribute not part of its uri" do
704
- data = {"a" => 'Table'}
697
+ it 'incorrectly validates an attribute not part of its uri' do
698
+ data = { 'a' => 'Table' }
705
699
  expect(JSON::Validator.validate(bound_uri, data)).to be true
706
700
  end
707
-
708
701
  end
709
702
 
710
- describe "how @uri also behaves as namespace" do
711
-
703
+ describe 'how @uri also behaves as namespace' do
712
704
  class BoundFloorSchema < JSON::Schema::Draft4
713
705
  def initialize
714
706
  super
715
- @attributes["bound"] = FloorOf8
716
- uri = "http://json-schema.org/bound-floor-draft/schema#"
707
+ @attributes['bound'] = FloorOf8
708
+ uri = 'http://json-schema.org/bound-floor-draft/schema#'
717
709
  @uri = JSON::Util::URI.parse(uri)
718
710
  end
719
711
 
720
- JSON::Validator.register_validator(self.new)
712
+ JSON::Validator.register_validator(new)
721
713
  end
722
714
 
723
715
  class BoundCeilingSchema < JSON::Schema::Draft4
724
716
  def initialize
725
717
  super
726
- @attributes["bound"] = CeilingOf20
727
- uri = "http://json-schema.org/bound-ceiling-draft/schema#"
718
+ @attributes['bound'] = CeilingOf20
719
+ uri = 'http://json-schema.org/bound-ceiling-draft/schema#'
728
720
  @uri = JSON::Util::URI.parse(uri)
729
721
  end
730
722
 
731
- JSON::Validator.register_validator(self.new)
723
+ JSON::Validator.register_validator(new)
732
724
  end
733
725
 
734
726
  bound_floor_schema = {
735
- "$schema" => "http://json-schema.org/bound-floor-draft/schema#",
736
- "required" => ["a"],
737
- "properties" => {
738
- "a" => {
739
- "bound" => "",
727
+ '$schema' => 'http://json-schema.org/bound-floor-draft/schema#',
728
+ 'required' => ['a'],
729
+ 'properties' => {
730
+ 'a' => {
731
+ 'bound' => '',
740
732
  },
741
733
  }
742
734
  }
743
735
 
744
736
  bound_ceiling_schema = {
745
- "$schema" => "http://json-schema.org/bound-ceiling-draft/schema#",
746
- "required" => ["a"],
747
- "properties" => {
748
- "a" => {
749
- "bound" => "",
737
+ '$schema' => 'http://json-schema.org/bound-ceiling-draft/schema#',
738
+ 'required' => ['a'],
739
+ 'properties' => {
740
+ 'a' => {
741
+ 'bound' => '',
750
742
  },
751
743
  }
752
744
  }
753
745
 
754
- it "validates BoundFloorSchema when called with its uri (Positive)" do
755
- data = {"a" => 9}
746
+ it 'validates BoundFloorSchema when called with its uri (Positive)' do
747
+ data = { 'a' => 9 }
756
748
  expect(JSON::Validator.validate(bound_floor_schema, data)).to be true
757
749
  end
758
750
 
759
- it "validates BoundFloorSchema when called with its uri (Negative)" do
760
- data = {"a" => 7}
751
+ it 'validates BoundFloorSchema when called with its uri (Negative)' do
752
+ data = { 'a' => 7 }
761
753
  expect(JSON::Validator.validate(bound_floor_schema, data)).to be false
762
754
  end
763
755
 
764
- it "validates BoundCeilingSchema when called with its uri (Positive)" do
765
- data = {"a" => 19}
756
+ it 'validates BoundCeilingSchema when called with its uri (Positive)' do
757
+ data = { 'a' => 19 }
766
758
  expect(JSON::Validator.validate(bound_ceiling_schema, data)).to be true
767
759
  end
768
760
 
769
- it "validates BoundCielingSchema when called with its uri (Negative)" do
770
- data = {"a" => 21}
761
+ it 'validates BoundCielingSchema when called with its uri (Negative)' do
762
+ data = { 'a' => 21 }
771
763
  expect(JSON::Validator.validate(bound_ceiling_schema, data)).to be false
772
764
  end
773
-
774
765
  end
775
-
776
766
  end