Skip to content

Commit 4e06359

Browse files
committed
Add Context#to_rb tests, and make sure preloaded context has a context_base.
1 parent 5263d56 commit 4e06359

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/json/ld/context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def parse(local_context,
304304
log_debug("parse") {"=> (call)"}
305305
PRELOADED[context_canon.to_s] = PRELOADED[context_canon.to_s].call
306306
end
307+
PRELOADED[context_canon.to_s].context_base ||= context_canon.to_s
307308
PRELOADED[context_canon.to_s]
308309
else
309310
# Load context document, if it is a string

spec/context_spec.rb

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,6 @@ def containers
655655
"@language" => "en"
656656
}
657657
}, logger)
658-
expect(subject.to_rb).not_to be_empty
659658
end
660659

661660
it "@vocab" do
@@ -665,7 +664,6 @@ def containers
665664
"@vocab" => "http://example.com/"
666665
}
667666
}, logger)
668-
expect(subject.to_rb).not_to be_empty
669667
end
670668

671669
it "term mappings" do
@@ -676,7 +674,6 @@ def containers
676674
"foo" => "http://example.com/"
677675
}
678676
}, logger)
679-
expect(c.to_rb).not_to be_empty
680677
end
681678

682679
it "@context" do
@@ -931,6 +928,37 @@ def containers
931928

932929
end
933930

931+
describe "#to_rb" do
932+
before(:all) {JSON::LD::Context.instance_variable_set(:@cache, nil)}
933+
subject {
934+
allow(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
935+
context.parse("http://example.com/context")
936+
}
937+
938+
it "encodes as utf-8" do
939+
expect(subject.to_rb).to match(/encoding: utf-8/)
940+
end
941+
942+
it "marked as auto-generated" do
943+
expect(subject.to_rb).to match(/This file generated automatically from/)
944+
end
945+
946+
it "includes URL in preloaded" do
947+
expect(subject.to_rb).to include(%(add_preloaded("http://example.com/context")))
948+
end
949+
950+
it "includes processingMode" do
951+
expect(subject.to_rb).to include(%(processingMode: "json-ld-1.1"))
952+
end
953+
954+
it "term mappings" do
955+
expect(subject.to_rb).to include(%("avatar" => TermDefinition.new("avatar", id: "http://xmlns.com/foaf/0.1/avatar", type_mapping: "@id")))
956+
expect(subject.to_rb).to include(%("homepage" => TermDefinition.new("homepage", id: "http://xmlns.com/foaf/0.1/homepage", type_mapping: "@id")))
957+
expect(subject.to_rb).to include(%("name" => TermDefinition.new("name", id: "http://xmlns.com/foaf/0.1/name", simple: true)))
958+
expect(subject.to_rb).to include(%("xsd" => TermDefinition.new("xsd", id: "http://www.w3.org/2001/XMLSchema#", simple: true, prefix: true)))
959+
end
960+
end
961+
934962
describe "#base=" do
935963
subject {
936964
context.parse({

0 commit comments

Comments
 (0)