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 46 47 48 49 50 51 52 53 54 55 56 57
|
require File.expand_path('../support/test_helper', __FILE__)
class CachingTestTest < Minitest::Test
def setup
@schema = Tempfile.new(['schema', '.json'])
end
def teardown
@schema.close
@schema.unlink
JSON::Validator.clear_cache
end
def test_caching
set_schema('type' => 'string')
assert_valid(schema_path, 'foo', :clear_cache => false)
set_schema('type' => 'number')
refute_valid(schema_path, 123)
end
def test_clear_cache
set_schema('type' => 'string')
assert_valid(schema_path, 'foo', :clear_cache => true)
set_schema('type' => 'number')
assert_valid(schema_path, 123)
end
def test_cache_schemas
suppress_warnings do
JSON::Validator.cache_schemas = false
end
set_schema('type' => 'string')
assert_valid(schema_path, 'foo', :clear_cache => false)
set_schema('type' => 'number')
assert_valid(schema_path, 123)
ensure
suppress_warnings do
JSON::Validator.cache_schemas = true
end
end
private
def schema_path
@schema.path
end
def set_schema(schema_definition)
@schema.write(schema_definition.to_json)
@schema.rewind
end
end
|