json_schema 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 090872e4eabd4666b863192705b856a9bed17f95
4
- data.tar.gz: d663a4d178b532eedea87e3b9e103e11c618169a
3
+ metadata.gz: 4699ec08cb42382077750ca85baa91aa4f60732e
4
+ data.tar.gz: 8574657b774444006927dc7df56fdae92f13b2f9
5
5
  SHA512:
6
- metadata.gz: ab37926ea68afd15a71c4ca1be9ee265b990caf1e24901c031ea094bea806b671472cd65cec3225f420ba1baed6ec3acc41063b505d6eda3a95bbb028c20664b
7
- data.tar.gz: 2345cc253f9cb16f2f542234f0c705a4d97e256beb55c1cba45b190be570b46c7691193ca01b176f13c702bc2356e9e300e63dcfe17532ab714e27500ba3397b
6
+ metadata.gz: 6754b7820652d126bf225614bf740ad017a31b3ecf73f62262df3f1763eb8186bda0c5273bf0941dc82887d695fac47d3bc332a130103c4b9c2e94af918c35d5
7
+ data.tar.gz: e36ea2ce6d723b7f244e4a18565ce3b5159203ea4ecb0ba2e24d6bdbc0ff04953cf7130e25345a455527fcccb213a04f0b69a9d7d976a453f8d94f2152e45c49
@@ -6,13 +6,16 @@ module JsonSchema
6
6
  # that have already happened and handles cyclic dependencies. Store a
7
7
  # reference to the top-level schema before doing anything else.
8
8
  class DocumentStore
9
+ include Enumerable
10
+
9
11
  def initialize
10
12
  @schema_map = {}
11
13
  end
12
14
 
13
15
  def add_schema(schema)
14
16
  raise "can't add nil URI" if schema.uri.nil?
15
- @schema_map[schema.uri] = schema
17
+ uri = schema.uri.chomp('#')
18
+ @schema_map[uri] = schema
16
19
  end
17
20
 
18
21
  def each
@@ -20,6 +23,7 @@ module JsonSchema
20
23
  end
21
24
 
22
25
  def lookup_schema(uri)
26
+ uri = uri.chomp('#')
23
27
  @schema_map[uri]
24
28
  end
25
29
  end
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+
3
+ require "json_schema"
4
+
5
+ describe JsonSchema::DocumentStore do
6
+ before do
7
+ @store = JsonSchema::DocumentStore.new
8
+ end
9
+
10
+ it "adds and looks up a schema" do
11
+ schema = schema_sample("http://example.com/schema")
12
+ @store.add_schema(schema)
13
+ assert_equal schema, @store.lookup_schema(schema.uri)
14
+ end
15
+
16
+ it "can iterate through its schemas" do
17
+ uri = "http://example.com/schema"
18
+ schema = schema_sample(uri)
19
+ @store.add_schema(schema)
20
+ assert_equal [[uri, schema]], @store.to_a
21
+ end
22
+
23
+ it "can lookup a schema added with a document root sign" do
24
+ uri = "http://example.com/schema"
25
+ schema = schema_sample(uri + "#")
26
+ @store.add_schema(schema)
27
+ assert_equal schema, @store.lookup_schema(uri)
28
+ end
29
+
30
+ it "can lookup a schema with a document root sign" do
31
+ uri = "http://example.com/schema"
32
+ schema = schema_sample(uri)
33
+ @store.add_schema(schema)
34
+ assert_equal schema, @store.lookup_schema(uri + "#")
35
+ end
36
+
37
+ def schema_sample(uri)
38
+ schema = JsonSchema::Schema.new
39
+ schema.uri = uri
40
+ schema
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -65,6 +65,7 @@ files:
65
65
  - test/data_scaffold.rb
66
66
  - test/json_pointer/evaluator_test.rb
67
67
  - test/json_reference/reference_test.rb
68
+ - test/json_schema/document_store_test.rb
68
69
  - test/json_schema/parser_test.rb
69
70
  - test/json_schema/reference_expander_test.rb
70
71
  - test/json_schema/validator_test.rb