File: load_ref_schema_test.rb

package info (click to toggle)
ruby-json-schema 2.8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 896 kB
  • sloc: ruby: 5,806; makefile: 6
file content (45 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require File.expand_path('../support/test_helper', __FILE__)

class LoadRefSchemaTest < Minitest::Test
  def load_other_schema
    JSON::Validator.add_schema(JSON::Schema.new(
      {
        '$schema' => 'http://json-schema.org/draft-04/schema#',
        'type' => 'object',
        'properties' => {
          "title" => {
            "type" => "string"
          }
        }
      },
      Addressable::URI.parse("http://example.com/schema#")
    ))
  end

  def test_cached_schema
    schema_url = "http://example.com/schema#"
    schema = { "$ref" => schema_url }
    data = {}
    load_other_schema
    _validator = JSON::Validator.new(schema, data)

    assert JSON::Validator.schema_loaded?(schema_url)
  end

  def test_cached_schema_with_fragment
    schema_url = "http://example.com/schema#"
    schema = { "$ref" => "#{schema_url}/properties/title" }
    data = {}
    load_other_schema
    _validator = JSON::Validator.new(schema, data)

    assert JSON::Validator.schema_loaded?(schema_url)
  end

  def test_metaschema
    schema = { "$ref" => "http://json-schema.org/draft-04/schema#" }
    data = {}

    assert_valid schema, data
  end
end