Skip to content

Commit

Permalink
fix tests to use $id not id for JSONSchemaOrgDraft06
Browse files Browse the repository at this point in the history
this was wrong here reflecting incorrect handling in the json-schema gem
  • Loading branch information
notEthan committed Oct 6, 2021
1 parent 020841d commit a520c48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions test/base_test.rb
@@ -1,10 +1,10 @@
require_relative 'test_helper'

NamedSchemaInstance = JSI.new_schema({id: 'https://schemas.jsi.unth.net/test/base/named_schema'}).jsi_schema_class
NamedSchemaInstance = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/base/named_schema'}).jsi_schema_class

# hitting .tap(&:name) causes JSI to assign a constant name from the ID,
# meaning the name NamedSchemaInstanceTwo is not known.
NamedSchemaInstanceTwo = JSI.new_schema({id: 'https://schemas.jsi.unth.net/test/base/named_schema_two'}).jsi_schema_class.tap(&:name)
NamedSchemaInstanceTwo = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/base/named_schema_two'}).jsi_schema_class.tap(&:name)

describe JSI::Base do
let(:schema_content) { {} }
Expand All @@ -19,7 +19,7 @@
assert_equal("(JSI Schema Class: #)", subject.class.inspect)
end
describe 'with schema id' do
let(:schema_content) { {'id' => 'https://jsi/foo'} }
let(:schema_content) { {'$id' => 'https://jsi/foo'} }
it 'is (JSI Schema Class: ...) for generated subclass with id' do
assert_equal("(JSI Schema Class: https://jsi/foo#)", subject.class.inspect)
end
Expand All @@ -33,7 +33,7 @@
end
end
describe 'class name' do
let(:schema_content) { {'id' => 'https://jsi/BaseTest'} }
let(:schema_content) { {'$id' => 'https://jsi/BaseTest'} }
it 'generates a class name from schema_id' do
assert_equal('JSI::SchemaClasses::Xhttps___jsi_BaseTest_', subject.class.name)
end
Expand Down Expand Up @@ -341,7 +341,7 @@
describe 'with errors' do
let(:schema_content) {
{
'id' => 'https://schemas.jsi.unth.net/test/JSI::Base::validation::with errors',
'$id' => 'https://schemas.jsi.unth.net/test/JSI::Base::validation::with errors',
'type' => 'object',
'properties' => {
'some_number' => {
Expand Down Expand Up @@ -375,7 +375,7 @@
describe 'at a depth' do
let(:schema_content) do
{
'id' => 'https://schemas.jsi.unth.net/test/JSI::Base::validation::at a depth',
'$id' => 'https://schemas.jsi.unth.net/test/JSI::Base::validation::at a depth',
'description' => 'hash schema',
'type' => 'object',
'properties' => {
Expand Down
20 changes: 10 additions & 10 deletions test/schema_test.rb
Expand Up @@ -29,24 +29,24 @@
assert_nil(JSI.new_schema({}).schema_id)
end
it 'uses a given id with a fragment' do
schema = JSI.new_schema({'id' => 'https://schemas.jsi.unth.net/test/given_id_with_fragment#'})
schema = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/given_id_with_fragment#'})
assert_equal('https://schemas.jsi.unth.net/test/given_id_with_fragment#', schema.schema_id)
end
it 'uses a given id (adding a fragment)' do
schema = JSI.new_schema({id: 'https://schemas.jsi.unth.net/test/given_id'})
schema = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/given_id'})
assert_equal('https://schemas.jsi.unth.net/test/given_id#', schema.schema_id)
end
it 'uses a pointer in the fragment' do
schema = JSI.new_schema({
'id' => 'https://schemas.jsi.unth.net/test/uses_pointer_in_fragment#',
'$id' => 'https://schemas.jsi.unth.net/test/uses_pointer_in_fragment#',
'properties' => {'foo' => {'type' => 'object'}},
})
subschema = schema['properties']['foo']
assert_equal('https://schemas.jsi.unth.net/test/uses_pointer_in_fragment#/properties/foo', subschema.schema_id)
end
it 'uses a pointer in the fragment relative to the fragment of the root' do
schema = JSI.new_schema({
'id' => 'https://schemas.jsi.unth.net/test/id_has_pointer#/notroot',
'$id' => 'https://schemas.jsi.unth.net/test/id_has_pointer#/notroot',
'properties' => {'foo' => {'type' => 'object'}},
})
subschema = schema['properties']['foo']
Expand Down Expand Up @@ -275,14 +275,14 @@
end
describe '#jsi_schema_module' do
it 'returns the module for the schema' do
schema = JSI.new_schema({'id' => 'https://schemas.jsi.unth.net/test/jsi_schema_module'})
schema = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/jsi_schema_module'})
assert_is_a(JSI::SchemaModule, schema.jsi_schema_module)
assert_equal(schema, schema.jsi_schema_module.schema)
end
end
describe '#jsi_schema_class' do
it 'returns the class for the schema' do
schema = JSI.new_schema({'id' => 'https://schemas.jsi.unth.net/test/schema_schema_class'})
schema = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/schema_schema_class'})
assert_equal(JSI::SchemaClasses.class_for_schemas([schema]), schema.jsi_schema_class)
end
end
Expand Down Expand Up @@ -376,21 +376,21 @@
end
describe 'stringification' do
let(:schema) do
JSI.new_schema({id: 'https://schemas.jsi.unth.net/test/stringification', type: 'object'})
JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/stringification', type: 'object'})
end

it '#inspect' do
assert_equal("\#{<JSI (JSI::JSONSchemaOrgDraft06) Schema> \"id\" => \"https://schemas.jsi.unth.net/test/stringification\", \"type\" => \"object\"}", schema.inspect)
assert_equal("\#{<JSI (JSI::JSONSchemaOrgDraft06) Schema> \"$id\" => \"https://schemas.jsi.unth.net/test/stringification\", \"type\" => \"object\"}", schema.inspect)
end
it '#pretty_print' do
assert_equal("\#{<JSI (JSI::JSONSchemaOrgDraft06) Schema>
\"id\" => \"https://schemas.jsi.unth.net/test/stringification\",
\"$id\" => \"https://schemas.jsi.unth.net/test/stringification\",
\"type\" => \"object\"
}".gsub(/^ /, ''), schema.pretty_inspect.chomp)
end
end
describe 'validation' do
let(:schema) { JSI.new_schema({id: 'https://schemas.jsi.unth.net/test/validation', type: 'object'}) }
let(:schema) { JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/validation', type: 'object'}) }
describe 'without errors' do
let(:instance) { {'foo' => 'bar'} }
it '#instance_validate' do
Expand Down

0 comments on commit a520c48

Please sign in to comment.