File: document_store_test.rb

package info (click to toggle)
ruby-brandur-json-schema 0.19.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 376 kB
  • sloc: ruby: 3,764; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (2)
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
require "test_helper"

require "json_schema"

describe JsonSchema::DocumentStore do
  before do
    @store = JsonSchema::DocumentStore.new
  end

  it "adds and looks up a schema" do
    schema = schema_sample("http://example.com/schema")
    @store.add_schema(schema)
    assert_equal schema, @store.lookup_schema(schema.uri)
  end

  it "can iterate through its schemas" do
    uri = "http://example.com/schema"
    schema = schema_sample(uri)
    @store.add_schema(schema)
    assert_equal [[uri, schema]], @store.to_a
  end

  it "can lookup a schema added with a document root sign" do
    uri = "http://example.com/schema"
    schema = schema_sample(uri + "#")
    @store.add_schema(schema)
    assert_equal schema, @store.lookup_schema(uri)
  end

  it "can lookup a schema with a document root sign" do
    uri = "http://example.com/schema"
    schema = schema_sample(uri)
    @store.add_schema(schema)
    assert_equal schema, @store.lookup_schema(uri + "#")
  end

  def schema_sample(uri)
    schema = JsonSchema::Schema.new
    schema.uri = uri
    schema
  end
end