json-schema-openc-fork 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE.md +19 -0
  3. data/README.textile +452 -0
  4. data/lib/json-schema.rb +19 -0
  5. data/lib/json-schema/attribute.rb +43 -0
  6. data/lib/json-schema/attributes/additionalitems.rb +28 -0
  7. data/lib/json-schema/attributes/additionalproperties.rb +58 -0
  8. data/lib/json-schema/attributes/allof.rb +39 -0
  9. data/lib/json-schema/attributes/anyof.rb +47 -0
  10. data/lib/json-schema/attributes/dependencies.rb +44 -0
  11. data/lib/json-schema/attributes/disallow.rb +12 -0
  12. data/lib/json-schema/attributes/divisibleby.rb +22 -0
  13. data/lib/json-schema/attributes/enum.rb +24 -0
  14. data/lib/json-schema/attributes/extends.rb +50 -0
  15. data/lib/json-schema/attributes/format.rb +14 -0
  16. data/lib/json-schema/attributes/formats/custom.rb +21 -0
  17. data/lib/json-schema/attributes/formats/date.rb +24 -0
  18. data/lib/json-schema/attributes/formats/date_time.rb +36 -0
  19. data/lib/json-schema/attributes/formats/date_time_v4.rb +15 -0
  20. data/lib/json-schema/attributes/formats/ip.rb +41 -0
  21. data/lib/json-schema/attributes/formats/time.rb +22 -0
  22. data/lib/json-schema/attributes/formats/uri.rb +20 -0
  23. data/lib/json-schema/attributes/items.rb +26 -0
  24. data/lib/json-schema/attributes/limit.rb +179 -0
  25. data/lib/json-schema/attributes/maxdecimal.rb +18 -0
  26. data/lib/json-schema/attributes/multipleof.rb +11 -0
  27. data/lib/json-schema/attributes/not.rb +30 -0
  28. data/lib/json-schema/attributes/oneof.rb +56 -0
  29. data/lib/json-schema/attributes/pattern.rb +18 -0
  30. data/lib/json-schema/attributes/patternproperties.rb +22 -0
  31. data/lib/json-schema/attributes/properties.rb +74 -0
  32. data/lib/json-schema/attributes/properties_optional.rb +26 -0
  33. data/lib/json-schema/attributes/ref.rb +74 -0
  34. data/lib/json-schema/attributes/required.rb +28 -0
  35. data/lib/json-schema/attributes/type.rb +83 -0
  36. data/lib/json-schema/attributes/type_v4.rb +29 -0
  37. data/lib/json-schema/attributes/uniqueitems.rb +16 -0
  38. data/lib/json-schema/errors/custom_format_error.rb +6 -0
  39. data/lib/json-schema/errors/json_parse_error.rb +6 -0
  40. data/lib/json-schema/errors/schema_error.rb +6 -0
  41. data/lib/json-schema/errors/validation_error.rb +46 -0
  42. data/lib/json-schema/schema.rb +63 -0
  43. data/lib/json-schema/schema/reader.rb +113 -0
  44. data/lib/json-schema/schema/validator.rb +36 -0
  45. data/lib/json-schema/util/array_set.rb +14 -0
  46. data/lib/json-schema/util/uri.rb +16 -0
  47. data/lib/json-schema/util/uuid.rb +285 -0
  48. data/lib/json-schema/validator.rb +592 -0
  49. data/lib/json-schema/validators/draft1.rb +45 -0
  50. data/lib/json-schema/validators/draft2.rb +46 -0
  51. data/lib/json-schema/validators/draft3.rb +50 -0
  52. data/lib/json-schema/validators/draft4.rb +56 -0
  53. data/lib/json-schema/validators/hyper-draft4.rb +14 -0
  54. data/resources/draft-01.json +155 -0
  55. data/resources/draft-02.json +166 -0
  56. data/resources/draft-03.json +174 -0
  57. data/resources/draft-04.json +150 -0
  58. data/test/data/all_of_ref_data.json +3 -0
  59. data/test/data/any_of_ref_data.json +7 -0
  60. data/test/data/bad_data_1.json +3 -0
  61. data/test/data/good_data_1.json +3 -0
  62. data/test/data/one_of_ref_links_data.json +5 -0
  63. data/test/schemas/address_microformat.json +18 -0
  64. data/test/schemas/all_of_ref_base_schema.json +6 -0
  65. data/test/schemas/all_of_ref_schema.json +7 -0
  66. data/test/schemas/any_of_ref_jane_schema.json +4 -0
  67. data/test/schemas/any_of_ref_jimmy_schema.json +4 -0
  68. data/test/schemas/any_of_ref_john_schema.json +4 -0
  69. data/test/schemas/any_of_ref_schema.json +15 -0
  70. data/test/schemas/definition_schema.json +15 -0
  71. data/test/schemas/extends_and_additionalProperties-1-filename.schema.json +34 -0
  72. data/test/schemas/extends_and_additionalProperties-1-ref.schema.json +34 -0
  73. data/test/schemas/extends_and_additionalProperties-2-filename.schema.json +33 -0
  74. data/test/schemas/extends_and_additionalProperties-2-ref.schema.json +33 -0
  75. data/test/schemas/good_schema_1.json +10 -0
  76. data/test/schemas/good_schema_2.json +10 -0
  77. data/test/schemas/good_schema_extends1.json +10 -0
  78. data/test/schemas/good_schema_extends2.json +13 -0
  79. data/test/schemas/inner.schema.json +21 -0
  80. data/test/schemas/one_of_ref_links_schema.json +16 -0
  81. data/test/schemas/ref john with spaces schema.json +11 -0
  82. data/test/schemas/relative_definition_schema.json +8 -0
  83. data/test/schemas/self_link_schema.json +17 -0
  84. data/test/schemas/up_link_schema.json +17 -0
  85. data/test/test_all_of_ref_schema.rb +35 -0
  86. data/test/test_any_of_ref_schema.rb +35 -0
  87. data/test/test_bad_schema_ref.rb +39 -0
  88. data/test/test_common_test_suite.rb +66 -0
  89. data/test/test_custom_format.rb +116 -0
  90. data/test/test_definition.rb +15 -0
  91. data/test/test_extended_schema.rb +62 -0
  92. data/test/test_extends_and_additionalProperties.rb +52 -0
  93. data/test/test_files_v3.rb +43 -0
  94. data/test/test_fragment_resolution.rb +30 -0
  95. data/test/test_fragment_validation_with_ref.rb +34 -0
  96. data/test/test_full_validation.rb +208 -0
  97. data/test/test_helper.rb +47 -0
  98. data/test/test_initialize_data.rb +118 -0
  99. data/test/test_jsonschema_draft1.rb +171 -0
  100. data/test/test_jsonschema_draft2.rb +142 -0
  101. data/test/test_jsonschema_draft3.rb +502 -0
  102. data/test/test_jsonschema_draft4.rb +704 -0
  103. data/test/test_list_option.rb +21 -0
  104. data/test/test_merge_missing_values.rb +45 -0
  105. data/test/test_minitems.rb +16 -0
  106. data/test/test_one_of.rb +85 -0
  107. data/test/test_ruby_schema.rb +59 -0
  108. data/test/test_schema_loader.rb +74 -0
  109. data/test/test_schema_type_attribute.rb +20 -0
  110. data/test/test_schema_validation.rb +185 -0
  111. data/test/test_stringify.rb +48 -0
  112. data/test/test_uri_related.rb +67 -0
  113. data/test/test_validator.rb +53 -0
  114. metadata +284 -0
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class ListOptionTest < Minitest::Test
4
+ def test_list_option_reusing_schemas
5
+ schema_hash = {
6
+ "$schema" => "http://json-schema.org/draft-04/schema#",
7
+ "type" => "object",
8
+ "properties" => { "a" => { "type" => "integer" } }
9
+ }
10
+
11
+ uri = Addressable::URI.parse('http://example.com/item')
12
+ schema = JSON::Schema.new(schema_hash, uri)
13
+ JSON::Validator.add_schema(schema)
14
+
15
+ data = {"a" => 1}
16
+ assert_valid uri.to_s, data
17
+
18
+ data = [{"a" => 1}]
19
+ assert_valid uri.to_s, data, :list => true
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class MergeMissingValuesTest < Minitest::Test
4
+ def test_merge_missing_values_for_string
5
+ original = 'foo'
6
+ updated = 'foo'
7
+ JSON::Validator.merge_missing_values(updated, original)
8
+ assert_equal('foo', original)
9
+ end
10
+
11
+ def test_merge_missing_values_for_empty_array
12
+ original = []
13
+ updated = []
14
+ JSON::Validator.merge_missing_values(updated, original)
15
+ assert_equal([], original)
16
+ end
17
+
18
+ def test_merge_missing_values_for_empty_hash
19
+ original = {}
20
+ updated = {}
21
+ JSON::Validator.merge_missing_values(updated, original)
22
+ assert_equal({}, original)
23
+ end
24
+
25
+ def test_merge_missing_values_for_new_values
26
+ original = {:hello => 'world'}
27
+ updated = {'hello' => 'world', 'foo' => 'bar'}
28
+ JSON::Validator.merge_missing_values(updated, original)
29
+ assert_equal({:hello => 'world', 'foo' => 'bar'}, original)
30
+ end
31
+
32
+ def test_merge_missing_values_for_nested_array
33
+ original = [:hello, 'world', 1, 2, 3, {:foo => :bar, 'baz' => 'qux'}]
34
+ updated = ['hello', 'world', 1, 2, 3, {'foo' => 'bar', 'baz' => 'qux', 'this_is' => 'new'}]
35
+ JSON::Validator.merge_missing_values(updated, original)
36
+ assert_equal([:hello, 'world', 1, 2, 3, {:foo => :bar, 'baz' => 'qux', 'this_is' => 'new'}], original)
37
+ end
38
+
39
+ def test_merge_missing_values_for_nested_hash
40
+ original = {:hello => 'world', :foo => ['bar', :baz, {:uno => {:due => 3}}]}
41
+ updated = {'hello' => 'world', 'foo' => ['bar', 'baz', {'uno' => {'due' => 3, 'this_is' => 'new'}}], 'ack' => 'sed'}
42
+ JSON::Validator.merge_missing_values(updated, original)
43
+ assert_equal({:hello => 'world', :foo => ['bar', :baz, {:uno => {:due => 3, 'this_is' => 'new'}}], 'ack' => 'sed'}, original)
44
+ end
45
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class MinItemsTest < Minitest::Test
4
+ def test_minitems_nils
5
+ schema = {
6
+ "type" => "array",
7
+ "minItems" => 1,
8
+ "items" => { "type" => "object" }
9
+ }
10
+
11
+ errors = JSON::Validator.fully_validate(schema, [nil])
12
+ assert_equal(errors.length, 1)
13
+ assert(errors[0] !~ /minimum/)
14
+ assert(errors[0] =~ /NilClass/)
15
+ end
16
+ end
@@ -0,0 +1,85 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class OneOfTest < Minitest::Test
4
+ def test_one_of_links_schema
5
+ schema = schema_fixture_path('one_of_ref_links_schema.json')
6
+ data = data_fixture_path('one_of_ref_links_data.json')
7
+ assert_valid schema, data
8
+ end
9
+
10
+ def test_one_of_with_string_patterns
11
+ schema = {
12
+ "$schema" => "http://json-schema.org/draft-04/schema#",
13
+ "oneOf" => [
14
+ {
15
+ "properties" => {"a" => {"type" => "string", "pattern" => "foo"}},
16
+ },
17
+ {
18
+ "properties" => {"a" => {"type" => "string", "pattern" => "bar"}},
19
+ },
20
+ {
21
+ "properties" => {"a" => {"type" => "string", "pattern" => "baz"}},
22
+ }
23
+ ]
24
+ }
25
+
26
+ assert_valid schema, { "a" => "foo" }
27
+ refute_valid schema, { "a" => "foobar" }
28
+ assert_valid schema, { "a" => "baz" }
29
+ refute_valid schema, { "a" => 5 }
30
+ end
31
+
32
+ def test_one_of_sub_errors
33
+ schema = {
34
+ "$schema" => "http://json-schema.org/draft-04/schema#",
35
+ "oneOf" => [
36
+ {
37
+ "properties" => {"a" => {"type" => "string", "pattern" => "foo"}},
38
+ },
39
+ {
40
+ "properties" => {"a" => {"type" => "string", "pattern" => "bar"}},
41
+ },
42
+ {
43
+ "properties" => {"a" => {"type" => "number", "minimum" => 10}},
44
+ }
45
+ ]
46
+ }
47
+
48
+ errors = JSON::Validator.fully_validate(schema, { "a" => 5 }, :errors_as_objects => true)
49
+ nested_errors = errors[0][:errors]
50
+ assert_equal([:oneof_0,:oneof_1,:oneof_2], nested_errors.keys, 'should have nested errors for each allOf subschema')
51
+ assert_match(/the property '#\/a' of type Fixnum did not match the following type: string/i, nested_errors[:oneof_0][0][:message])
52
+ assert_match(/the property '#\/a' did not have a minimum value of 10, inclusively/i, nested_errors[:oneof_2][0][:message])
53
+ end
54
+
55
+ def test_one_of_sub_errors_message
56
+ schema = {
57
+ "$schema" => "http://json-schema.org/draft-04/schema#",
58
+ "oneOf" => [
59
+ {
60
+ "properties" => {"a" => {"type" => "string", "pattern" => "foo"}},
61
+ },
62
+ {
63
+ "properties" => {"a" => {"type" => "string", "pattern" => "bar"}},
64
+ },
65
+ {
66
+ "properties" => {"a" => {"type" => "number", "minimum" => 10}},
67
+ }
68
+ ]
69
+ }
70
+
71
+ errors = JSON::Validator.fully_validate(schema, { "a" => 5 })
72
+ expected_message = """The property '#/' of type Hash did not match any of the required schemas. The schema specific errors were:
73
+
74
+ - oneOf #0:
75
+ - The property '#/a' of type Fixnum did not match the following type: string
76
+ - oneOf #1:
77
+ - The property '#/a' of type Fixnum did not match the following type: string
78
+ - oneOf #2:
79
+ - The property '#/a' did not have a minimum value of 10, inclusively"""
80
+
81
+ assert_equal(expected_message, errors[0])
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class RubySchemaTest < Minitest::Test
4
+ def test_string_keys
5
+ schema = {
6
+ "type" => 'object',
7
+ "required" => ["a"],
8
+ "properties" => {
9
+ "a" => {"type" => "integer", "default" => 42},
10
+ "b" => {"type" => "integer"}
11
+ }
12
+ }
13
+
14
+ assert_valid schema, { "a" => 5 }
15
+ end
16
+
17
+ def test_symbol_keys
18
+ schema = {
19
+ :type => 'object',
20
+ :required => ["a"],
21
+ :properties => {
22
+ :a => {:type => "integer", :default => 42},
23
+ :b => {:type => "integer"}
24
+ }
25
+ }
26
+
27
+ assert_valid schema, { :a => 5 }
28
+ end
29
+
30
+ def test_symbol_keys_in_hash_within_array
31
+ schema = {
32
+ :type => 'object',
33
+ :properties => {
34
+ :a => {
35
+ :type => "array",
36
+ :items => [
37
+ {
38
+ :properties => {
39
+ :b => {
40
+ :type => "integer"
41
+ }
42
+ }
43
+ }
44
+ ]
45
+ }
46
+ }
47
+ }
48
+
49
+ data = {
50
+ :a => [
51
+ {
52
+ :b => 1
53
+ }
54
+ ]
55
+ }
56
+
57
+ assert_valid schema, data, :validate_schema => true
58
+ end
59
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestSchemaReader < Minitest::Test
4
+ ADDRESS_SCHEMA_URI = 'http://json-schema.org/address'
5
+ ADDRESS_SCHEMA_PATH = File.expand_path('../schemas/address_microformat.json', __FILE__)
6
+
7
+ def stub_address_request(body = File.read(ADDRESS_SCHEMA_PATH))
8
+ stub_request(:get, ADDRESS_SCHEMA_URI).
9
+ to_return(:body => body, :status => 200)
10
+ end
11
+
12
+ def test_accept_all_uris
13
+ stub_address_request
14
+
15
+ reader = JSON::Schema::Reader.new
16
+ schema = reader.read(ADDRESS_SCHEMA_URI)
17
+
18
+ assert_equal schema.uri, Addressable::URI.parse("#{ADDRESS_SCHEMA_URI}#")
19
+ end
20
+
21
+ def test_accept_all_files
22
+ reader = JSON::Schema::Reader.new
23
+ schema = reader.read(ADDRESS_SCHEMA_PATH)
24
+
25
+ assert_equal schema.uri, Addressable::URI.convert_path(ADDRESS_SCHEMA_PATH + '#')
26
+ end
27
+
28
+ def test_refuse_all_uris
29
+ reader = JSON::Schema::Reader.new(:accept_uri => false)
30
+ refute reader.accept_uri?(Addressable::URI.parse('http://foo.com'))
31
+ end
32
+
33
+ def test_refuse_all_files
34
+ reader = JSON::Schema::Reader.new(:accept_file => false)
35
+ refute reader.accept_file?(Pathname.new('/foo/bar/baz'))
36
+ end
37
+
38
+ def test_accept_uri_proc
39
+ reader = JSON::Schema::Reader.new(
40
+ :accept_uri => proc { |uri| uri.host == 'json-schema.org' }
41
+ )
42
+
43
+ assert reader.accept_uri?(Addressable::URI.parse('http://json-schema.org/address'))
44
+ refute reader.accept_uri?(Addressable::URI.parse('http://sub.json-schema.org/address'))
45
+ end
46
+
47
+ def test_accept_file_proc
48
+ test_root = Pathname.new(__FILE__).expand_path.dirname
49
+
50
+ reader = JSON::Schema::Reader.new(
51
+ :accept_file => proc { |path| path.to_s.start_with?(test_root.to_s) }
52
+ )
53
+
54
+ assert reader.accept_file?(test_root.join('anything.json'))
55
+ refute reader.accept_file?(test_root.join('..', 'anything.json'))
56
+ end
57
+
58
+ def test_file_scheme
59
+ reader = JSON::Schema::Reader.new(:accept_uri => true, :accept_file => false)
60
+ assert_raises(JSON::Schema::ReadRefused) do
61
+ reader.read('file://' + ADDRESS_SCHEMA_PATH)
62
+ end
63
+ end
64
+
65
+ def test_parse_error
66
+ stub_address_request('this is totally not valid JSON!')
67
+
68
+ reader = JSON::Schema::Reader.new
69
+
70
+ assert_raises(parser_error) do
71
+ reader.read(ADDRESS_SCHEMA_URI)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestSchemaTypeAttribute < Minitest::Test
4
+ def test_type_of_data
5
+ assert_equal(type_of_data(String.new), 'string')
6
+ assert_equal(type_of_data(Numeric.new), 'number')
7
+ assert_equal(type_of_data(1), 'integer')
8
+ assert_equal(type_of_data(true), 'boolean')
9
+ assert_equal(type_of_data(false), 'boolean')
10
+ assert_equal(type_of_data(Hash.new), 'object')
11
+ assert_equal(type_of_data(nil), 'null')
12
+ assert_equal(type_of_data(Object.new), 'any')
13
+ end
14
+
15
+ private
16
+
17
+ def type_of_data(data)
18
+ JSON::Schema::TypeAttribute.type_of_data(data)
19
+ end
20
+ end
@@ -0,0 +1,185 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+ require 'tmpdir'
3
+
4
+ class JSONSchemaValidation < Minitest::Test
5
+ def valid_schema_v3
6
+ {
7
+ "$schema" => "http://json-schema.org/draft-03/schema#",
8
+ "type" => "object",
9
+ "properties" => {
10
+ "b" => {
11
+ "required" => true
12
+ }
13
+ }
14
+ }
15
+ end
16
+
17
+ def invalid_schema_v3
18
+ {
19
+ "$schema" => "http://json-schema.org/draft-03/schema#",
20
+ "type" => "object",
21
+ "properties" => {
22
+ "b" => {
23
+ "required" => "true"
24
+ }
25
+ }
26
+ }
27
+ end
28
+
29
+ def valid_schema_v4
30
+ {
31
+ "$schema" => "http://json-schema.org/draft-04/schema#",
32
+ "type" => "object",
33
+ "required" => ["b"],
34
+ "properties" => {
35
+ }
36
+ }
37
+ end
38
+
39
+ def invalid_schema_v4
40
+ {
41
+ "$schema" => "http://json-schema.org/draft-04/schema#",
42
+ "type" => "object",
43
+ "required" => "b",
44
+ "properties" => {
45
+ }
46
+ }
47
+ end
48
+
49
+ def symbolized_schema
50
+ {
51
+ :type => :object,
52
+ :required => [
53
+ :id,
54
+ :name,
55
+ :real_name,
56
+ :role,
57
+ :website,
58
+ :biography,
59
+ :created_at,
60
+ :demographic
61
+ ],
62
+ :properties => {
63
+ :id => {
64
+ :type => [
65
+ :integer
66
+ ]
67
+ },
68
+ :name => {
69
+ :type => [
70
+ :string
71
+ ]
72
+ },
73
+ :real_name => {
74
+ :type => [
75
+ :string
76
+ ]
77
+ },
78
+ :role => {
79
+ :type => [
80
+ :string
81
+ ]
82
+ },
83
+ :website => {
84
+ :type => [
85
+ :string,
86
+ :null
87
+ ]
88
+ },
89
+ :created_at => {
90
+ :type => [
91
+ :string
92
+ ]
93
+ },
94
+ :biography => {
95
+ :type => [
96
+ :string,
97
+ :null
98
+ ]
99
+ }
100
+ },
101
+ :relationships => {
102
+ :demographic => {
103
+ :type => :object,
104
+ :required => [
105
+ :id,
106
+ :gender
107
+ ],
108
+ :properties => {
109
+ :id => {
110
+ :type => [
111
+ :integer
112
+ ]
113
+ },
114
+ :gender => {
115
+ :type => [
116
+ :string
117
+ ]
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ end
124
+
125
+ def test_draft03_validation
126
+ data = {"b" => {"a" => 5}}
127
+ assert(JSON::Validator.validate(valid_schema_v3,data,:validate_schema => true, :version => :draft3))
128
+ assert(!JSON::Validator.validate(invalid_schema_v3,data,:validate_schema => true, :version => :draft3))
129
+ end
130
+
131
+ def test_validate_just_schema_draft03
132
+ errors = JSON::Validator.fully_validate_schema(valid_schema_v3, :version => :draft3)
133
+ assert_equal [], errors
134
+
135
+ errors = JSON::Validator.fully_validate_schema(invalid_schema_v3, :version => :draft3)
136
+ assert_equal 1, errors.size
137
+ assert_match(/the property .*required.*did not match/i, errors.first)
138
+ end
139
+
140
+
141
+ def test_draft04_validation
142
+ data = {"b" => {"a" => 5}}
143
+ assert(JSON::Validator.validate(valid_schema_v4,data,:validate_schema => true, :version => :draft4))
144
+ assert(!JSON::Validator.validate(invalid_schema_v4,data,:validate_schema => true, :version => :draft4))
145
+ end
146
+
147
+ def test_validate_just_schema_draft04
148
+ errors = JSON::Validator.fully_validate_schema(valid_schema_v4, :version => :draft4)
149
+ assert_equal [], errors
150
+
151
+ errors = JSON::Validator.fully_validate_schema(invalid_schema_v4, :version => :draft4)
152
+ assert_equal 1, errors.size
153
+ assert_match(/the property .*required.*did not match/i, errors.first)
154
+ end
155
+
156
+ def test_validate_schema_3_without_version_option
157
+ data = {"b" => {"a" => 5}}
158
+ assert(JSON::Validator.validate(valid_schema_v3,data,:validate_schema => true))
159
+ assert(!JSON::Validator.validate(invalid_schema_v3,data,:validate_schema => true))
160
+ end
161
+
162
+ def test_schema_validation_from_different_directory
163
+ Dir.mktmpdir do |tmpdir|
164
+ Dir.chdir(tmpdir) do
165
+ data = {"b" => {"a" => 5}}
166
+ assert(JSON::Validator.validate(valid_schema_v4,data,:validate_schema => true, :version => :draft4))
167
+ assert(!JSON::Validator.validate(invalid_schema_v4,data,:validate_schema => true, :version => :draft4))
168
+ end
169
+ end
170
+ end
171
+
172
+ def test_validate_schema_with_symbol_keys
173
+ data = {
174
+ "created_at" => "2014-01-25T00:58:33-08:00",
175
+ "id" => 8517194300913402149003,
176
+ "name" => "chelsey",
177
+ "real_name" => "Mekhi Hegmann",
178
+ "website" => nil,
179
+ "role" => "user",
180
+ "biography" => nil,
181
+ "demographic" => nil
182
+ }
183
+ assert(JSON::Validator.validate!(symbolized_schema, data, :validate_schema => true))
184
+ end
185
+ end