Skip to content

Commit

Permalink
test use applied schemas for naming class; disuse jsi_schema_class
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Oct 26, 2021
1 parent 43ce14e commit 8272513
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions test/base_array_test.rb
Expand Up @@ -11,9 +11,10 @@
],
}
NAMED_ARY_SCHEMA = JSI.new_schema(base)
NamedArrayInstance = NAMED_ARY_SCHEMA.jsi_schema_class
NAMED_ID_ARY_SCHEMA = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/base/named_array_schema'}.merge(base))
NamedIdArrayInstance = NAMED_ID_ARY_SCHEMA.jsi_schema_class
# TODO drop support for this
NamedArrayInstance = NAMED_ARY_SCHEMA.new_jsi([]).class
NamedIdArrayInstance = NAMED_ID_ARY_SCHEMA.new_jsi([]).class

describe 'JSI::Base array' do
let(:instance) { ['foo', {'lamp' => [3]}, ['q', 'r'], {'four' => 4}] }
Expand Down
4 changes: 2 additions & 2 deletions test/base_hash_test.rb
Expand Up @@ -10,9 +10,9 @@
},
}
NAMED_HASH_SCHEMA = JSI.new_schema(base)
NamedHashInstance = NAMED_HASH_SCHEMA.jsi_schema_class
NAMED_ID_HASH_SCHEMA = JSI.new_schema({'$id' => 'https://schemas.jsi.unth.net/test/base/named_hash_schema'}.merge(base))
NamedIdHashInstance = NAMED_ID_HASH_SCHEMA.jsi_schema_class
NamedHashInstance = NAMED_HASH_SCHEMA.new_jsi([]).class
NamedIdHashInstance = NAMED_ID_HASH_SCHEMA.new_jsi([]).class

describe 'JSI::Base hash' do
let(:instance) { {'foo' => {'x' => 'y'}, 'bar' => [9], 'baz' => [true]} }
Expand Down
9 changes: 5 additions & 4 deletions test/base_test.rb
Expand Up @@ -3,14 +3,15 @@
NamedSchemaInstance = JSI.new_schema({
'$schema' => 'http://json-schema.org/draft-07/schema#',
'$id' => 'https://schemas.jsi.unth.net/test/base/named_schema',
}).jsi_schema_class
}).new_jsi({}).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({
NamedSchemaInstanceTwo = JSI.new_schema({
'$schema' => 'http://json-schema.org/draft-07/schema#',
'$id' => 'https://schemas.jsi.unth.net/test/base/named_schema_two',
}).jsi_schema_class.tap(&:name)
}).new_jsi({}).class.tap(&:name)

Phonebook = JSI.new_schema_module(YAML.load(<<~YAML
title: Phone Book
Expand Down Expand Up @@ -73,7 +74,7 @@ module Contact
end
describe 'class for schema .jsi_class_schemas' do
it '.jsi_class_schemas' do
assert_equal(Set[schema], schema.jsi_schema_class.jsi_class_schemas)
assert_equal(Set[schema], schema.new_jsi({}).class.jsi_class_schemas)
end
end
describe 'module for schema .inspect' do
Expand Down Expand Up @@ -787,7 +788,7 @@ def to_s
end
end
describe 'equality between different classes of JSI::Base subclasses' do
let(:subject_subclass) { Class.new(schema.jsi_schema_class).new(instance) }
let(:subject_subclass) { Class.new(schema.new_jsi({}).class).new(instance) }

it 'considers a Base subclass (class_for_schema) and subsubclass to be equal with the same instance' do
assert_equal(subject.hash, subject_subclass.hash)
Expand Down

0 comments on commit 8272513

Please sign in to comment.